com.veriplace.oauth.consumer
Class Consumer

java.lang.Object
  extended by com.veriplace.oauth.consumer.Consumer

public class Consumer
extends java.lang.Object

Consumer representation as defined by OAuth 1.0, section 4.


Field Summary
protected  Client client
          Client to use for requests.
protected  java.lang.String consumerKey
          The OAuth consumer key.
protected  java.lang.String consumerSecret
          The OAuth consumer secret.
protected  NonceFactory nonceFactory
          Factory for generating a nonce.
protected  Revision revision
          Revision of OAuth to use for requests, e.g.
protected  ServiceProvider serviceProvider
          The OAuth service provider that issues the consumer key and secret and that will be asked for authorization.
protected  TimestampFactory timestampFactory
          Factory for generating a timestamp.
 
Constructor Summary
Consumer(java.lang.String consumerKey, java.lang.String consumerSecret, ServiceProvider serviceProvider)
          Create a Consumer of OAuth.
Consumer(java.lang.String consumerKey, java.lang.String consumerSecret, ServiceProvider serviceProvider, Revision revision)
          Create a Consumer of OAuth.
 
Method Summary
protected  Request createRequest(java.net.URL requestUrl, RequestType requestType, RequestMethod requestMethod, ParameterSet requestParameters, ParameterSet additionalParameters, java.lang.Integer soTimeout, Token token, java.lang.String contentType, SignatureMethod... signatureMethods)
          Generalized request factory method.
 Token getAccessToken(RequestMethod requestMethod, Token requestToken, java.lang.String verifier, java.lang.Integer soTimeout, SignatureMethod... signatureMethods)
          Get an access token using custom arguments.
 Token getAccessToken(Token requestToken)
          Get an access token using POST, HMAC-SHA1, and no additional parameters.
 Token getAccessToken(Token requestToken, java.lang.String verifier)
          Get an access token using POST, HMAC-SHA1, and no additional parameters.
 Client getClient()
          Get the current Client instance.
 java.lang.String getConsumerKey()
          Get the consumer key value.
 java.lang.String getConsumerSecret()
          Get the consumer secret value.
 Response getProtectedResource(java.net.URL protectedResourceUrl, RequestMethod requestMethod, ParameterSet additionalParameters, Token accessToken, java.lang.Integer soTimeout, java.lang.String contentType, SignatureMethod... signatureMethods)
          Get a protected resource.
 Response getProtectedResource(java.net.URL protectedResourceUrl, RequestMethod requestMethod, Token accessToken, ParameterSet additionalParameters)
          Get a protected resource.
 Response getProtectedResource(java.net.URL protectedResourceUrl, RequestMethod requestMethod, Token accessToken, ParameterSet additionalParameters, java.lang.String contentType)
          Get a protected resource, specifying the desired content type.
 Token getRequestToken()
          Get a request token using POST, HMAC-SHA1, and no additional parameters.
 Token getRequestToken(RequestMethod requestMethod, java.lang.String callback, ParameterSet additionalParameters, java.lang.Integer soTimeout, SignatureMethod... signatureMethods)
          Get a request token using custom arguments.
 Token getRequestToken(java.lang.String callback)
          Get a request token using POST, HMAC-SHA1, and an oauth_callback.
 Token getRequestToken(java.lang.String callback, ParameterSet parameters)
          Get a request token using POST, HMAC-SHA1, an oauth_callback, and optional special parameters.
protected  Response getResponse(Request request)
          Generalized request method.
 Revision getRevision()
          Get the OAuth protocol revision used by this consumer.
 java.lang.String getUserAuthorizationUrl(ParameterSet additionalParameters, Token requestToken)
          Get a user authorization URL for redirection using GET.
 java.lang.String getUserAuthorizationUrl(ParameterSet additionalParameters, Token requestToken, java.lang.Integer soTimeout)
          Get a user authorization URL for redirection using GET.
 void setClient(Client client)
          Consumer supports alternate Client implementations, especially for test scenarios.
 void setDefaultParameters(ParameterSet requestParameters)
          Set default request parameters, including: oauth_version oauth_consumer_key oauth_timestamp oauth_nonce
 void setNonceFactory(NonceFactory nonceFactory)
          Consumer supports alternate NonceFactory implementations, especially for test scenarios.
 void setTimestampFactory(TimestampFactory timestampFactory)
          Consumer supports alternate TimestampFactory implemenations, especially for test scenarios.
 void setTokenParameters(ParameterSet requestParameters, Token token)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumerKey

protected final java.lang.String consumerKey
The OAuth consumer key.


consumerSecret

