com.dyuproject.oauth
Class Consumer

java.lang.Object
  extended by com.dyuproject.oauth.Consumer

public final class Consumer
extends Object

OAuth Consumer helper class which manages the oauth consumer lifecycle

Author:
David Yu
Date created:
May 29, 2009

Field Summary
static String DEFAULT_RESOURCE_PATH
          The default resource path.
 
Constructor Summary
Consumer(ConsumerContext context, TokenManager manager)
           
 
Method Summary
 void addEndpoint(Endpoint ep)
          Adds an endpoint ep which would also be added to the wrapped ConsumerContext.
 HttpConnector.Response fetchToken(Endpoint ep, Token token)
          Fetches the token using the given endpoint and token - and returns the http response HttpConnector.Response.
 HttpConnector.Response fetchToken(Endpoint ep, TokenExchange exchange, Token token)
          Fetches the token using the given endpoint, exchange and token - and returns the http response HttpConnector.Response.
 HttpConnector.Response fetchToken(Endpoint ep, UrlEncodedParameterMap params, TokenExchange exchange, Token token)
          Fetches the token using the given endpoint, params, exchange and token - and returns the http response HttpConnector.Response.
 ConsumerContext getConsumerContext()
          Gets the consumer context.
 Endpoint getEndpoint(String domain)
          Gets the endpoint from the given domain.
static Consumer getInstance()
          Gets the instance configured from the default resource path DEFAULT_RESOURCE_PATH.
 Token getToken(String consumerKey, HttpServletRequest request)
          Gets a token from the request and delegates to the wrapped TokenManager if not found.
 TokenManager getTokenManager()
          Gets the token manager.
 boolean invalidate(String consumerKey, HttpServletRequest request, HttpServletResponse response)
          Invalidates the token based from its key; Delegates to the TokenManager.
 boolean invalidate(Token token, HttpServletRequest request, HttpServletResponse response)
          Invalidates the token.; Delegates to the TokenManager.
static Consumer newInstance(InputStream in)
          Creates a new instance configured from the InputStream in.
static Consumer newInstance(Properties props)
          Creates a new instance configured form the Properties props.
static Consumer newInstance(String resourceLoc)
          Creates a new instance configured from the resource path resourceLoc.
static Consumer newInstance(URL resource)
          Creates a new instance configured from the URL resource.
 boolean saveToken(Token token, HttpServletRequest request, HttpServletResponse response)
          Saves the token; Delegates to the TokenManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RESOURCE_PATH

public static final String DEFAULT_RESOURCE_PATH
The default resource path. ("oauth_consumer.properties")

See Also:
Constant Field Values
Constructor Detail

Consumer

public Consumer(ConsumerContext context,
                TokenManager manager)
Method Detail

getInstance

public static Consumer getInstance()
Gets the instance configured from the default resource path DEFAULT_RESOURCE_PATH.


newInstance

public static Consumer newInstance(String resourceLoc)
Creates a new instance configured from the resource path resourceLoc.


newInstance

public static Consumer newInstance(URL resource)
                            throws IOException
Creates a new instance configured from the URL resource.

Throws:
IOException

newInstance

public static Consumer newInstance(InputStream in)
                            throws IOException
Creates a new instance configured from the InputStream in.

Throws:
IOException

newInstance

public static Consumer newInstance(Properties props)
                            throws IOException
Creates a new instance configured form the Properties props.

Throws:
IOException

getConsumerContext

public ConsumerContext getConsumerContext()
Gets the consumer context.


getTokenManager

public TokenManager getTokenManager()
Gets the token manager.


getEndpoint

public Endpoint getEndpoint(String domain)
Gets the endpoint from the given domain.


addEndpoint

public void addEndpoint(Endpoint ep)
Adds an endpoint ep which would also be added to the wrapped ConsumerContext.


getToken

public Token getToken(String consumerKey,
                      HttpServletRequest request)
               throws IOException
Gets a token from the request and delegates to the wrapped TokenManager if not found. The new token will be set in the request attribute.

Throws:
IOException

saveToken

public boolean saveToken(Token token,
                         HttpServletRequest request,
                         HttpServletResponse response)
                  throws IOException
Saves the token; Delegates to the TokenManager.

Throws:
IOException

invalidate

public boolean invalidate(String consumerKey,
                          HttpServletRequest request,
                          HttpServletResponse response)
                   throws IOException
Invalidates the token based from its key; Delegates to the TokenManager.

Throws:
IOException

invalidate

public boolean invalidate(Token token,
                          HttpServletRequest request,
                          HttpServletResponse response)
                   throws IOException
Invalidates the token.; Delegates to the TokenManager.

Throws:
IOException

fetchToken

public HttpConnector.Response fetchToken(Endpoint ep,
                                         Token token)
                                  throws IOException
Fetches the token using the given endpoint and token - and returns the http response HttpConnector.Response.

Throws:
IOException

fetchToken

public HttpConnector.Response fetchToken(Endpoint ep,
                                         TokenExchange exchange,
                                         Token token)
                                  throws IOException
Fetches the token using the given endpoint, exchange and token - and returns the http response HttpConnector.Response.

Throws:
IOException

fetchToken

public HttpConnector.Response fetchToken(Endpoint ep,
                                         UrlEncodedParameterMap params,
                                         TokenExchange exchange,
                                         Token token)
                                  throws IOException
Fetches the token using the given endpoint, params, exchange and token - and returns the http response HttpConnector.Response.

Throws:
IOException


Copyright © 2008-2013. All Rights Reserved.