当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationResult类代码示例

本文整理汇总了Java中com.microsoft.aad.adal4j.AuthenticationResult的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationResult类的具体用法?Java AuthenticationResult怎么用?Java AuthenticationResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationResult类属于com.microsoft.aad.adal4j包,在下文中一共展示了AuthenticationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAccessToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private AuthenticationResult getAccessToken(VertxContext<Server> vertxContext, String clientId, String clientKey, String authorization, String resource) throws Exception {
    AuthenticationContext context = new AuthenticationContext(authorization, false, executorService);
    ClientCredential credentials = new ClientCredential(clientId, clientKey);
    AuthenticationResult result = context.acquireToken(resource, credentials, null).get();
    checkNotNull(result, "AuthenticationResult was null");
    return result;
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:8,代码来源:AzureKms.java

示例2: createCredentials

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private CloudCredentials createCredentials(VertxContext<Server> vertxContext) throws Exception {
    return new KeyVaultCredentials() {

        @Override
        public Header doAuthenticate(ServiceRequestContext request, Map<String, String> challenge) {
            try {
                String authorization = challenge.get("authorization");
                String resource = challenge.get("resource");
                AuthenticationResult authResult = getAccessToken(vertxContext, accessKeyId, secretKey, authorization, resource);
                return new BasicHeader("Authorization", authResult.getAccessTokenType() + " " + authResult.getAccessToken());
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    };
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:17,代码来源:AzureKms.java

示例3: getToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
@Override
public synchronized String getToken(String resource) throws IOException {
    // Find exact match for the resource
    AuthenticationResult authenticationResult = tokens.get(resource);
    // Return if found and not expired
    if (authenticationResult != null && authenticationResult.getExpiresOnDate().after(new Date())) {
        return authenticationResult.getAccessToken();
    }
    // If found then refresh
    boolean shouldRefresh = authenticationResult != null;
    // If not found for the resource, but is MRRT then also refresh
    if (authenticationResult == null && !tokens.isEmpty()) {
        authenticationResult = new ArrayList<>(tokens.values()).get(0);
        shouldRefresh = authenticationResult.isMultipleResourceRefreshToken();
    }
    // Refresh
    if (shouldRefresh) {
        authenticationResult = acquireAccessTokenFromRefreshToken(resource, authenticationResult.getRefreshToken(), authenticationResult.isMultipleResourceRefreshToken());
    }
    // If refresh fails or not refreshable, acquire new token
    if (authenticationResult == null) {
        authenticationResult = acquireNewAccessToken(resource);
    }
    tokens.put(resource, authenticationResult);
    return authenticationResult.getAccessToken();
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:27,代码来源:UserTokenCredentials.java

示例4: acquireNewAccessToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
AuthenticationResult acquireNewAccessToken(String resource) throws IOException {
    String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor);
    if (proxy() != null) {
        context.setProxy(proxy());
    }
    try {
        return context.acquireToken(
                resource,
                this.clientId(),
                this.username(),
                this.password,
                null).get();
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:21,代码来源:UserTokenCredentials.java

示例5: main

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
public static void main(String args[]) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(
                System.in))) {
            System.out.print("Enter username: ");
            String username = br.readLine();
            System.out.print("Enter password: ");
            String password = br.readLine();

            AuthenticationResult result = getAccessTokenFromUserCredentials(
                    username, password);
            System.out.println("Access Token - " + result.getAccessToken());
            System.out.println("Refresh Token - " + result.getRefreshToken());
            System.out.println("ID Token - " + result.getIdToken());
        }
    }
 
开发者ID:Azure-Samples,项目名称:active-directory-java-native-headless,代码行数:17,代码来源:PublicClient.java

示例6: getDirectoryObjects

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public String getDirectoryObjects(ModelMap model, HttpServletRequest httpRequest) {
    HttpSession session = httpRequest.getSession();
    AuthenticationResult result = (AuthenticationResult) session.getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME);
    if (result == null) {
        model.addAttribute("error", new Exception("AuthenticationResult not found in session."));
        return "/error";
    } else {
        String data;
        try {
            String tenant = session.getServletContext().getInitParameter("tenant");
            data = getUsernamesFromGraph(result.getAccessToken(), tenant);
            model.addAttribute("tenant", tenant);
            model.addAttribute("users", data);
            model.addAttribute("userInfo", result.getUserInfo());
        } catch (Exception e) {
            model.addAttribute("error", e);
            return "/error";
        }
    }
    return "/secure/aad";
}
 
开发者ID:Azure-Samples,项目名称:active-directory-java-webapp-openidconnect,代码行数:23,代码来源:AadController.java

示例7: acquireTokenForGraphApi

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private AuthenticationResult acquireTokenForGraphApi(
        String idToken,
        String tenantId) throws Throwable {
    final ClientCredential credential = new ClientCredential(
            aadAuthFilterProp.getClientId(), aadAuthFilterProp.getClientSecret());
    final UserAssertion assertion = new UserAssertion(idToken);

    AuthenticationResult result = null;
    ExecutorService service = null;
    try {
        service = Executors.newFixedThreadPool(1);
        final AuthenticationContext context = new AuthenticationContext(
                aadAuthFilterProp.getAadSignInUri() + tenantId + "/",
                true,
                service);
        final Future<AuthenticationResult> future = context
                .acquireToken(aadAuthFilterProp.getAadGraphAPIUri(), assertion, credential, null);
        result = future.get();
    } catch (ExecutionException e) {
        throw e.getCause();
    } finally {
        if (service != null) {
            service.shutdown();
        }
    }

    if (result == null) {
        throw new ServiceUnavailableException(
                "unable to acquire on-behalf-of token for client " + aadAuthFilterProp.getClientId());
    }
    return result;
}
 
开发者ID:Microsoft,项目名称:azure-spring-boot,代码行数:33,代码来源:AADAuthenticationFilter.java

示例8: authenticate

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
/**
 * Authenticates with the partner service.
 * 
 * @param requestContext An optional request context.
 * @return A task that is complete when the authentication is complete.
 */
@Override
public void authenticate( IRequestContext requestContext )
{
    // get the application AAD token
    AuthenticationResult authResult = null;
    ExecutorService service = null;
    try
    {
        URI activeDirectoryEndpoint = new URI( this.getActiveDirectoryAuthority() + this.aadApplicationDomain );
        service = Executors.newFixedThreadPool( 1 );
        AuthenticationContext authenticationContext =
            new AuthenticationContext( activeDirectoryEndpoint.toString(), false, service );
        if ( null != requestContext )
        {
            authenticationContext.setCorrelationId( requestContext.getCorrelationId().toString() );
        }

        ClientCredential clientCred = new ClientCredential( this.getClientId(), this.applicationSecret );
        Future<AuthenticationResult> future =
            authenticationContext.acquireToken( this.getGraphApiEndpoint(), clientCred, null );
        authResult = future.get();
    }
    catch ( Exception e )
    {
        throw new PartnerException( "Failed to do the application AAD login", e );
    }
    finally
    {
        service.shutdown();
    }
    this.setAADToken( new AuthenticationToken( authResult.getAccessToken(),
                                               new DateTime( authResult.getExpiresOnDate() ) ) );
}
 
开发者ID:PartnerCenterSamples,项目名称:Partner-Center-Java-SDK,代码行数:40,代码来源:ApplicationPartnerCredentials.java

示例9: getToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
@Override
public synchronized String getToken(String resource) throws IOException {
    AuthenticationResult authenticationResult = tokens.get(resource);
    if (authenticationResult == null || authenticationResult.getExpiresOnDate().before(new Date())) {
        authenticationResult = acquireAccessToken(resource);
    }
    tokens.put(resource, authenticationResult);
    return authenticationResult.getAccessToken();
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:10,代码来源:ApplicationTokenCredentials.java

示例10: acquireAccessToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private AuthenticationResult acquireAccessToken(String resource) throws IOException {
    String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor);
    if (proxy() != null) {
        context.setProxy(proxy());
    }
    try {
        if (clientSecret != null) {
            return context.acquireToken(
                    resource,
                    new ClientCredential(this.clientId(), clientSecret),
                    null).get();
        } else if (clientCertificate != null && clientCertificatePassword != null) {
            return context.acquireToken(
                    resource,
                    AsymmetricKeyCredential.create(clientId, new ByteArrayInputStream(clientCertificate), clientCertificatePassword),
                    null).get();
        } else if (clientCertificate != null) {
            return context.acquireToken(
                    resource,
                    AsymmetricKeyCredential.create(clientId(), privateKeyFromPem(new String(clientCertificate)), publicKeyFromPem(new String(clientCertificate))),
                    null).get();
        }
        throw new AuthenticationException("Please provide either a non-null secret or a non-null certificate.");
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:32,代码来源:ApplicationTokenCredentials.java

示例11: acquireAccessTokenFromRefreshToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
AuthenticationResult acquireAccessTokenFromRefreshToken(String resource, String refreshToken, boolean isMultipleResourceRefreshToken) throws IOException {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    try {
        return refreshTokenClient.refreshToken(domain(), clientId(), resource, refreshToken, isMultipleResourceRefreshToken);
    } catch (Exception e) {
        return null;
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:11,代码来源:UserTokenCredentials.java

示例12: acquireAccessTokenFromRefreshToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private AuthenticationResult acquireAccessTokenFromRefreshToken(String resource, String refreshToken, boolean isMultipleResourceRefreshToken) throws IOException {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    try {
        return refreshTokenClient.refreshToken(domain(), clientId(), resource, refreshToken, isMultipleResourceRefreshToken);
    } catch (Exception e) {
        return null;
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:11,代码来源:DelegatedTokenCredentials.java

示例13: withAuthenticationResult

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
AzureCliToken withAuthenticationResult(AuthenticationResult result) {
    this.accessToken = result.getAccessToken();
    this.refreshToken = result.getRefreshToken();
    this.expiresIn = result.getExpiresAfter();
    this.expiresOnDate = result.getExpiresOnDate();
    return this;
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:8,代码来源:AzureCliToken.java

示例14: acquireAccessToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private void acquireAccessToken() throws IOException {
    this.authenticationResult = new AuthenticationResult(
            null,
            "token1",
            "refresh",
            1,
            null,
            null,
            false);
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:11,代码来源:UserTokenCredentialsTests.java

示例15: acquireAccessTokenFromRefreshToken

import com.microsoft.aad.adal4j.AuthenticationResult; //导入依赖的package包/类
private void acquireAccessTokenFromRefreshToken() throws IOException {
    this.authenticationResult = new AuthenticationResult(
            null,
            "token2",
            "refresh",
            1,
            null,
            null,
            false);
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:11,代码来源:UserTokenCredentialsTests.java


注:本文中的com.microsoft.aad.adal4j.AuthenticationResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。