正在查看: MX Player v1.97.8 应用的 OAuth2WebViewClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: MX Player v1.97.8 应用的 OAuth2WebViewClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.microsoft.identity.common.internal.ui.webview;
import android.app.Activity;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import com.microsoft.identity.common.internal.ui.webview.challengehandlers.ChallengeFactory;
import com.microsoft.identity.common.internal.ui.webview.challengehandlers.NtlmChallengeHandler;
import com.microsoft.identity.common.internal.util.StringUtil;
import com.microsoft.identity.common.java.exception.ClientException;
import com.microsoft.identity.common.java.providers.RawAuthorizationResult;
import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback;
import com.microsoft.identity.common.logging.Logger;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
public abstract class OAuth2WebViewClient extends WebViewClient {
private static final String TAG = "OAuth2WebViewClient";
@SuppressFBWarnings(justification = "This is only exposed in testing", value = {"MS_SHOULD_BE_FINAL"})
public static ExpectedPage mExpectedPage;
private final Activity mActivity;
private final IAuthorizationCompletionCallback mCompletionCallback;
private final OnPageLoadedCallback mPageLoadedCallback;
public OAuth2WebViewClient(@NonNull Activity activity, @NonNull IAuthorizationCompletionCallback iAuthorizationCompletionCallback, @NonNull OnPageLoadedCallback onPageLoadedCallback) {
this.mActivity = activity;
this.mCompletionCallback = iAuthorizationCompletionCallback;
this.mPageLoadedCallback = onPageLoadedCallback;
}
private void checkStartUrl(String str) {
String h = z31.h(new StringBuilder(), TAG, ":checkStartUrl");
if (StringUtil.isEmpty(str)) {
Logger.info(h, "onPageStarted: Null url for page to load.");
return;
}
Uri parse = Uri.parse(str);
if (parse.isOpaque()) {
Logger.info(h, "onPageStarted: Non-hierarchical loading uri.");
Logger.infoPII(h, "start url: " + str);
return;
}
if (StringUtil.isEmpty(parse.getQueryParameter("code"))) {
Logger.info(h, "onPageStarted: URI has no auth code ('code') query parameter.");
Logger.infoPII(h, "Scheme:" + parse.getScheme() + " Host: " + parse.getHost() + " Path: " + parse.getPath());
return;
}
Logger.info(h, "Auth code is returned for the loading url.");
Logger.infoPII(h, "Scheme:" + parse.getScheme() + " Host: " + parse.getHost() + " Path: " + parse.getPath());
}
private void sendErrorToCallback(@NonNull WebView webView, int i, @NonNull String str) {
webView.stopLoading();
this.mCompletionCallback.onChallengeResponseReceived(RawAuthorizationResult.fromException(new ClientException(wh0.c(i, "Code:"), str)));
}
public Activity getActivity() {
return this.mActivity;
}
public IAuthorizationCompletionCallback getCompletionCallback() {
return this.mCompletionCallback;
}
@Override
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
this.mPageLoadedCallback.onPageLoaded(str);
ExpectedPage expectedPage = mExpectedPage;
if (expectedPage != null && str.startsWith(expectedPage.mExpectedPageUrlStartsWith)) {
mExpectedPage.mCallback.onPageLoaded(str);
}
webView.setVisibility(0);
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
String h = z31.h(new StringBuilder(), TAG, ":onPageStarted");
checkStartUrl(str);
Logger.info(h, "WebView starts loading.");
super.onPageStarted(webView, str, bitmap);
}
@Override
public void onReceivedError(WebView webView, int i, String str, String str2) {
sendErrorToCallback(webView, i, str);
}
@Override
public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
String str3 = TAG + ":onReceivedHttpAuthRequest";
Logger.info(str3, "Receive the http auth request. Start the dialog to ask for creds. ");
Logger.infoPII(str3, "Host:" + str);
new NtlmChallengeHandler(this.mActivity, this.mCompletionCallback).processChallenge((NtlmChallengeHandler) ChallengeFactory.getNtlmChallenge(webView, httpAuthHandler, str, str2));
}
@Override
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
super.onReceivedSslError(webView, sslErrorHandler, sslError);
sslErrorHandler.cancel();
Logger.error(TAG + ":onReceivedSslError", "Received SSL Error during request. For more info see: https://go.microsoft.com/fwlink/?linkid=2138180", null);
this.mCompletionCallback.onChallengeResponseReceived(RawAuthorizationResult.fromException(new ClientException("Code:-11", sslError.toString())));
}
@Override
public void onReceivedError(@NonNull WebView webView, @NonNull WebResourceRequest webResourceRequest, @NonNull WebResourceError webResourceError) {
String h = z31.h(new StringBuilder(), TAG, ":onReceivedError");
Logger.warn(h, "WebResourceError - isForMainFrame? " + webResourceRequest.isForMainFrame());
Logger.warnPII(h, "Failing url: " + webResourceRequest.getUrl());
if (webResourceRequest.isForMainFrame()) {
sendErrorToCallback(webView, webResourceError.getErrorCode(), webResourceError.getDescription().toString());
}
}
}