Search in sources :

Example 1 with UnsupportedGrantTypeException

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()));
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) Finder(org.restlet.resource.Finder) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) UnsupportedGrantTypeException(org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) UnsupportedGrantTypeException(org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException)

Aggregations

OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 InvalidRequestException (org.forgerock.oauth2.core.exceptions.InvalidRequestException)1 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)1 UnsupportedGrantTypeException (org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException)1 Finder (org.restlet.resource.Finder)1