protected final java.lang.String consumerSecret
The OAuth consumer secret.


serviceProvider

protected final ServiceProvider serviceProvider
The OAuth service provider that issues the consumer key and secret and that will be asked for authorization.


timestampFactory

protected TimestampFactory timestampFactory
Factory for generating a timestamp. Defaults to SystemTimestampFactory


nonceFactory

protected NonceFactory nonceFactory
Factory for generating a nonce. Defaults to IncrementalNonceFactory


client

protected Client client
Client to use for requests. Defaults to CommonsHttpClient


revision

protected final Revision revision
Revision of OAuth to use for requests, e.g. Rev A.

Constructor Detail

Consumer

public Consumer(java.lang.String consumerKey,
                java.lang.String consumerSecret,
                ServiceProvider serviceProvider)
         throws java.security.NoSuchAlgorithmException
Create a Consumer of OAuth. The Consumer Key and Consumer Secret are to be provided by the Service Provider.

Throws:
java.security.NoSuchAlgorithmException

Consumer

public Consumer(java.lang.String consumerKey,
                java.lang.String consumerSecret,
                ServiceProvider serviceProvider,
                Revision revision)
         throws java.security.NoSuchAlgorithmException
Create a Consumer of OAuth. The Consumer Key and Consumer Secret are to be provided by the Service Provider.

Throws:
java.security.NoSuchAlgorithmException
Method Detail

getConsumerKey

public final java.lang.String getConsumerKey()
Get the consumer key value.


getConsumerSecret

public final java.lang.String getConsumerSecret()
Get the consumer secret value.


getClient

public Client getClient()
Get the current Client instance.


getRevision

public Revision getRevision()
Get the OAuth protocol revision used by this consumer.


setTimestampFactory

public void setTimestampFactory(TimestampFactory timestampFactory)
Consumer supports alternate TimestampFactory implemenations, especially for test scenarios.


setNonceFactory

public void setNonceFactory(NonceFactory nonceFactory)
Consumer supports alternate NonceFactory implementations, especially for test scenarios.


setClient

public void setClient(Client client)
Consumer supports alternate Client implementations, especially for test scenarios.


getRequestToken

public Token getRequestToken()
                      throws OAuthException,
                             java.io.IOException
Get a request token using POST, HMAC-SHA1, and no additional parameters.

This method should only be used for OAuth Core (not Rev A).

Throws:
OAuthException
java.io.IOException

getRequestToken

public Token getRequestToken(java.lang.String callback)
                      throws OAuthException,
                             java.io.IOException
Get a request token using POST, HMAC-SHA1, and an oauth_callback.

This method should be used for OAuth Core Rev A.

Throws:
OAuthException
java.io.IOException

getRequestToken

public Token getRequestToken(java.lang.String callback,
                             ParameterSet parameters)
                      throws OAuthException,
                             java.io.IOException
Get a request token using POST, HMAC-SHA1, an oauth_callback, and optional special parameters.

This method should be used for OAuth Core Rev A.

Throws:
OAuthException
java.io.IOException

getAccessToken

public Token getAccessToken(Token requestToken)
                     throws OAuthException,
                            java.io.IOException
Get an access token using POST, HMAC-SHA1, and no additional parameters.

This method should only be used for OAuth Core (not Rev A).

Parameters:
requestToken - the requestToken for this request
Throws:
OAuthException
java.io.IOException

getAccessToken

public Token getAccessToken(Token requestToken,
                            java.lang.String verifier)
                     throws OAuthException,
                            java.io.IOException
Get an access token using POST, HMAC-SHA1, and no additional parameters.

This method should be used for OAuth Core Rev A.

Parameters:
requestToken - the requestToken for this request
verifier - the verifier value from the callback
Throws:
OAuthException
java.io.IOException

getUserAuthorizationUrl

public java.lang.String getUserAuthorizationUrl(ParameterSet additionalParameters,
                                                Token requestToken)
                                         throws OAuthException,
                                                java.io.IOException
Get a user authorization URL for redirection using GET.

Parameters:
additionalParameters - any additional parameters to be sent, may be null
requestToken - the requestToken for this request
Throws:
OAuthException
java.io.IOException

getProtectedResource

public Response getProtectedResource(java.net.URL protectedResourceUrl,
                                     RequestMethod requestMethod,
                                     Token accessToken,
                                     ParameterSet additionalParameters,
                                     java.lang.String contentType)
                              throws OAuthException,
                                     java.io.IOException
Get a protected resource, specifying the desired content type. The content type will be passed in the HTTP Accept header.

