本文整理汇总了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();
}
}
示例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);
}
示例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;
}
}
}
示例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();
}
}