Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.jersey.oauth.client
Class OAuthClientFilter

    java.lang.Object
      com.sun.jersey.api.client.filter.ClientFilter
          com.sun.jersey.oauth.client.OAuthClientFilter

All Implemented Interfaces:
  ClientHandler

    public final class OAuthClientFilter

extends ClientFilter

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() {

    Author:
      Paul C. Bryan , Martin Matula

    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

    OAuthClientFilter

    public OAuthClientFilter(Providers providers,
                             OAuthParameters parameters,
                             OAuthSecrets secrets)

    Constructs a new OAuth client filter with the specified providers.

    Parameters: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.

    OAuthClientFilter

    public 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. Passing these URI's will
     cause the filter will automatically attempt to obtain the tokens based
     if it receives 401 Unauthorized http status code.

    Parameters: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

    handle

    public ClientResponse handle(ClientRequest request)
                          throws ClientHandlerException

    Note: This method automatically sets the nonce and timestamp.

    Specified by:handle in interface ClientHandlerSpecified by:handle in class ClientFilter

    Throws:
    ClientHandlerException

          Package
        Class
          Use
          Tree
          Deprecated
          Index
          Help

     PREV CLASS
     NEXT CLASS

      FRAMES
     NO FRAMES

      SUMMARY: NESTED | FIELD | CONSTR | METHOD

    DETAIL: FIELD | CONSTR | METHOD

    Copyright © 2013 Oracle Corporation. All Rights Reserved.