com.google.api.client.extensions.servlet.auth
Class AbstractTwoLeggedFlowServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.google.api.client.extensions.servlet.auth.AbstractTwoLeggedFlowServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
AbstractAppEngineTwoLeggedFlowServlet

public abstract class AbstractTwoLeggedFlowServlet
extends javax.servlet.http.HttpServlet

This specialization of HttpServlet allows accessing OAuth resources using a credential that can be created without user intervention. Subclasses should call getCredential in their handlers when they want access to protected resources.

Since:
1.5
Author:
moshenko@google.com (Jacob Moshenko)
See Also:
Serialized Form

Constructor Summary
AbstractTwoLeggedFlowServlet()
          Create an instance of the servlet.
 
Method Summary
protected  Credential getCredential(javax.servlet.http.HttpServletRequest req)
          Fetch a credential associated with this request.
protected  HttpTransport getHttpTransport()
          Return the HttpTransport instance for this servlet.
protected  JsonFactory getJsonFactory()
          Return the JsonFactory instance for this servlet.
protected abstract  javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
          Obtain a PersistenceManagerFactory for working with the datastore.
protected abstract  String getUserId()
           
protected abstract  TwoLeggedFlow newFlow(String userId)
          Create a two legged flow that can be used to create credentials for accessing protected resources using OAuth.
protected abstract  HttpTransport newHttpTransportInstance()
          Create a new HttpTransport instance.
protected abstract  JsonFactory newJsonFactoryInstance()
          Create a new JsonFactory instance.
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTwoLeggedFlowServlet

public AbstractTwoLeggedFlowServlet()
Create an instance of the servlet.

Method Detail

service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws javax.servlet.ServletException,
                       IOException
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

getCredential

protected Credential getCredential(javax.servlet.http.HttpServletRequest req)
                            throws IOException
Fetch a credential associated with this request.

Parameters:
req - Request object to use as context for fetching the credential.
Returns:
Credential object for this request and user.
Throws:
IOException

newFlow

protected abstract TwoLeggedFlow newFlow(String userId)
Create a two legged flow that can be used to create credentials for accessing protected resources using OAuth.

Parameters:
userId - Identifier used to associate a flow or credential object with a specific user.
Returns:
Flow object that the servlet can use to create a credential object.

getJsonFactory

protected final JsonFactory getJsonFactory()
Return the JsonFactory instance for this servlet.


getHttpTransport

protected final HttpTransport getHttpTransport()
Return the HttpTransport instance for this servlet.


getPersistenceManagerFactory

protected abstract javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
Obtain a PersistenceManagerFactory for working with the datastore.

Returns:
PersistenceManagerFactory instance.

newHttpTransportInstance

protected abstract HttpTransport newHttpTransportInstance()
Create a new HttpTransport instance. Implementations can create any type of applicable transport and should be as simple as:
  new NetHttpTransport();
 

Returns:
HttpTransport instance for your particular environment

newJsonFactoryInstance

protected abstract JsonFactory newJsonFactoryInstance()
Create a new JsonFactory instance. Implementations can create any type of applicable json factory and should be as simple as:
  new JacksonFactory();
 

Returns:
JsonFactory instance for your particular environment

getUserId

protected abstract String getUserId()
Returns:
Get a string representation of a userId that can be used to associate credentials and flows with a specific user.


Copyright © 2011 Google. All Rights Reserved.