Parameters:
protectedResourceUrl - the URL of the protected resource
requestMethod - the request method to use (e.g. GET or POST)
accessToken - the accessToken for this resource
additionalParameters - any additional parameters to be sent, may be null
contentType - the desired MIME content type of the resource
Throws:
OAuthException
java.io.IOException

getProtectedResource

public Response getProtectedResource(java.net.URL protectedResourceUrl,
                                     RequestMethod requestMethod,
                                     Token accessToken,
                                     ParameterSet additionalParameters)
                              throws OAuthException,
                                     java.io.IOException
Get a protected resource.

Parameters:
protectedResourceUrl - the URL of the protected resource
requestMethod - the request method to use (e.g. GET or POST)
additionalParameters - any additional parameters to be sent, may be null
accessToken - the accessToken for this resource
Throws:
OAuthException
java.io.IOException

getRequestToken

public Token getRequestToken(RequestMethod requestMethod,
                             java.lang.String callback,
                             ParameterSet additionalParameters,
                             java.lang.Integer soTimeout,
                             SignatureMethod... signatureMethods)
                      throws OAuthException,
                             java.io.IOException
Get a request token using custom arguments.

Parameters:
requestMethod - the request method to use (POST is default)
callback - the oauth_callback as required by OAuth Core 1.0 Rev A
additionalParameters - any additional parameters to be sent, may be null
soTimeout - read socket timeout
signatureMethods - the desired signature method(s), in order of preference
Returns:
an OAuth Request Token; will not be null
Throws:
OAuthException - if the server returns an OAuth error
java.io.IOException - if there is an I/O error in communication with the server

getUserAuthorizationUrl

public java.lang.String getUserAuthorizationUrl(ParameterSet additionalParameters,
                                                Token requestToken,
                                                java.lang.Integer soTimeout)
                                         throws OAuthException,
                                                java.io.IOException
Get a user authorization URL for redirection using GET.

Parameters:
additionalParameters - any additional parameters to be sent, may be null
requestToken - the requestToken for this request
soTimeout - read socket timeout
Throws:
OAuthException
java.io.IOException

getAccessToken

public Token getAccessToken(RequestMethod requestMethod,
                            Token requestToken,
                            java.lang.String verifier,
                            java.lang.Integer soTimeout,
                            SignatureMethod... signatureMethods)
                     throws OAuthException,
                            java.io.IOException
Get an access token using custom arguments.

Parameters:
requestMethod - the request method to use (POST is default)
requestToken - the requestToken for this request
soTimeout - read socket timeout
signatureMethods - the desired signature method(s), in order of preference
Returns:
an OAuth Access Token; will not be null
Throws:
OAuthException - if the server returns an OAuth error
java.io.IOException - if there is an I/O error in communication with the server

getProtectedResource

public Response getProtectedResource(java.net.URL protectedResourceUrl,
                                     RequestMethod requestMethod,
                                     ParameterSet additionalParameters,
                                     Token accessToken,
                                     java.lang.Integer soTimeout,
                                     java.lang.String contentType,
                                     SignatureMethod... signatureMethods)
                              throws OAuthException,
                                     java.io.IOException
Get a protected resource.

Parameters:
protectedResourceUrl - the URL of the protected resource
requestMethod - the request method to use (e.g. GET or POST)
additionalParameters - any additional parameters to be sent, may be null
soTimeout - read socket timeout
accessToken - the accessToken for this resource
contentType - the desired MIME content type, if any
signatureMethods - the desired signature method(s), in order of preference
Throws:
OAuthException
java.io.IOException

createRequest

protected Request createRequest(java.net.URL requestUrl,
                                RequestType requestType,
                                RequestMethod requestMethod,
                                ParameterSet requestParameters,
                                ParameterSet additionalParameters,
                                java.lang.Integer soTimeout,
                                Token token,
                                java.lang.String contentType,
                                SignatureMethod... signatureMethods)
                         throws OAuthException,
                                java.io.IOException
Generalized request factory method.

Throws:
OAuthException
java.io.IOException

getResponse

protected Response getResponse(Request request)
                        throws OAuthException,
                               java.io.IOException
Generalized request method.

Returns:
a response which is guaranteed not to be an error response (isOk() is true)
Throws:
OAuthException - if the server returns an OAuth error
java.io.IOException - if there is an I/O error in communication with the server

setDefaultParameters

public void setDefaultParameters(ParameterSet requestParameters)
Set default request parameters, including:


setTokenParameters

public void setTokenParameters(ParameterSet requestParameters,
                               Token token)
                        throws OAuthException
Throws:
OAuthException