导航菜单

页面标题

页面副标题

St.John's v1.0.9 - OAuth2WebViewClient.java 源代码

正在查看: St.John's v1.0.9 应用的 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 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;

public abstract class OAuth2WebViewClient extends WebViewClient {
    private static final String TAG = "OAuth2WebViewClient";
    public static ExpectedPage mExpectedPage;
    private final Activity mActivity;
    private final IAuthorizationCompletionCallback mCompletionCallback;
    private final OnPageLoadedCallback mPageLoadedCallback;

    public Activity getActivity() {
        return this.mActivity;
    }

    IAuthorizationCompletionCallback getCompletionCallback() {
        return this.mCompletionCallback;
    }

    OAuth2WebViewClient(Activity activity, IAuthorizationCompletionCallback iAuthorizationCompletionCallback, OnPageLoadedCallback onPageLoadedCallback) {
        this.mActivity = activity;
        this.mCompletionCallback = iAuthorizationCompletionCallback;
        this.mPageLoadedCallback = onPageLoadedCallback;
    }

    @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 onReceivedError(WebView webView, int i, String str, String str2) {
        sendErrorToCallback(webView, i, str);
    }

    @Override
    public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
        int errorCode;
        CharSequence description;
        String str = TAG + ":onReceivedError";
        Logger.warn(str, "WebResourceError - isForMainFrame? " + webResourceRequest.isForMainFrame());
        Logger.warnPII(str, "Failing url: " + webResourceRequest.getUrl());
        if (webResourceRequest.isForMainFrame()) {
            errorCode = webResourceError.getErrorCode();
            description = webResourceError.getDescription();
            sendErrorToCallback(webView, errorCode, description.toString());
        }
    }

    private void sendErrorToCallback(WebView webView, int i, String str) {
        webView.stopLoading();
        this.mCompletionCallback.onChallengeResponseReceived(RawAuthorizationResult.fromException(new ClientException("Code:" + i, str)));
    }

    @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 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 str2 = TAG + ":onPageStarted";
        checkStartUrl(str);
        Logger.info(str2, "WebView starts loading.");
        super.onPageStarted(webView, str, bitmap);
    }

    private void checkStartUrl(String str) {
        String str2 = TAG + ":checkStartUrl";
        if (StringUtil.isEmpty(str)) {
            Logger.info(str2, "onPageStarted: Null url for page to load.");
            return;
        }
        Uri parse = Uri.parse(str);
        if (parse.isOpaque()) {
            Logger.info(str2, "onPageStarted: Non-hierarchical loading uri.");
            Logger.infoPII(str2, "start url: " + str);
            return;
        }
        if (StringUtil.isEmpty(parse.getQueryParameter("code"))) {
            Logger.info(str2, "onPageStarted: URI has no auth code ('code') query parameter.");
            Logger.infoPII(str2, "Scheme:" + parse.getScheme() + " Host: " + parse.getHost() + " Path: " + parse.getPath());
            return;
        }
        Logger.info(str2, "Auth code is returned for the loading url.");
        Logger.infoPII(str2, "Scheme:" + parse.getScheme() + " Host: " + parse.getHost() + " Path: " + parse.getPath());
    }
}