Class OAuth2Request


  • public class OAuth2Request
    extends Object
    An abstraction of the actual request so as to allow the core of the OAuth2 provider to be agnostic of the library used to translate the HTTP request.
    Since:
    12.0.0
    • Constructor Detail

      • OAuth2Request

        @Inject
        public OAuth2Request​(JacksonRepresentationFactory jacksonRepresentationFactory,
                             org.restlet.Request request)
        Constructs a new RestletOAuth2Request.
        Parameters:
        jacksonRepresentationFactory - The factory class for JacksonRepresentation.
        request - The Restlet request.
    • Method Detail

      • getRequest

        public org.restlet.Request getRequest()
        Gets the actual underlying request.
        Returns:
        The underlying request.
      • getParameter

        public <T> T getParameter​(String name)
        Gets the specified parameter from the request.
        It is up to the implementation to determine how and where it gets the parameter from on the request, i.e. query parameters, request attributes, etc.
        Type Parameters:
        T - The type of the parameter.
        Parameters:
        name - The name of the parameter.
        Returns:
        The parameter value.
      • getQueryParameter

        public String getQueryParameter​(String name)
        Gets the specified parameter from the request's query string only, ignoring any request attribute or request body carrying the same name.
        Parameters:
        name - The name of the parameter.
        Returns:
        The query string value, or null if the query string does not carry the parameter.
      • getBodyParameter

        public String getBodyParameter​(String name)
        Gets the specified parameter from the request's body only, ignoring any request attribute or query string parameter carrying the same name. Both body encodings getParameter(String) understands are read, so that a caller cannot be told one thing by a form encoded body and another by a JSON one.

        getParameter(String) gives the query string priority over the body and so cannot tell the two apart. A caller that has to - because the same name arriving from both places means something different from it arriving from one - reads each side with this method and getQueryParameter(String).

        Parameters:
        name - The name of the parameter.
        Returns:
        The body value, or null if the request carries no body with that parameter.
      • getParameterCount

        public int getParameterCount​(String name)
        Gets the count of the parameter present in the request with the given name
        Parameters:
        name - The name of the parameter
        Returns:
        The count of the the parameter with the given name
      • getParameterNames

        public Set<String> getParameterNames()
        Gets the name of the parameters in the current request
        Returns:
        The parameter names in the request
      • getBody

        public org.forgerock.json.JsonValue getBody()
        Gets the body of the request.
        Note: reading of the body maybe a one time only operation, so the implementation needs to cache the content of the body so multiple calls to this method do not behave differently.
        This method should only ever be called for access and refresh token request and requests to the userinfo and tokeninfo endpoints.
        Returns:
        The body of the request.
      • setToken

        public <T extends Token> void setToken​(Class<T> tokenClass,
                                               T token)
        Set a Token that is in play for this request.
        Type Parameters:
        T - The type of token.
        Parameters:
        tokenClass - The token type.
        token - The token instance.
      • getToken

        public <T extends Token> T getToken​(Class<T> tokenClass)
        Get a Token that is in play for this request.
        Type Parameters:
        T - The type of token.
        Parameters:
        tokenClass - The token type.
        Returns:
        The token instance.
      • getTokens

        public Collection<Token> getTokens()
        Get all the tokens that have been used in this request.
        Returns:
        The token instances.
      • setSession

        public void setSession​(String sessionId)
        Sets the user's session for this request.
        Parameters:
        sessionId - The user's session.
      • getSession

        public String getSession()
        Gets the user's session for this request.
        Returns:
        The user's session.
      • getLocale

        public Locale getLocale()
        Get the request locale.
        Returns:
        The Locale object.
      • getClientRegistration

        public ClientRegistration getClientRegistration()
        Get the OAuth2 client registration of the request.
        Returns:
        The client registration.
      • forRealm

        public static OAuth2Request forRealm​(String realm)
        Creates an OAuth2Request which holds the provided realm only.
        Parameters:
        realm - The request realm.
        Returns:
        An OAuth2Request.
      • setClientRegistration

        public void setClientRegistration​(ClientRegistration clientRegistration)
        Set the OAuth2 client registration.
        Parameters:
        clientRegistration - The client registration.