导航菜单

页面标题

页面副标题

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

正在查看: St.John's v1.0.9 应用的 FociQueryUtilities.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.microsoft.identity.common.java.foci;

import com.microsoft.identity.common.java.AuthenticationConstants;
import com.microsoft.identity.common.java.authscheme.AbstractAuthenticationScheme;
import com.microsoft.identity.common.java.authscheme.BearerAuthenticationSchemeInternal;
import com.microsoft.identity.common.java.cache.BrokerOAuth2TokenCache;
import com.microsoft.identity.common.java.cache.ICacheRecord;
import com.microsoft.identity.common.java.controllers.BaseController;
import com.microsoft.identity.common.java.dto.IAccountRecord;
import com.microsoft.identity.common.java.dto.RefreshTokenRecord;
import com.microsoft.identity.common.java.exception.ClientException;
import com.microsoft.identity.common.java.logging.Logger;
import com.microsoft.identity.common.java.opentelemetry.OTelUtility;
import com.microsoft.identity.common.java.opentelemetry.SpanExtension;
import com.microsoft.identity.common.java.opentelemetry.SpanName;
import com.microsoft.identity.common.java.providers.microsoft.MicrosoftTokenResponse;
import com.microsoft.identity.common.java.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationRequest;
import com.microsoft.identity.common.java.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Configuration;
import com.microsoft.identity.common.java.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy;
import com.microsoft.identity.common.java.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest;
import com.microsoft.identity.common.java.providers.oauth2.OAuth2StrategyParameters;
import com.microsoft.identity.common.java.providers.oauth2.OAuth2TokenCache;
import com.microsoft.identity.common.java.providers.oauth2.TokenResult;
import com.microsoft.identity.common.java.util.CommonURIBuilder;
import com.microsoft.identity.common.java.util.StringUtil;
import com.microsoft.identity.common.java.util.ported.ObjectUtils;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.UUID;

public class FociQueryUtilities {
    private static final String TAG = "FociQueryUtilities";

    public static boolean tryFociTokenWithGivenClientId(BrokerOAuth2TokenCache brokerOAuth2TokenCache, String str, String str2, ICacheRecord iCacheRecord) throws IOException, ClientException {
        if (brokerOAuth2TokenCache == null) {
            throw new NullPointerException("brokerOAuth2TokenCache is marked non-null but is null");
        }
        if (str == null) {
            throw new NullPointerException("clientId is marked non-null but is null");
        }
        if (str2 == null) {
            throw new NullPointerException("redirectUri is marked non-null but is null");
        }
        if (iCacheRecord == null) {
            throw new NullPointerException("cacheRecord is marked non-null but is null");
        }
        return tryFociTokenWithGivenClientId(brokerOAuth2TokenCache, str, str2, iCacheRecord.getRefreshToken(), iCacheRecord.getAccount());
    }

    public static boolean tryFociTokenWithGivenClientId(OAuth2TokenCache oAuth2TokenCache, String str, String str2, RefreshTokenRecord refreshTokenRecord, IAccountRecord iAccountRecord) throws ClientException, IOException {
        String delimitedDefaultScopeString;
        if (oAuth2TokenCache == null) {
            throw new NullPointerException("brokerOAuth2TokenCache is marked non-null but is null");
        }
        if (str == null) {
            throw new NullPointerException("clientId is marked non-null but is null");
        }
        if (str2 == null) {
            throw new NullPointerException("redirectUri is marked non-null but is null");
        }
        if (refreshTokenRecord == null) {
            throw new NullPointerException("refreshTokenRecord is marked non-null but is null");
        }
        if (iAccountRecord == null) {
            throw new NullPointerException("accountRecord is marked non-null but is null");
        }
        MicrosoftStsOAuth2Configuration microsoftStsOAuth2Configuration = new MicrosoftStsOAuth2Configuration();
        CommonURIBuilder commonURIBuilder = new CommonURIBuilder();
        commonURIBuilder.setScheme(AuthenticationConstants.HTTPS_PROTOCOL_STRING).setHost(refreshTokenRecord.getEnvironment()).setPath(StringUtil.isNullOrEmpty(iAccountRecord.getRealm()) ? "common" : iAccountRecord.getRealm());
        try {
            microsoftStsOAuth2Configuration.setAuthorityUrl(new URL(commonURIBuilder.build().toString()));
            MicrosoftStsOAuth2Strategy microsoftStsOAuth2Strategy = new MicrosoftStsOAuth2Strategy(microsoftStsOAuth2Configuration, OAuth2StrategyParameters.builder().build());
            String secret = refreshTokenRecord.getSecret();
            if (ObjectUtils.equals(str, "87749df4-7ccf-48f8-aa87-704bad0e0e16")) {
                Span createSpan = OTelUtility.createSpan(SpanName.SetScopeForDMAgentForFoci.name());
                try {
                    Scope makeCurrentSpan = SpanExtension.makeCurrentSpan(createSpan);
                    try {
                        delimitedDefaultScopeString = "https://devicemgmt.teams.microsoft.com/.default " + BaseController.getDelimitedDefaultScopeString();
                        Logger.info(TAG + ":tryFociTokenWithGivenClientId", "Teams agent client ID - making a test request with teams agent resource.");
                        if (makeCurrentSpan != null) {
                            makeCurrentSpan.close();
                        }
                    } finally {
                    }
                } finally {
                    createSpan.end();
                }
            } else {
                delimitedDefaultScopeString = BaseController.getDelimitedDefaultScopeString();
            }
            String str3 = delimitedDefaultScopeString;
            UUID randomUUID = UUID.randomUUID();
            StringBuilder sb = new StringBuilder();
            String str4 = TAG;
            sb.append(str4);
            sb.append(":tryFociTokenWithGivenClientId");
            Logger.verbose(sb.toString(), "Create the token request with correlationId [" + randomUUID + "]");
            MicrosoftStsTokenRequest createTokenRequest = createTokenRequest(str, str3, secret, str2, microsoftStsOAuth2Strategy, randomUUID, "2");
            Logger.verbose(str4 + ":tryFociTokenWithGivenClientId", "Start refreshing token (to verify foci) with correlationId [" + randomUUID + "]");
            TokenResult requestToken = microsoftStsOAuth2Strategy.requestToken(createTokenRequest);
            Logger.verbose(str4 + ":tryFociTokenWithGivenClientId", "Is the client ID able to use the foci? [" + requestToken.getSuccess() + "] with correlationId [" + randomUUID + "]");
            if (requestToken.getSuccess()) {
                MicrosoftStsAuthorizationRequest createAuthRequest = createAuthRequest(microsoftStsOAuth2Strategy, str, str2, str3, iAccountRecord, randomUUID);
                Logger.verbose(str4 + ":tryFociTokenWithGivenClientId", "Saving records to cache with client id" + str);
                brokerOAuth2TokenCacheSave(oAuth2TokenCache, microsoftStsOAuth2Strategy, requestToken, createAuthRequest);
            }
            return requestToken.getSuccess();
        } catch (URISyntaxException e) {
            throw new ClientException("malformed_url", e.getMessage(), e);
        }
    }

