public class OslcOAuthService extends Object
This class is recommended to be used in conjunction with RedirectOAuthHandler
.
RedirectOAuthHandler
Constructor and Description |
---|
OslcOAuthService() |
Modifier and Type | Method and 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 authorization 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 |
showLoginPage()
Shows a default login page.
|
public static URI getDefaultLoginPageLocation(HttpServletRequest request, String relativePath) throws IOException
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.
request
- the HTTP request.relativePath
- the relative path to the login page, e.g. "/oauth/login"
.IOException
- on I/O errors.public static void generateAccessToken(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
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.
httpRequest
- the HTTP request.httpResponse
- the HTTP responseIOException
- on I/O errorsServletException
- on servlet errorspublic Response getRequestToken() throws IOException, ServletException
IOException
- on I/O errorsServletException
- on servlet errorspublic Response postRequestToken() throws IOException, ServletException
IOException
- on I/O errorsServletException
- on servlet errorspublic Response getAccessToken() throws IOException, ServletException
IOException
- on I/O errorsServletException
- on servlet errorspublic Response postAccessToken() throws IOException, ServletException
IOException
- on I/O errorsServletException
- on servlet errorspublic Response approveRequestToken(String requestToken) throws IOException, ServletException
requestToken
- the request token to approve, for future exchange with an access token.IOException
- on I/O errorsServletException
- on internal errors validating the requestpublic Response authorize() throws ServletException, IOException
IOException
- on I/O errorsServletException
- on internal errors validating the requestpublic Response showLoginPage() throws IOException, ServletException
IOException
- on I/O errorsServletException
- on internal errors validating the requestgetDefaultLoginPageLocation(HttpServletRequest, String)
public Response login(String id, String password, String requestToken)
id
- the user ID.password
- the user password.requestToken
- the OAuth request tokenpublic Response callback(String verifierId, String verifier, String redirect) throws IOException, ServletException
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).
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.redirect
page, if any, or the content of the callback page.IOException
- if the target resource throws this exception.ServletException
- if the target resource throws this exception.public Response generateProvisionalConsumerKey() throws IOException
IOException
- on I/O errorspublic Response showApproveProvisionalConsumerPage(String key) throws IOException, ServletException
key
- the consumer key.IOException
- on I/O errorsServletException
- on internal errors validating the requestpublic Response approveProvisionalConsumer(String consumerName, String consumerKey, boolean trusted, boolean approve) throws ServletException, IOException
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.IOException
- on I/O errorsServletException
- on internal errors validating the request