|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jersey.api.client.filter.ClientFilter
com.sun.jersey.oauth.client.OAuthClientFilter
public final class OAuthClientFilter
Client filter adding OAuth authorization header to the HTTP request, if no authorization header is already present. If the URI's for requesting request and access tokens and authorization are provided, as well as the AuthHandler implementation, the filter also takes care of handling the OAuth authorization flow.
Note: This filter signs the request based on its request parameters. For this reason, you should invoke this filter after any others that modify any request parameters.
Example 1:
// baseline OAuth parameters for access to resource OAuthParameters params = new OAuthParameters().signatureMethod("HMAC-SHA1"). consumerKey("key").setToken("accesskey"); // OAuth secrets to access resource OAuthSecrets secrets = new OAuthSecrets().consumerSecret("secret").setTokenSecret("accesssecret"); // if parameters and secrets remain static, filter can be added to each web resource OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets); // OAuth test server WebResource resource = client.resource("http://term.ie/oauth/example/request_token.php"); resource.addFilter(filter); String response = resource.get(String.class);
Example 2 (handling authorization flow):
OAuthClientFilter filter = new OAuthClientFilter( client.getProviders(), new OAuthParameters().consumerKey("key"), new OAuthSecrets().consumerSecret("secret"), "http://request.token.uri", "http://access.token.uri", "http://authorization.uri", new OAuthClientFilter.AuthHandler() {
Nested Class Summary | |
---|---|
static interface |
OAuthClientFilter.AuthHandler
Implementation of this interface should be passed to the filter constructor to handle user authorization requests and respond to obtaining a new access token (e.g. |
Constructor Summary | |
---|---|
OAuthClientFilter(Providers providers,
OAuthParameters parameters,
OAuthSecrets secrets)
Constructs a new OAuth client filter with the specified providers. |
|
OAuthClientFilter(Providers providers,
OAuthParameters parameters,
OAuthSecrets secrets,
java.lang.String requestTokenUri,
java.lang.String accessTokenUri,
java.lang.String authorizationUri,
OAuthClientFilter.AuthHandler handler)
Constructs a new OAuth client filter providing URI's for requesting request and access tokens and authorization. |
Method Summary | |
---|---|
ClientResponse |
handle(ClientRequest request)
Note: This method automatically sets the nonce and timestamp. |
Methods inherited from class com.sun.jersey.api.client.filter.ClientFilter |
---|
getNext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OAuthClientFilter(Providers providers, OAuthParameters parameters, OAuthSecrets secrets)
providers
- the registered providers from Client.getProviders()
method.parameters
- the OAuth parameters to be used in signing requests.secrets
- the OAuth secrets to be used in signing requests.public OAuthClientFilter(Providers providers, OAuthParameters parameters, OAuthSecrets secrets, java.lang.String requestTokenUri, java.lang.String accessTokenUri, java.lang.String authorizationUri, OAuthClientFilter.AuthHandler handler)
providers
- the registered providers from Client.getProviders()
method.parameters
- the OAuthParameters to be used in signing requests.secrets
- the OAuth secrets to be used in signing requests.requestTokenUri
- URI for requesting new request tokens.accessTokenUri
- URI for requesting access tokens.authorizationUri
- URI for requesting authorization of request tokens.handler
- Implementation of AuthHandler this filter calls to obtain user authorization
and notify the application of a new access token obtained. If null is passed,
instead of invoking the handler for user authorization when needed,
UnauthorizedRequestException
is thrown by the filter.Method Detail |
---|
public ClientResponse handle(ClientRequest request) throws ClientHandlerException
handle
in interface ClientHandler
handle
in class ClientFilter
ClientHandlerException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |