Class OslcOAuthService
- java.lang.Object
-
- com.sodius.oslc.server.oauth.services.OslcOAuthService
-
public class OslcOAuthService extends Object
Services to support necessary OAuth end-points for connectivity from a OSLC Remote Application.This class is recommended to be used in conjunction with
RedirectOAuthHandler
.- Since:
- 1.3.0
- See Also:
RedirectOAuthHandler
-
-
Constructor Summary
Constructors Constructor Description OslcOAuthService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Response
approveProvisionalConsumer(String consumerName, String consumerKey, boolean trusted, boolean approve)
Approves or rejects the given provisional consumer key.Response
approveRequestToken(String requestToken)
Approves a request token, once user has authenticated and granted remote application to access data from the connector application.Response
authorize()
Responds with a web page to log in.Response
callback(String verifierId, String verifier, String redirect)
Implements the OAuth callback end-point, called by the remote application once user has successfully logged in and OAuth dance can be resumed.static void
generateAccessToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
Responds with an access token, exchanged from a request token and upon authorization.Response
generateProvisionalConsumerKey()
Generates a provisional consumer key.Response
getAccessToken()
Responds with an access token, exchanged from a request token and upon authorization.static URI
getDefaultLoginPageLocation(HttpServletRequest request, String relativePath)
Returns the URL of the default login page, given the relative path to the OAuth services.Response
getRequestToken()
Responds with a request token and token secret.Response
login(String id, String password, String requestToken)
Validates the ID and password on the authentication form.Response
postAccessToken()
Responds with an access token, exchanged from a request token and upon authorization.Response
postRequestToken()
Responds with a request token and token secret.Response
showApproveProvisionalConsumerPage(String key)
Shows the approval page for a provisional consumer.Response
showLoginBridgePage(URI redirectUri)
Provides an HTML to indicate the remote session has ended with a link to the login screen.Response
showLoginPage()
Shows a default login page.
-
-
-
Method Detail
-
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
public Response getRequestToken() throws IOException, ServletException
Responds with a request token and token secret.- Returns:
- the response
- Throws:
IOException
- on I/O errorsServletException
- on servlet errors
-
postRequestToken
public Response postRequestToken() throws IOException, ServletException
Responds with a request token and token secret.- Returns:
- the response
- Throws:
IOException
- on I/O errorsServletException
- on servlet errors
-
getAccessToken
public Response getAccessToken() throws IOException, ServletException
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
public Response postAccessToken() throws IOException, ServletException
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
public Response approveRequestToken(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
public Response authorize() throws ServletException, IOException
Responds with a web page to log in.- Returns:
- the response
- Throws:
IOException
- on I/O errorsServletException
- on internal errors validating the request
-
showLoginPage
public Response showLoginPage() throws IOException, ServletException
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:
getDefaultLoginPageLocation(HttpServletRequest, String)
-
showLoginBridgePage
public Response showLoginBridgePage(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:
OAuthApplication.sendUnauthorized(HttpServletRequest, HttpServletResponse)
-
login
public Response login(String id, String password, 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
public Response callback(String verifierId, String verifier, 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,null
if none.- Returns:
- a HTTP redirection to
redirect
page, 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
public Response generateProvisionalConsumerKey() throws IOException
Generates 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:
- Jazz Root Services Spec Addendum2
-
showApproveProvisionalConsumerPage
public Response showApproveProvisionalConsumerPage(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
public Response approveProvisionalConsumer(String consumerName, String consumerKey, boolean trusted, 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
-true
if the consumer is approved,false
if it is rejected.- Returns:
- the response.
- Throws:
IOException
- on I/O errorsServletException
- on internal errors validating the request
-
-