use of org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException in project OpenAM by OpenRock.
the class OAuth2FlowFinder method create.
/**
* Creates a new instance of the handler for the correct OAuth2 endpoint based from the grant type specified in
* the requests query parameters.
*
* @param request {@inheritDoc}
* @param response {@inheritDoc}
* @return {@inheritDoc}
*/
public ServerResource create(Request request, Response response) {
final OAuth2Request oAuth2Request = requestFactory.create(request);
final String grantType = oAuth2Request.getParameter("grant_type");
if (isEmpty(grantType)) {
logger.error("Type is not set");
return new ErrorResource(exceptionHandler, new InvalidRequestException("Grant type is not set"));
}
Finder finder = endpointClasses.get(grantType);
if (finder == null) {
logger.error("Unsupported grant type: Type is not supported: " + grantType);
return new ErrorResource(exceptionHandler, new UnsupportedGrantTypeException("Grant type is not supported: " + grantType));
}
try {
return finder.create(request, response);
} catch (Exception e) {
logger.warn("Exception while instantiating the target server resource.", e);
return new ErrorResource(exceptionHandler, new ServerException(e.getMessage()));
}
}
Aggregations