org.jboss.resteasy.auth.oauth
Class OAuthMemoryProvider

java.lang.Object
  extended by org.jboss.resteasy.auth.oauth.OAuthMemoryProvider
All Implemented Interfaces:
OAuthConsumerRegistration, OAuthProvider
Direct Known Subclasses:
MyProvider, OAuthDBProvider

public class OAuthMemoryProvider
extends java.lang.Object
implements OAuthProvider

OAuthProvider that keeps all data in memory. Mainly used as an example and for tests.

Author:
Stéphane Épardaud

Constructor Summary
OAuthMemoryProvider()
           
OAuthMemoryProvider(java.lang.String realm)
           
 
Method Summary
protected  OAuthConsumer _getConsumer(java.lang.String consumerKey)
           
protected  void addAccessKey(java.lang.String consumerKey, java.lang.String accessToken, java.lang.String accessSecret, java.lang.String[] permissions)
           
protected  void addConsumer(java.lang.String consumerKey, java.lang.String consumerSecret)
           
protected  void addRequestKey(java.lang.String consumerKey, java.lang.String requestToken, java.lang.String requestSecret, java.lang.String callback, java.lang.String[] scopes)
           
 java.lang.String authoriseRequestToken(java.lang.String consumerKey, java.lang.String requestToken)
          Authorises the given Request Token for the given Consumer and return a new Verifier to be returned to the Client.
protected  void authoriseRequestToken(java.lang.String consumerKey, java.lang.String requestToken, java.lang.String verifier)
           
 void checkTimestamp(OAuthToken token, long timestamp)
          Checks that the given timestamp is valid for the given OAuth Token.
 OAuthToken getAccessToken(java.lang.String consumerKey, java.lang.String accessToken)
          Returns the OAuth Access Token for the given Consumer key and Access Token.
 OAuthConsumer getConsumer(java.lang.String consumerKey)
          Returns the OAuth Consumer for the given Consumer key.
 java.lang.String getRealm()
          Returns the Realm of this provider
 OAuthRequestToken getRequestToken(java.lang.String requestToken)
           
 OAuthRequestToken getRequestToken(java.lang.String consumerKey, java.lang.String requestToken)
          Returns the OAuth Request Token for the given Consumer key and Request Token.
 OAuthToken makeAccessToken(java.lang.String consumerKey, java.lang.String requestToken, java.lang.String verifier)
          Make a new OAuth Access Token for the given Consumer, using the given Request Token and Verifier.
 OAuthRequestToken makeRequestToken(java.lang.String consumerKey, java.lang.String callback, java.lang.String[] scopes, java.lang.String[] permissions)
          Make a new OAuth Request Token for the given Consumer, using the given callback.
 OAuthConsumer registerConsumer(java.lang.String consumerKey, java.lang.String displayName, java.lang.String connectURI)
          Creates a new OAuth Consumer
 void registerConsumerPermissions(java.lang.String consumerKey, OAuthPermissions permissions)
          Registers Consumer Permissions
 void registerConsumerScopes(java.lang.String consumerKey, java.lang.String[] scopes)
          Registers Consumer Scopes
 OAuthRequestToken verifyAndRemoveRequestToken(java.lang.String customerKey, java.lang.String requestToken, java.lang.String verifier)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuthMemoryProvider

public OAuthMemoryProvider()

OAuthMemoryProvider

public OAuthMemoryProvider(java.lang.String realm)
Method Detail

verifyAndRemoveRequestToken

public OAuthRequestToken verifyAndRemoveRequestToken(java.lang.String customerKey,
                                                     java.lang.String requestToken,
                                                     java.lang.String verifier)
                                              throws OAuthException
Throws:
OAuthException

addConsumer

protected void addConsumer(java.lang.String consumerKey,
                           java.lang.String consumerSecret)

addRequestKey

protected void addRequestKey(java.lang.String consumerKey,
                             java.lang.String requestToken,
                             java.lang.String requestSecret,
                             java.lang.String callback,
                             java.lang.String[] scopes)
                      throws OAuthException
Throws:
OAuthException

addAccessKey

protected void addAccessKey(java.lang.String consumerKey,
                            java.lang.String accessToken,
                            java.lang.String accessSecret,
                            java.lang.String[] permissions)
                     throws OAuthException
Throws:
OAuthException

authoriseRequestToken

protected void authoriseRequestToken(java.lang.String consumerKey,
                                     java.lang.String requestToken,
                                     java.lang.String verifier)
                              throws OAuthException
Throws:
OAuthException

_getConsumer

protected OAuthConsumer _getConsumer(java.lang.String consumerKey)
                              throws OAuthException
Throws:
OAuthException

getRealm

public java.lang.String getRealm()
Description copied from interface: OAuthProvider
Returns the Realm of this provider

Specified by:
getRealm in interface OAuthProvider

authoriseRequestToken

public java.lang.String authoriseRequestToken(java.lang.String consumerKey,
                                              java.lang.String requestToken)
                                       throws OAuthException
Description copied from interface: OAuthProvider
Authorises the given Request Token for the given Consumer and return a new Verifier to be returned to the Client. If the given Consumer or Request Token do not exist, or if the Request Token has already been authorised, throw an OAuthException.

Specified by:
authoriseRequestToken in interface OAuthProvider
Parameters:
consumerKey - the Consumer Key whose Request Token we want to authorise
requestToken - the Request Token to authorise
Returns:
a Verifier associated with the newly-authorised Request Token.
Throws:
OAuthException - thrown if the given Consumer or Request Token do not exist, or if the Request Token has already been authorised.

registerConsumer

