|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectoauth.signpost.AbstractOAuthConsumer
public abstract class AbstractOAuthConsumer
ABC for consumer implementations. If you're developing a custom consumer you will probably inherit from this class to save you a lot of work.
| Constructor Summary | |
|---|---|
AbstractOAuthConsumer(String consumerKey,
String consumerSecret)
|
|
| Method Summary | |
|---|---|
protected void |
collectBodyParameters(HttpRequest request,
HttpParameters out)
Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec section 9.1.1 |
protected void |
collectHeaderParameters(HttpRequest request,
HttpParameters out)
Collects OAuth Authorization header parameters as per OAuth Core 1.0 spec section 9.1.1 |
protected void |
collectQueryParameters(HttpRequest request,
HttpParameters out)
Collects HTTP GET query string parameters as per OAuth Core 1.0 spec section 9.1.1 |
protected void |
completeOAuthParameters(HttpParameters out)
Helper method that adds any OAuth parameters to the given request parameters which are missing from the current request but required for signing. |
protected String |
generateNonce()
|
protected String |
generateTimestamp()
|
String |
getConsumerKey()
|
String |
getConsumerSecret()
|
HttpParameters |
getRequestParameters()
Returns all parameters collected from the HTTP request during message signing (this means the return value may be NULL before a call to OAuthConsumer.sign(oauth.signpost.http.HttpRequest)), plus all required OAuth parameters that were added
because the request didn't contain them beforehand. |
String |
getToken()
|
String |
getTokenSecret()
|
void |
setAdditionalParameters(HttpParameters additionalParameters)
Allows you to add parameters (typically OAuth parameters such as oauth_callback or oauth_verifier) which will go directly into the signer, i.e. |
void |
setMessageSigner(OAuthMessageSigner messageSigner)
Sets the message signer that should be used to generate the OAuth signature. |
void |
setSendEmptyTokens(boolean enable)
Causes the consumer to always include the oauth_token parameter to be sent, even if blank. |
void |
setSigningStrategy(SigningStrategy signingStrategy)
Defines which strategy should be used to write a signature to an HTTP request. |
void |
setTokenWithSecret(String token,
String tokenSecret)
Sets the OAuth token and token secret used for message signing. |
HttpRequest |
sign(HttpRequest request)
Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it. |
HttpRequest |
sign(Object request)
Signs the given HTTP request by writing an OAuth signature (and other required OAuth parameters) to it. |
String |
sign(String url)
"Signs" the given URL by appending all OAuth parameters to it which are required for message signing. |
protected abstract HttpRequest |
wrap(Object request)
Adapts the given request object to a Signpost HttpRequest. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractOAuthConsumer(String consumerKey,
String consumerSecret)
| Method Detail |
|---|
public void setMessageSigner(OAuthMessageSigner messageSigner)
OAuthConsumer
setMessageSigner in interface OAuthConsumermessageSigner - the signerHmacSha1MessageSigner,
PlainTextMessageSignerpublic void setSigningStrategy(SigningStrategy signingStrategy)
OAuthConsumer
setSigningStrategy in interface OAuthConsumersigningStrategy - the strategyAuthorizationHeaderSigningStrategy,
QueryStringSigningStrategypublic void setAdditionalParameters(HttpParameters additionalParameters)
OAuthConsumerSigningStrategy will then take care of writing them to the
correct part of the request before it is sent. Note that these parameters
are expected to already be percent encoded -- they will be simply merged
as-is.
setAdditionalParameters in interface OAuthConsumeradditionalParameters - the parameters
public HttpRequest sign(HttpRequest request)
throws OAuthMessageSignerException,
OAuthExpectationFailedException,
OAuthCommunicationException
OAuthConsumerSigningStrategy.
sign in interface OAuthConsumerrequest - the request to sign
OAuthMessageSignerException
OAuthExpectationFailedException
OAuthCommunicationException
public HttpRequest sign(Object request)
throws OAuthMessageSignerException,
OAuthExpectationFailedException,
OAuthCommunicationException
OAuthConsumer
Signs the given HTTP request by writing an OAuth signature (and other
required OAuth parameters) to it. Where these parameters are written
depends on the current SigningStrategy.
sign in interface OAuthConsumerrequest - the request to sign
OAuthMessageSignerException
OAuthExpectationFailedException
OAuthCommunicationException
public String sign(String url)
throws OAuthMessageSignerException,
OAuthExpectationFailedException,
OAuthCommunicationException
OAuthConsumer"Signs" the given URL by appending all OAuth parameters to it which are required for message signing. The assumed HTTP method is GET. Essentially, this is equivalent to signing an HTTP GET request, but it can be useful if your application requires clickable links to protected resources, i.e. when your application does not have access to the actual request that is being sent.
sign in interface OAuthConsumerurl - the input URL. May have query parameters.
OAuthMessageSignerException
OAuthExpectationFailedException
OAuthCommunicationExceptionprotected abstract HttpRequest wrap(Object request)
HttpRequest. How
this is done depends on the consumer implementation.
request - the native HTTP request instance
public void setTokenWithSecret(String token,
String tokenSecret)
OAuthConsumer
setTokenWithSecret in interface OAuthConsumertoken - the tokentokenSecret - the token secretpublic String getToken()
getToken in interface OAuthConsumerpublic String getTokenSecret()
getTokenSecret in interface OAuthConsumerpublic String getConsumerKey()
getConsumerKey in interface OAuthConsumerpublic String getConsumerSecret()
getConsumerSecret in interface OAuthConsumerprotected void completeOAuthParameters(HttpParameters out)
Helper method that adds any OAuth parameters to the given request parameters which are missing from the current request but required for signing. A good example is the oauth_nonce parameter, which is typically not provided by the client in advance.
It's probably not a very good idea to override this method. If you want
to generate different nonces or timestamps, override
generateNonce() or generateTimestamp() instead.
out - the request parameter which should be completedpublic HttpParameters getRequestParameters()
OAuthConsumerOAuthConsumer.sign(oauth.signpost.http.HttpRequest)), plus all required OAuth parameters that were added
because the request didn't contain them beforehand. In other words, this
is the exact set of parameters that were used for creating the message
signature.
getRequestParameters in interface OAuthConsumerpublic void setSendEmptyTokens(boolean enable)
OAuthConsumer
Causes the consumer to always include the oauth_token parameter to be
sent, even if blank. If you're seeing 401s during calls to
OAuthProvider.retrieveRequestToken(oauth.signpost.OAuthConsumer, java.lang.String), try setting this to true.
setSendEmptyTokens in interface OAuthConsumerenable - true or false
protected void collectHeaderParameters(HttpRequest request,
HttpParameters out)
protected void collectBodyParameters(HttpRequest request,
HttpParameters out)
throws IOException
IOException
protected void collectQueryParameters(HttpRequest request,
HttpParameters out)
protected String generateTimestamp()
protected String generateNonce()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||