use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class YahooAuthenticator method validate.
@Override
public void validate(final OpenIdCredentials credentials, final WebContext context) {
final ParameterList parameterList = credentials.getParameterList();
final DiscoveryInformation discoveryInformation = credentials.getDiscoveryInformation();
logger.debug("parameterList: {}", parameterList);
logger.debug("discoveryInformation: {}", discoveryInformation);
try {
// verify the response
final VerificationResult verification = this.client.getConsumerManager().verify(this.client.computeFinalCallbackUrl(context), parameterList, discoveryInformation);
// examine the verification result and extract the verified identifier
final Identifier verified = verification.getVerifiedId();
if (verified != null) {
final AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
logger.debug("authSuccess: {}", authSuccess);
final YahooOpenIdProfile profile = createProfile(authSuccess);
profile.setId(verified.getIdentifier());
logger.debug("profile: {}", profile);
credentials.setUserProfile(profile);
return;
}
} catch (final OpenIDException e) {
throw new TechnicalException("OpenID exception", e);
}
final String message = "No verifiedId found";
throw new TechnicalException(message);
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class YahooRedirectActionBuilder method redirect.
@Override
public RedirectAction redirect(final WebContext context) {
try {
// perform discovery on the user-supplied identifier
final List discoveries = this.client.getConsumerManager().discover(YAHOO_GENERIC_USER_IDENTIFIER);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
final DiscoveryInformation discoveryInformation = this.client.getConsumerManager().associate(discoveries);
// save discovery information in session
context.getSessionStore().set(context, this.client.getDiscoveryInformationSessionAttributeName(), discoveryInformation);
// create authentication request to be sent to the OpenID provider
final AuthRequest authRequest = this.client.getConsumerManager().authenticate(discoveryInformation, this.client.computeFinalCallbackUrl(context));
// create fetch request for attributes
final FetchRequest fetchRequest = getFetchRequest();
if (fetchRequest != null) {
authRequest.addExtension(fetchRequest);
}
final String redirectionUrl = authRequest.getDestinationUrl(true);
logger.debug("redirectionUrl: {}", redirectionUrl);
return RedirectAction.redirect(redirectionUrl);
} catch (final OpenIDException e) {
throw new TechnicalException("OpenID exception", e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class OAuth10RedirectActionBuilder method redirect.
@Override
public RedirectAction redirect(final WebContext context) {
try {
final OAuth10aService service = this.configuration.buildService(context, client, null);
final OAuth1RequestToken requestToken;
try {
requestToken = service.getRequestToken();
} catch (final IOException | InterruptedException | ExecutionException e) {
throw new HttpCommunicationException("Error getting token: " + e.getMessage());
}
logger.debug("requestToken: {}", requestToken);
// save requestToken in user session
context.getSessionStore().set(context, configuration.getRequestTokenSessionAttributeName(client.getName()), requestToken);
final String authorizationUrl = service.getAuthorizationUrl(requestToken);
logger.debug("authorizationUrl: {}", authorizationUrl);
return RedirectAction.redirect(authorizationUrl);
} catch (final OAuthException e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class OidcLogoutActionBuilder method getLogoutAction.
@Override
public RedirectAction getLogoutAction(final WebContext context, final U currentProfile, final String targetUrl) {
final String logoutUrl = configuration.getLogoutUrl();
if (CommonHelper.isNotBlank(logoutUrl)) {
try {
final URI endSessionEndpoint = new URI(logoutUrl);
final JWT idToken = currentProfile.getIdToken();
LogoutRequest logoutRequest;
if (CommonHelper.isNotBlank(targetUrl)) {
logoutRequest = new LogoutRequest(endSessionEndpoint, idToken, new URI(targetUrl), null);
} else {
logoutRequest = new LogoutRequest(endSessionEndpoint, idToken);
}
if (ajaxRequestResolver.isAjax(context)) {
context.getSessionStore().set(context, Pac4jConstants.REQUESTED_URL, "");
context.setResponseHeader(HttpConstants.LOCATION_HEADER, logoutRequest.toURI().toString());
throw HttpAction.status(403, context);
}
return RedirectAction.redirect(logoutRequest.toURI().toString());
} catch (final URISyntaxException e) {
throw new TechnicalException(e);
}
}
return null;
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class AzureAdProfile method isExpired.
@Override
public boolean isExpired() {
try {
JWT jwt = this.getIdToken();
JWTClaimsSet claims = jwt.getJWTClaimsSet();
Date expiresOn = claims.getExpirationTime();
Calendar now = Calendar.getInstance();
now.add(Calendar.SECOND, idTokenExpireAdvance);
if (expiresOn.before(now.getTime())) {
return true;
}
} catch (ParseException e) {
throw new TechnicalException(e);
}
return false;
}
Aggregations