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


Java AuthenticationException类代码示例

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


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

示例1: acquireAccessToken

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

示例2: doFilter

import com.microsoft.aad.adal4j.AuthenticationException; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        try {
            String currentUri = httpRequest.getRequestURL().toString();
            String queryStr = httpRequest.getQueryString();
            String fullUrl = currentUri + (queryStr != null ? "?" + queryStr : "");

            // check if user has a AuthData in the session
            if (!AuthHelper.isAuthenticated(httpRequest)) {
                if (AuthHelper.containsAuthenticationData(httpRequest)) {
                    processAuthenticationData(httpRequest, currentUri, fullUrl);
                } else {
                    // not authenticated
                    sendAuthRedirect(httpRequest, httpResponse);
                    return;
                }
            }
            if (isAuthDataExpired(httpRequest)) {
                updateAuthDataUsingRefreshToken(httpRequest);
            }
        } catch (AuthenticationException authException) {
            // something went wrong (like expiration or revocation of token)
            // we should invalidate AuthData stored in session and redirect to Authorization server
            removePrincipalFromSession(httpRequest);
            sendAuthRedirect(httpRequest, httpResponse);
            return;
        } catch (Throwable exc) {
            httpResponse.setStatus(500);
            request.setAttribute("error", exc.getMessage());
            request.getRequestDispatcher("/error.jsp").forward(request, response);
        }
    }
    chain.doFilter(request, response);
}
 
开发者ID:Azure-Samples,项目名称:active-directory-java-webapp-openidconnect,代码行数:38,代码来源:BasicFilter.java

示例3: handleAuthException

import com.microsoft.aad.adal4j.AuthenticationException; //导入依赖的package包/类
private <T> T handleAuthException(Supplier<T> function) {
    try {
        return function.get();
    } catch (RuntimeException e) {
        if (ExceptionUtils.indexOfThrowable(e, AuthenticationException.class) != -1) {
            throw new ProviderAuthenticationFailedException(e);
        } else {
            throw e;
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:12,代码来源:AzureClient.java

示例4: acquireNewAccessToken

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