Class OslcOAuthService
This class is recommended to be used in conjunction with RedirectOAuthHandler.
- Since:
- 1.3.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapproveProvisionalConsumer(String consumerName, String consumerKey, boolean trusted, boolean approve) Approves or rejects the given provisional consumer key.approveRequestToken(String requestToken) Approves a request token, once user has authenticated and granted remote application to access data from the connector application.Responds with a web page to log in.Implements the OAuth callback end-point, called by the remote application once user has successfully logged in and OAuth dance can be resumed.static voidgenerateAccessToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse) Responds with an access token, exchanged from a request token and upon authorization.Generates a provisional consumer key.Responds with an access token, exchanged from a request token and upon authorization.static URIgetDefaultLoginPageLocation(HttpServletRequest request, String relativePath) Returns the URL of the default login page, given the relative path to the OAuth services.Responds with a request token and token secret.Validates the ID and password on the authentication form.Responds with an access token, exchanged from a request token and upon authorization.Responds with a request token and token secret.Shows the approval page for a provisional consumer.showLoginBridgePage(URI redirectUri) Provides an HTML to indicate the remote session has ended with a link to the login screen.Shows a default login page.
-
Constructor Details
-
OslcOAuthService
public OslcOAuthService()
-
-
Method Details
-
getDefaultLoginPageLocation
public static URI getDefaultLoginPageLocation(HttpServletRequest request, String relativePath) throws IOException Returns the URL of the default login page, given the relative path to the OAuth services.This method appends the given relative path to the context path of the HTTP request to obtain an absolute URL. It also adds those query parameters:
oauth_token- the OAuth request token, if any.callback- the given HTTP request URL, to redirect to once login is completed.
Note that most connectors are rather expected to use the login screen provided by the underlying application. This login screen is mostly for demonstration purpose.
- Parameters:
request- the HTTP request.relativePath- the relative path to the login page, e.g."/oauth/login".- Returns:
- the URL of the login page.
- Throws:
IOException- on I/O errors.- Since:
- 2.0.0
-
generateAccessToken
public static void generateAccessToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException Responds with an access token, exchanged from a request token and upon authorization.The generation of the access token is usually directly handled by an end point provided by this class. Some connectors might need to perform this generation directly at HTTP filter level, so that the underlying application does not intercept the request and tries handling it on its own, thus conflicting with the OAuth capabilities provided by the connector.
- Parameters:
httpRequest- the HTTP request.httpResponse- the HTTP response- Throws:
IOException- on I/O errorsServletException- on servlet errors- Since:
- 2.0.0
-
getRequestToken
Responds with a request token and token secret.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on servlet errors
-
postRequestToken
@POST @Path("/requestToken") public Response postRequestToken() throws IOException, ServletExceptionResponds with a request token and token secret.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on servlet errors
-
getAccessToken
Responds with an access token, exchanged from a request token and upon authorization.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on servlet errors
-
postAccessToken
Responds with an access token, exchanged from a request token and upon authorization.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on servlet errors
-
approveRequestToken
@POST @Path("/internal/approveToken") public Response approveRequestToken(@FormParam("requestToken") String requestToken) throws IOException, ServletException Approves a request token, once user has authenticated and granted remote application to access data from the connector application. This is intended to be invoked by an XHR on the OAuth access authorization page.- Parameters:
requestToken- the request token to approve, for future exchange with an access token.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on internal errors validating the request
-
authorize
Responds with a web page to log in.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on internal errors validating the request
-
showLoginPage
Shows a default login page. This is mostly for demonstration purpose. In most cases, a connector should rather use the login page provided by the underlying application.- Returns:
- the response
- Throws:
IOException- on I/O errorsServletException- on internal errors validating the request- See Also:
-
showLoginBridgePage
@GET @Path("/login-bridge") @Produces("text/html") public Response showLoginBridgePage(@QueryParam("redirectUri") URI redirectUri) throws IOException Provides an HTML to indicate the remote session has ended with a link to the login screen.- Parameters:
redirectUri- the URI to redirect to- Returns:
- an HTML with a message indicating the remote session has ended
- Throws:
IOException- if the login page cannot be rendered.- Since:
- 3.7.0
- See Also:
-
login
@POST @Path("/login") public Response login(@FormParam("id") String id, @FormParam("password") String password, @FormParam("requestToken") String requestToken) Validates the ID and password on the authentication form. This is intended to be invoked by an XHR on the login page.- Parameters:
id- the user ID.password- the user password.requestToken- the OAuth request token- Returns:
- the response, 409 if login failed or 204 if successful
-
callback
@GET @Path("callback") public Response callback(@QueryParam("verifierId") String verifierId, @QueryParam("oauth_verifier") String verifier, @QueryParam("redirect") String redirect) throws IOException, ServletException Implements the OAuth callback end-point, called by the remote application once user has successfully logged in and OAuth dance can be resumed.This method stores the approved OAuth connection. It then replies with a temporary redirect to the specified redirect location, if any, or forwards to another resource (servlet, JSP or HTML file).
- Parameters:
verifierId- the identity of the verifier.verifier- the OAuth verifier, approving the specified verifier id.redirect- the URL the application should redirect to,nullif none.- Returns:
- a HTTP redirection to
redirectpage, if any, or the content of the callback page. - Throws:
IOException- if the target resource throws this exception.ServletException- if the target resource throws this exception.
-
generateProvisionalConsumerKey
@POST @Path("/requestKey") @Produces("application/json") public Response generateProvisionalConsumerKey() throws IOExceptionGenerates a provisional consumer key. This provisional key must be later approved by an administrator.- Returns:
- a JSON response with the provisional key
- Throws:
IOException- on I/O errors- See Also:
-
showApproveProvisionalConsumerPage
@GET @Path("/approveKey") @Produces("text/html") public Response showApproveProvisionalConsumerPage(@QueryParam("key") String key) throws IOException, ServletException Shows the approval page for a provisional consumer.- Parameters:
key- the consumer key.- Returns:
- the approval consumer page.
- Throws:
IOException- on I/O errorsServletException- on internal errors validating the request
-
approveProvisionalConsumer
@POST @Path("/approveKey") public Response approveProvisionalConsumer(@FormParam("consumerName") String consumerName, @FormParam("key") String consumerKey, @FormParam("trusted") boolean trusted, @FormParam("approve") boolean approve) throws ServletException, IOException Approves or rejects the given provisional consumer key. This is intended to be invoked by an XHR on the consumer approval page.- Parameters:
consumerName- the consumer name.consumerKey- the consumer key.trusted- whether the consumer key becomes trusted.approve-trueif the consumer is approved,falseif it is rejected.- Returns:
- the response.
- Throws:
IOException- on I/O errorsServletException- on internal errors validating the request
-