    public static MicrosoftStsTokenRequest createTokenRequest(String str, String str2, String str3, String str4, MicrosoftStsOAuth2Strategy microsoftStsOAuth2Strategy, UUID uuid, String str5) throws ClientException {
        if (str == null) {
            throw new NullPointerException("clientId is marked non-null but is null");
        }
        if (str2 == null) {
            throw new NullPointerException("scopes is marked non-null but is null");
        }
        if (str3 == null) {
            throw new NullPointerException("refreshToken is marked non-null but is null");
        }
        if (str4 == null) {
            throw new NullPointerException("redirectUri is marked non-null but is null");
        }
        if (microsoftStsOAuth2Strategy == null) {
            throw new NullPointerException("strategy is marked non-null but is null");
        }
        if (str5 == null) {
            throw new NullPointerException("idTokenVersion is marked non-null but is null");
        }
        MicrosoftStsTokenRequest createRefreshTokenRequest = microsoftStsOAuth2Strategy.createRefreshTokenRequest((AbstractAuthenticationScheme) new BearerAuthenticationSchemeInternal());
        createRefreshTokenRequest.setClientId(str);
        createRefreshTokenRequest.setScope(str2);
        createRefreshTokenRequest.setCorrelationId(uuid);
        createRefreshTokenRequest.setRefreshToken(str3);
        createRefreshTokenRequest.setRedirectUri(str4);
        createRefreshTokenRequest.setIdTokenVersion(str5);
        return createRefreshTokenRequest;
    }

    private static MicrosoftStsAuthorizationRequest createAuthRequest(MicrosoftStsOAuth2Strategy microsoftStsOAuth2Strategy, String str, String str2, String str3, IAccountRecord iAccountRecord, UUID uuid) {
        if (microsoftStsOAuth2Strategy == null) {
            throw new NullPointerException("strategy is marked non-null but is null");
        }
        if (str == null) {
            throw new NullPointerException("clientId is marked non-null but is null");
        }
        if (str2 == null) {
            throw new NullPointerException("redirectUri is marked non-null but is null");
        }
        if (str3 == null) {
            throw new NullPointerException("scope is marked non-null but is null");
        }
        if (iAccountRecord == null) {
            throw new NullPointerException("accountRecord is marked non-null but is null");
        }
        return ((MicrosoftStsAuthorizationRequest.Builder) ((MicrosoftStsAuthorizationRequest.Builder) ((MicrosoftStsAuthorizationRequest.Builder) microsoftStsOAuth2Strategy.createAuthorizationRequestBuilder(iAccountRecord).setClientId(str)).setRedirectUri(str2)).setCorrelationId(uuid).setScope(str3)).build();
    }

    private static void brokerOAuth2TokenCacheSave(OAuth2TokenCache oAuth2TokenCache, MicrosoftStsOAuth2Strategy microsoftStsOAuth2Strategy, TokenResult tokenResult, MicrosoftStsAuthorizationRequest microsoftStsAuthorizationRequest) throws ClientException {
        if (oAuth2TokenCache == null) {
            throw new NullPointerException("brokerOAuth2TokenCache is marked non-null but is null");
        }
        oAuth2TokenCache.save(microsoftStsOAuth2Strategy, microsoftStsAuthorizationRequest, (MicrosoftTokenResponse) tokenResult.getTokenResponse());
    }
}