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


Java AuthenticationContext类代码示例

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


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

示例1: getAccessToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的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: acquireNewAccessToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的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

示例3: _authenticate

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的package包/类
private String _authenticate() throws AuthenticationFailureException {
    try {
        AuthenticationContext authenticationContext = new AuthenticationContext(
                authority,
                validateAuthority,
                executor
        );

        String result = getAccessToken(
                authenticationContext,
                powerBiResourceId,
                nativeClientId,
                username + "@" + tenant,
                password
        );

        if (StringUtils.isEmpty(result)) {
            throw new AuthenticationFailureException("Returned access token is null.");
        }

        return result;
    } catch (ExecutionException | InterruptedException | IOException e) {
        throw new AuthenticationFailureException(e);
    }
}
 
开发者ID:satalyst,项目名称:powerbi-rest-java,代码行数:26,代码来源:Office365Authenticator.java

示例4: acquireTokenForGraphApi

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的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

示例5: authenticate

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的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

示例6: acquireAccessToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的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

示例7: getAccessToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的package包/类
private String getAccessToken(AuthenticationContext authenticationContext, String resourceId, String clientId,
                              String username, String password) throws ExecutionException, InterruptedException {
    return authenticationContext.acquireToken(
            resourceId,
            clientId,
            username,
            password,
            null
    ).get().getAccessToken();
}
 
开发者ID:satalyst,项目名称:powerbi-rest-java,代码行数:11,代码来源:Office365Authenticator.java

示例8: redeemDaemon

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的package包/类
/**
 * Redeem daemon.
 *
 * @param redeemDaemonRequest the redeem daemon request
 * @return the Access Token redeemed it
 * @throws AuthenticationException the authentication exception
 */
public static String redeemDaemon(RedeemDaemonRequest redeemDaemonRequest) throws AuthenticationException{
	ExecutorService service = Executors.newCachedThreadPool();
	AuthenticationResult authenticationResult = null;
	String authority = String.format(ApiEnviroment.tokenDaemonBaseUrl.getValue(), redeemDaemonRequest.getTenantId());
	logger.debug("Trying to get App Only token for {}", redeemDaemonRequest);
	try {
		AuthenticationContext authenticationContext =  new AuthenticationContext(authority, false, service);
		String filePkcs12 = ApiEnviroment.fileUrlPkcs12Certificate.getValue();
		if(StringUtils.isNotEmpty(redeemDaemonRequest.getFileUrlPkcs12Certificate())){
			filePkcs12 = redeemDaemonRequest.getFileUrlPkcs12Certificate(); 
		}
		
		String filePkcs12Secret = ApiEnviroment.pkcs12CertificateSecret.getValue();
		if(StringUtils.isNotEmpty(redeemDaemonRequest.getCertificateSecret())){
			filePkcs12Secret = redeemDaemonRequest.getCertificateSecret(); 
		}
		
		Validate.notEmpty(filePkcs12, "Pkcs12 Key file path must be provided or configured. You can set it on environment var 'ONEDRIVE_DAEMON_PKCS12_FILE_URL' or through Java System Property 'onedrive.daemon.pkcs12.file.url'");
		Validate.notEmpty(filePkcs12Secret, "Pkcs12 Secret Key file must be provided or configured. You can set it on environment var 'ONEDRIVE_DAEMON_PKCS12_FILE_SECRET' or through Java System Property 'onedrive.daemon.pkcs12.file.secret'");
		
		InputStream pkcs12Certificate = new FileInputStream(filePkcs12);
		AsymmetricKeyCredential credential = AsymmetricKeyCredential.create(redeemDaemonRequest.getClientId(), pkcs12Certificate, filePkcs12Secret);
		
		Future<AuthenticationResult> future = authenticationContext.acquireToken(redeemDaemonRequest.getResourceSharepointId(), credential, null);
		authenticationResult = future.get(10, TimeUnit.SECONDS);
		logger.debug("Token retrieved {}", ToStringBuilder.reflectionToString(authenticationResult, ToStringStyle.SHORT_PREFIX_STYLE));
		return authenticationResult.getAccessToken();
	} catch (Exception e) {
		logger.error("Error trying to get new App Only Token", e);
		throw new AuthenticationException(String.format("Error trying to get new App Only Token for tenantId %s and sharepointUri %s", redeemDaemonRequest.getTenantId(), redeemDaemonRequest.getResourceSharepointId()));
	}finally{
		service.shutdown();
	}

}
 
开发者ID:mxhero,项目名称:onedrive-api,代码行数:43,代码来源:OneDrive.java

示例9: getToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的package包/类
@NotNull
public static AuthenticationResult getToken(@NotNull final AuthorizationTokenInputs inputs) throws Exception {
    final ExecutorService service = Executors.newSingleThreadExecutor();
    final AuthenticationContext context = new AuthenticationContext(inputs.getAuthority(), false, service);
    context.setProxy(getProxy(inputs.getProxyHost(), inputs.getProxyPort(), inputs.getProxyUsername(), inputs.getProxyPassword()));
    final Future<AuthenticationResult> future = context.acquireToken(inputs.getResource(), inputs.getClientId(), inputs.getUsername(), inputs.getPassword(), null);
    service.shutdown();
    return future.get();
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:10,代码来源:AuthorizationTokenImpl.java

示例10: acquireNewAccessToken

import com.microsoft.aad.adal4j.AuthenticationContext; //导入依赖的package包/类
AuthenticationResult acquireNewAccessToken(String resource) throws IOException {
    if (authorizationCode == null) {
        throw new IllegalArgumentException("You must acquire an authorization code by redirecting to the authentication URL");
    }
    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 (applicationCredentials.clientSecret() != null) {
            return context.acquireTokenByAuthorizationCode(
                    authorizationCode,
                    new URI(redirectUrl),
                    new ClientCredential(applicationCredentials.clientId(), applicationCredentials.clientSecret()),
                    resource, null).get();
        } else if (applicationCredentials.clientCertificate() != null && applicationCredentials.clientCertificatePassword() != null) {
            return context.acquireTokenByAuthorizationCode(
                    authorizationCode,
                    new URI(redirectUrl),
                    AsymmetricKeyCredential.create(
                            applicationCredentials.clientId(),
                            new ByteArrayInputStream(applicationCredentials.clientCertificate()),
                            applicationCredentials.clientCertificatePassword()),
                    resource,
                    null).get();
        } else if (applicationCredentials.clientCertificate() != null) {
            return context.acquireTokenByAuthorizationCode(
                    authorizationCode,
                    new URI(redirectUrl),
                    AsymmetricKeyCredential.create(
                            clientId(),
                            ApplicationTokenCredentials.privateKeyFromPem(new String(applicationCredentials.clientCertificate())),
                            ApplicationTokenCredentials.publicKeyFromPem(new String(applicationCredentials.clientCertificate()))),
                    resource,
                    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,代码行数:46,代码来源:DelegatedTokenCredentials.java


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