use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class ValidationServerResource method validate.
/**
* Handles GET requests to the OAuth2 tokeninfo endpoint for retrieving information about the provided token.
*
* @return The body to be sent in the response to the user agent.
* @throws OAuth2RestletException
*/
@Get
public Representation validate() throws OAuth2RestletException {
logger.trace("In Validator resource");
final OAuth2Request request = requestFactory.create(getRequest());
try {
final JsonValue tokenInfo = tokenInfoService.getTokenInfo(request);
// Sets the no-store Cache-Control header
getResponse().getCacheDirectives().add(CacheDirective.noCache());
getResponse().getCacheDirectives().add(CacheDirective.noStore());
return jacksonRepresentationFactory.create(tokenInfo.asMap());
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
}
}
use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class OpenIDConnectConfiguration method getConfiguration.
/**
* Handles GET requests to the OpenId Connect .well-known endpoint for retrieving the OpenId Connect provider
* configuration.
*
* @return The representation of the OpenId Connect provider configuration.
* @throws OAuth2RestletException If an error occurs whilst retrieving the OpenId Connect provider configuration.
*/
@Get
public Representation getConfiguration() throws OAuth2RestletException {
try {
final OAuth2Request request = requestFactory.create(getRequest());
final JsonValue configuration = providerConfiguration.getConfiguration(request);
return new JsonRepresentation(configuration.asMap());
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
}
}
use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class OpenIDConnectDiscovery method discovery.
/**
* Handles GET requests to the OpenId Connect discovery endpoint.
*
* @return The representation of the OpenId Connect discovery.
* @throws OAuth2RestletException If an error occurs whilst performing the discovery.
*/
@Get
public Representation discovery() throws OAuth2RestletException {
final OAuth2Request request = requestFactory.create(getRequest());
final String resource = request.getParameter("resource");
final String rel = request.getParameter("rel");
final String realm = request.getParameter("realm");
try {
final String deploymentUrl = baseUrlProviderFactory.get(realm).getRootURL(ServletUtils.getRequest(getRequest()));
final Map<String, Object> response = providerDiscovery.discover(resource, rel, deploymentUrl, request);
return new JsonRepresentation(response);
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
}
}
use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class ConnectClientRegistration method getClient.
/**
* Handles GET requests to the OpenId Connect client registration endpoint for retrieving OpenId Connect client
* registrations.
*
* @return The representation of the client registration details.
* @throws OAuth2RestletException If an error occurs whilst retrieving the client registration.
*/
@Get
public Representation getClient() throws OAuth2RestletException {
final OAuth2Request request = requestFactory.create(getRequest());
final String clientId = request.getParameter(OAuth2Constants.OAuth2Client.CLIENT_ID);
final String accessToken = getRequest().getChallengeResponse().getRawValue();
try {
final JsonValue registration = clientRegistrationService.getRegistration(clientId, accessToken, request);
return jacksonRepresentationFactory.create(registration.asMap());
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
}
}
use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class OpenIDTokenIssuer method issueToken.
/**
* Issues an OpenId Connect token, using the details of the access token.
*
* @param accessToken The access token requested by the OAuth2 request.
* @param request The OAuth2 request.
* @return A {@code Map.Entry} of the token name with the Token instance.
* @throws ServerException If any internal server error occurs.
* @throws InvalidClientException If either the request does not contain the client's id or the client fails to be
* authenticated.
* @throws NotFoundException If the realm does not have an OAuth 2.0 provider service.
*/
public Map.Entry<String, String> issueToken(AccessToken accessToken, OAuth2Request request) throws ServerException, InvalidClientException, NotFoundException {
final Set<String> scope = accessToken.getScope();
if (scope != null && scope.contains(OAuth2Constants.Params.OPENID)) {
final ResourceOwner resourceOwner;
try {
request.setSession(accessToken.getSessionId());
resourceOwner = resourceOwnerSessionValidator.validate(request);
final String nonce = accessToken.getNonce();
final OpenIdConnectToken openIdToken = tokenStore.createOpenIDToken(resourceOwner, accessToken.getClientId(), accessToken.getClientId(), nonce, getOps(accessToken, request), request);
final SignedJwt signedJwt = openIdToken.sign();
return new AbstractMap.SimpleEntry<String, String>(OAuth2Constants.JWTTokenParams.ID_TOKEN, signedJwt.build());
} catch (SignatureException e) {
logger.error("Unable to sign JWT", e);
throw new ServerException("Cant sign JWT");
} catch (OAuth2Exception e) {
logger.error("User must be authenticated to issue ID tokens.", e);
throw new ServerException("User must be authenticated to issue ID tokens.");
}
}
return null;
}
Aggregations