Class RedirectOAuthHandler

  • All Implemented Interfaces:
    OAuthHandler

    public class RedirectOAuthHandler
    extends Object
    implements OAuthHandler
    A OAuth connection handler targeted for OSLC provider applications. The handler uses a OAuth callback location that targets a servlet contributed by the implemented OSLC provider application.

    This class is recommended to be used in conjunction with OslcOAuthService.

    Since:
    1.3.0
    See Also:
    OslcOAuthService
    • Constructor Detail

      • RedirectOAuthHandler

        public RedirectOAuthHandler​(URI callbackLocation)
        Creates a handler that uses the specified callback location as base URL for the OAuth callback. When a OAuth callback is to compute, this handler will add the necessary query parameters to the base callback URL.
        Parameters:
        callbackLocation - the base URL used to compute an OAuth callback location, which must be a servlet contributed by the implemented OSLC provider application.
      • RedirectOAuthHandler

        public RedirectOAuthHandler​(URI callbackLocation,
                                    URI redirectLocation)
        Creates a handler that uses the specified callback location as base URL for the OAuth callback and redirect location when the OAuth challenge is completed. When a OAuth callback is to compute, this handler will add the necessary query parameters to the base callback URL. When the OAuth challenge is completed (i.e. the user has logged-in the remote OSLC application), the web browser will display the specified redirect location.
        Parameters:
        callbackLocation - the base URL used to compute an OAuth callback location, which must be a servlet contributed by the implemented OSLC provider application.
        redirectLocation - the URL the application should redirect to once the OAuth challenge is completed, null if none.
    • Method Detail

      • getRedirectLocation

        public static URI getRedirectLocation​(HttpServletRequest request)
        Returns the URL the application should redirect to once the OAuth challenge is completed. If the specified request is targeting HTML content, it is assumed the log-in to the remote OSLC application takes place in the web browser main window. In such case, this method returns the request location, so that once the log-in is completed the web page shows the location requested in the first place. If any other type of content is requested, it is assumed the log-in to the remote OSLC application takes place in a web browser pop-up. In such case, this method returns null, as there's no content to display in the pop-up once the log-in is completed.
        Parameters:
        request - the servlet request that triggers an OAuth challenge on an OSLC remote application.
        Returns:
        the URL the application should redirect to once the OAuth challenge is completed, null if none.
      • createCallback

        public URI createCallback​(RootServices rootServices,
                                  String verifierId)
        Returns a callback URL to use when an OAuth token is requested.

        The returned callback location combines the base URL provided in the constructor and following query parameters:

        • rootServices: the URL of the root services.
        • verifierId: the verifier ID used to approve the connection.
        • redirect: the URL the application should redirect to once the OAuth challenge is completed. This parameter is not set if no redirect location was provided in the constructor.
        Specified by:
        createCallback in interface OAuthHandler
        Parameters:
        rootServices - the root services of the target application.
        verifierId - the verifier ID used to approve the connection.
        Returns:
        a URL to be called by the target application when the OAuth connection is approved.
      • authorize

        public void authorize​(RootServices rootServices,
                              URI authorizationUri)
                       throws net.oauth.OAuthException
        Throws a RedirectOAuthException wrapping the specified authorization URI.
        Specified by:
        authorize in interface OAuthHandler
        Parameters:
        rootServices - the root services of the target application.
        authorizationUri - the URL to display in a web browser for the user to approve the connection.
        Throws:
        net.oauth.OAuthException - if the connection is not approved.
      • downstreamAuthorize

        public void downstreamAuthorize​(URI authorizationUri)
                                 throws net.oauth.OAuthException
        Throws a RedirectOAuthException wrapping the specified downstream authorization URI.
        Specified by:
        downstreamAuthorize in interface OAuthHandler
        Parameters:
        authorizationUri - the URL to display in a web browser for the user to approve the connection.
        Throws:
        net.oauth.OAuthException - if the connection is not approved.