public OAuthConsumer registerConsumer(java.lang.String consumerKey,
                                      java.lang.String displayName,
                                      java.lang.String connectURI)
                               throws OAuthException
Description copied from interface: OAuthConsumerRegistration
Creates a new OAuth Consumer

Specified by:
registerConsumer in interface OAuthConsumerRegistration
Parameters:
consumerKey - the Consumer key.
Returns:
consumer secret.
Throws:
OAuthException - thrown if Consumer can not be registered.

getConsumer

public OAuthConsumer getConsumer(java.lang.String consumerKey)
                          throws OAuthException
Description copied from interface: OAuthProvider
Returns the OAuth Consumer for the given Consumer key. If no such Consumer exists, throw an OAuthException.

Specified by:
getConsumer in interface OAuthProvider
Parameters:
consumerKey - the Consumer key to load.
Returns:
the OAuth Consumer for the given Consumer key.
Throws:
OAuthException - thrown if the given Consumer does not exist.

getRequestToken

public OAuthRequestToken getRequestToken(java.lang.String consumerKey,
                                         java.lang.String requestToken)
                                  throws OAuthException
Description copied from interface: OAuthProvider
Returns the OAuth Request Token for the given Consumer key and Request Token. If no such Consumer or Request Token exist, throw an OAuthException.

Specified by:
getRequestToken in interface OAuthProvider
Parameters:
consumerKey - the Consumer key whose Request Token we want to load
requestToken - the Request Token to load
Returns:
the OAuth Request Token for the given Consumer key and Request Token
Throws:
OAuthException - thrown if the given Request Token does not exist.

getAccessToken

public OAuthToken getAccessToken(java.lang.String consumerKey,
                                 java.lang.String accessToken)
                          throws OAuthException
Description copied from interface: OAuthProvider
Returns the OAuth Access Token for the given Consumer key and Access Token. If no such Consumer or Access Token exist, throw an OAuthException.

Specified by:
getAccessToken in interface OAuthProvider
Parameters:
consumerKey - the Consumer key whose Access Token we want to load
Returns:
the OAuth Access Token for the given Consumer key and Access Token
Throws:
OAuthException - thrown if the given Consumer or Access Token do not exist.

checkTimestamp

public void checkTimestamp(OAuthToken token,
                           long timestamp)
                    throws OAuthException
Description copied from interface: OAuthProvider
Checks that the given timestamp is valid for the given OAuth Token. The timestamp should always be greater or equal to the last timestamp used for the given OAuth Token. The responsability to know whether the given OAuth Token is a Request or Access Token is left to the implementer. This method should associate and remember the given timestamp for the given Token if it is valid, since the message integrity has already been verified and we are guaranteed that the given timestamp comes from a message signed from the appropriate Consumer.

Specified by:
checkTimestamp in interface OAuthProvider
Parameters:
token - the OAuth Token whose timestamp to check and save if valid
timestamp - the timestamp to check and save if valid
Throws:
OAuthException - thrown if the given timestamp is not greater or equal to the last timestamp associated with the given OAuth Token

makeAccessToken

public OAuthToken makeAccessToken(java.lang.String consumerKey,
                                  java.lang.String requestToken,
                                  java.lang.String verifier)
                           throws OAuthException
Description copied from interface: OAuthProvider
Make a new OAuth Access Token for the given Consumer, using the given Request Token and Verifier. If the Request Token has not yet been authorised and/or does not match the given Specifier, throw an OAuthException.

Specified by:
makeAccessToken in interface OAuthProvider
Parameters:
consumerKey - the Consumer key for whom to create a new Access Token
requestToken - the Request Token to exchange for a new Access Token
verifier - the Client-specified Verifier that must match the Verifier that was given to the Client when the given Request Token was authorised.
Returns:
a new OAuth Access Token for the given Consumer
Throws:
OAuthException - thrown if the given Consumer or Request Token does not exist, if the Request Token is not authorised or if the Verifier is invalid.

makeRequestToken

public OAuthRequestToken makeRequestToken(java.lang.String consumerKey,
                                          java.lang.String callback,
                                          java.lang.String[] scopes,
                                          java.lang.String[] permissions)
                                   throws OAuthException
Description copied from interface: OAuthProvider
Make a new OAuth Request Token for the given Consumer, using the given callback.

Specified by:
makeRequestToken in interface OAuthProvider
Parameters:
consumerKey - the Consumer key for whom to create a new Request Token
callback - the Client-specified callback for this Request Token
scopes - resource URIs the consumer would like to access
Returns:
a new OAuth Request Token for the given Consumer
Throws:
OAuthException - thrown if the given Consumer does not exist

getRequestToken

public OAuthRequestToken getRequestToken(java.lang.String requestToken)
                                  throws OAuthException
Throws:
OAuthException

registerConsumerScopes

public void registerConsumerScopes(java.lang.String consumerKey,
                                   java.lang.String[] scopes)
                            throws OAuthException
Description copied from interface: OAuthConsumerRegistration
Registers Consumer Scopes

Specified by:
registerConsumerScopes in interface OAuthConsumerRegistration
Parameters:
consumerKey - the Consumer key.
Throws:
OAuthException - thrown if scopes can not be registered.

registerConsumerPermissions

public void registerConsumerPermissions(java.lang.String consumerKey,
                                        OAuthPermissions permissions)
                                 throws OAuthException
Description copied from interface: OAuthConsumerRegistration
Registers Consumer Permissions

Specified by:
registerConsumerPermissions in interface OAuthConsumerRegistration
Parameters:
consumerKey - the Consumer key.
Throws:
OAuthException - thrown if permissions can not be registered.


Copyright © 2010. All Rights Reserved.