org.glassfish.jersey.server.oauth1
Class DefaultOAuth1Provider

java.lang.Object
  extended by org.glassfish.jersey.server.oauth1.DefaultOAuth1Provider
All Implemented Interfaces:
OAuth1Provider

@Provider
public class DefaultOAuth1Provider
extends Object
implements OAuth1Provider

Default in-memory implementation of OAuth1Provider. Stores consumers and tokens in static hash maps. Provides some additional helper methods for consumer and token management (registering new consumers, retrieving a list of all registered consumers per owner, listing the authorized tokens per principal, revoking tokens, etc.)

Author:
Martin Matula, Miroslav Fuksa (miroslav.fuksa at oracle.com)

Nested Class Summary
static class DefaultOAuth1Provider.Consumer
          Simple read-only implementation of OAuth1Consumer.
 class DefaultOAuth1Provider.Token
          Simple immutable implementation of OAuth1Token.
 
Constructor Summary
DefaultOAuth1Provider()
           
 
Method Summary
 void addAccessToken(String token, String secret, String consumerKey, String callbackUrl, Principal principal, Set<String> roles, javax.ws.rs.core.MultivaluedMap<String,String> attributes)
           
 String authorizeToken(DefaultOAuth1Provider.Token token, Principal userPrincipal, Set<String> roles)
          Authorizes a request token for given principal and roles and returns verifier.
 OAuth1Token getAccessToken(String token)
          Returns the access token by the consumer key and token value.
 Set<DefaultOAuth1Provider.Token> getAccessTokens(String principalName)
          Returns a list of access tokens authorized with the supplied principal name.
 DefaultOAuth1Provider.Consumer getConsumer(String consumerKey)
          Gets consumer corresponding to a given consumer key.
 Set<DefaultOAuth1Provider.Consumer> getConsumers(String owner)
          Returns a set of consumers registered by a given owner.
 DefaultOAuth1Provider.Token getRequestToken(String token)
          Returns the request token by the consumer key and token value.
 OAuth1Token newAccessToken(OAuth1Token requestToken, String verifier)
          Creates a new access token.
 OAuth1Token newRequestToken(String consumerKey, String callbackUrl, Map<String,List<String>> attributes)
          Creates a new request token for a given consumerKey.
protected  String newUUIDString()
          Generates a new non-guessable random string (used for token/customer strings, secrets and verifier.
 DefaultOAuth1Provider.Consumer registerConsumer(String owner, javax.ws.rs.core.MultivaluedMap<String,String> attributes)
          Register a new consumer.
 DefaultOAuth1Provider.Consumer registerConsumer(String owner, String key, String secret, javax.ws.rs.core.MultivaluedMap<String,String> attributes)
          Register a new consumer configured with Consumer Key.
 void revokeAccessToken(String token, String principalName)
          Checks if the supplied token is authorized for a given principal name and if so, revokes the authorization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultOAuth1Provider

public DefaultOAuth1Provider()
Method Detail

getConsumer

public DefaultOAuth1Provider.Consumer getConsumer(String consumerKey)
Description copied from interface: OAuth1Provider
Gets consumer corresponding to a given consumer key.

Specified by:
getConsumer in interface OAuth1Provider
Parameters:
consumerKey - consumer key
Returns:
corresponding consumer secret or null if no consumer with the given key is known

registerConsumer

public DefaultOAuth1Provider.Consumer registerConsumer(String owner,
                                                       javax.ws.rs.core.MultivaluedMap<String,String> attributes)
Register a new consumer.

Parameters:
owner - Identifier of the owner that registers the consumer (user ID or similar).
attributes - Additional attributes (name-values pairs - to store additional information about the consumer, such as name, URI, description, etc.)
Returns:
Consumer object for the newly registered consumer.

registerConsumer

public DefaultOAuth1Provider.Consumer registerConsumer(String owner,
                                                       String key,
                                                       String secret,
                                                       javax.ws.rs.core.MultivaluedMap<String,String> attributes)
Register a new consumer configured with Consumer Key.

Parameters:
owner - Identifier of the owner that registers the consumer (user ID or similar).
key - Consumer key.
secret - Consumer key secret.
attributes - Additional attributes (name-values pairs - to store additional information about the consumer, such as name, URI, description, etc.)
Returns:

getConsumers

public Set<DefaultOAuth1Provider.Consumer> getConsumers(String owner)
Returns a set of consumers registered by a given owner.

Parameters:
owner - Identifier of the owner that registered the consumers to be retrieved.
Returns:
consumers registered by the owner.

getAccessTokens

public Set<DefaultOAuth1Provider.Token> getAccessTokens(String principalName)
Returns a list of access tokens authorized with the supplied principal name.

Parameters:
principalName - Principal name for which to retrieve the authorized tokens.
Returns:
authorized access tokens.

authorizeToken

public String authorizeToken(DefaultOAuth1Provider.Token token,
                             Principal userPrincipal,
                             Set<String> roles)
Authorizes a request token for given principal and roles and returns verifier.

Parameters:
token - Request token to authorize.
userPrincipal - User principal to authorize the token for.
roles - Set of roles to authorize the token for.
Returns:
OAuth verifier value for exchanging this token for an access token.

revokeAccessToken

public void revokeAccessToken(String token,
                              String principalName)
Checks if the supplied token is authorized for a given principal name and if so, revokes the authorization.

Parameters:
token - Access token to revoke the authorization for.
principalName - Principal name the token is currently authorized for.

newUUIDString

protected String newUUIDString()
Generates a new non-guessable random string (used for token/customer strings, secrets and verifier.

Returns:
Random UUID string.

getRequestToken

public DefaultOAuth1Provider.Token getRequestToken(String token)
Description copied from interface: OAuth1Provider
Returns the request token by the consumer key and token value.

Specified by:
getRequestToken in interface OAuth1Provider
Parameters:
token - request token value
Returns:
request token or null if no such token corresponding to a given consumer key is found

newRequestToken

public OAuth1Token newRequestToken(String consumerKey,
                                   String callbackUrl,
                                   Map<String,List<String>> attributes)
Description copied from interface: OAuth1Provider
Creates a new request token for a given consumerKey.

Specified by:
newRequestToken in interface OAuth1Provider
Parameters:
consumerKey - consumer key to create a request token for
callbackUrl - callback url for this request token request
attributes - additional service provider-specific parameters (this can be used to indicate what level of access is requested - i.e. readonly, or r/w, etc.)
Returns:
new request token

newAccessToken

public OAuth1Token newAccessToken(OAuth1Token requestToken,
                                  String verifier)
Description copied from interface: OAuth1Provider
Creates a new access token. This method must validate the passed arguments and return null if any of them is invalid.

Specified by:
newAccessToken in interface OAuth1Provider
Parameters:
requestToken - authorized request token
verifier - verifier passed to the callback after authorization
Returns:
new access token or null if the arguments are invalid (e.g. there is no such request token as in the argument, or the verifier does not match)

addAccessToken

public void addAccessToken(String token,
                           String secret,
                           String consumerKey,
                           String callbackUrl,
                           Principal principal,
                           Set<String> roles,
                           javax.ws.rs.core.MultivaluedMap<String,String> attributes)

getAccessToken

public OAuth1Token getAccessToken(String token)
Description copied from interface: OAuth1Provider
Returns the access token by the consumer key and token value.

Specified by:
getAccessToken in interface OAuth1Provider
Parameters:
token - access token value
Returns:
access token or null if no such found


Copyright © 2007-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.