com.force.sdk.oauth.connector
Class ForceOAuthConnector

java.lang.Object
  extended by com.force.sdk.oauth.connector.ForceOAuthConnector
All Implemented Interfaces:
ForceConnector

public class ForceOAuthConnector
extends Object
implements ForceConnector

This is the main actor in the OAuth handshake. The other pieces of the OAuth integration will ultimately rely on the ForceOAuthConnector to handle the details of the OAuth flow.

In addition to the usual OAuth 2.0 protocol a UserDataRetrievalService is passed in and used to retrieve data about the authenticated user after the handshake completes. This service can either be the standard service or an application specific one. This allows user data to be made available to the application.

This object is used from a per application singleton. DO NOT store per request values with this class.

Author:
Fiaz Hossain, Tim Kral

Nested Class Summary
static class ForceOAuthConnector.OAuthVersion
          OAuth spec version.
 
Field Summary
static String LOGIN_REDIRECT_URL_ATTRIBUTE
          The request attribute that the login redirect url will be read from.
static String REDIRECT_AUTH_URI
          The url that is used for the authentication code callback.
 
Fields inherited from interface com.force.sdk.connector.ForceConnector
PROXY_HOST, PROXY_PORT
 
Constructor Summary
ForceOAuthConnector()
          Default constructor.
ForceOAuthConnector(UserDataRetrievalService userDataRetrievalService)
          Sets OAuth version to 2.0.
 
Method Summary
 void close()
          Close the connection.
 String getAccessCode(javax.servlet.http.HttpServletRequest request)
          Parse the access code out of the servlet request.
 SecurityContext getAccessToken(String accessCode, String redirectUri)
          Get the access token for user.
 String getForceLogoutUrl(javax.servlet.http.HttpServletRequest request, String forceEndpoint, String localLogoutSuccessfulPath)
          Build the logout url.
 String getHostPort(javax.servlet.http.HttpServletRequest request)
          Returns the host and port of the endpoint.
 String getHostPort(String endpoint, String protocol)
          Returns the host and port of the endpoint.
 String getLoginRedirectUrl(javax.servlet.http.HttpServletRequest request)
          get the url that the user will be redirected to for authentication.
 ForceOAuthConnector.OAuthVersion getOAuthVersion()
           
 String getRedirectUri(javax.servlet.http.HttpServletRequest request)
          get the URI to redirect to for user authentication.
 SecurityContext refreshAccessToken(String refreshToken)
          Use the refresh token to obtain a new auth token for the user.
 void setConnectionInfo(ForceOAuthConnectionInfo connectionInfo)
           
 void setConnectionName(String connectionName)
           
 void setOAuthVersion(String oauthVersion)
           
 void setTokenRetrievalService(TokenRetrievalService tokenRetrievalService)
           
 void setUserDataRetrievalService(UserDataRetrievalService userDataRetrievalService)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REDIRECT_AUTH_URI

public static final String REDIRECT_AUTH_URI
The url that is used for the authentication code callback.

See Also:
Constant Field Values

LOGIN_REDIRECT_URL_ATTRIBUTE

public static final String LOGIN_REDIRECT_URL_ATTRIBUTE
The request attribute that the login redirect url will be read from.

See Also:
Constant Field Values
Constructor Detail

ForceOAuthConnector

public ForceOAuthConnector()
Default constructor. Sets OAuth version to 2.0. Uses standard data retrieval service.


ForceOAuthConnector

public ForceOAuthConnector(UserDataRetrievalService userDataRetrievalService)
Sets OAuth version to 2.0. Takes in a UserDataRetrievalService so that an extension can be used.

Parameters:
userDataRetrievalService - UserDataRetrievalService
Method Detail

getAccessToken

public SecurityContext getAccessToken(String accessCode,
                                      String redirectUri)
                               throws IOException
Get the access token for user. This gets called after an access code has been obtained. That access code will now be exchanged for an access token or "auth token". Once an access token is obtained it will immediately be used to retrieve data about the user to populate a SecurityContext.

Parameters:
accessCode - String
redirectUri - String
Returns:
a SecurityContext containing data about the authenticated user
Throws:
IOException - i/o error

refreshAccessToken

public SecurityContext refreshAccessToken(String refreshToken)
                                   throws IOException
Use the refresh token to obtain a new auth token for the user.

Parameters:
refreshToken - String
Returns:
a SecurityContext containing data about the authenticated user
Throws:
IOException - i/o error

close

public void close()
Close the connection.


getAccessCode

public String getAccessCode(javax.servlet.http.HttpServletRequest request)
Parse the access code out of the servlet request.

Parameters:
request - HttpServletRequest
Returns:
OAuth access code

getForceLogoutUrl

public String getForceLogoutUrl(javax.servlet.http.HttpServletRequest request,
                                String forceEndpoint,
                                String localLogoutSuccessfulPath)
Build the logout url.

Parameters:
request - HttpServletRequest
forceEndpoint - String
localLogoutSuccessfulPath - String
Returns:
the logout url

getHostPort

public String getHostPort(javax.servlet.http.HttpServletRequest request)
Returns the host and port of the endpoint.

Parameters:
request - HttpServletRequest
Returns:
the host and port string

getHostPort

public String getHostPort(String endpoint,
                          String protocol)
Returns the host and port of the endpoint.

Parameters:
endpoint - String
protocol - String
Returns:
the host and port string

getLoginRedirectUrl

public String getLoginRedirectUrl(javax.servlet.http.HttpServletRequest request)
                           throws IOException
get the url that the user will be redirected to for authentication. This url should send the user to a login screen so that they can enter their credentials. Once the user sucessfully authenticates a callback will be received with the access code.

Parameters:
request - HttpServletRequest
Returns:
the url to redirect the user to
Throws:
IOException - i/o error

getRedirectUri

public String getRedirectUri(javax.servlet.http.HttpServletRequest request)
get the URI to redirect to for user authentication.

Parameters:
request - HttpServletRequest
Returns:
the redirection URI

setConnectionName

public void setConnectionName(String connectionName)

setConnectionInfo

public void setConnectionInfo(ForceOAuthConnectionInfo connectionInfo)

setOAuthVersion

public void setOAuthVersion(String oauthVersion)

getOAuthVersion

public ForceOAuthConnector.OAuthVersion getOAuthVersion()

setUserDataRetrievalService

public void setUserDataRetrievalService(UserDataRetrievalService userDataRetrievalService)

setTokenRetrievalService

public void setTokenRetrievalService(TokenRetrievalService tokenRetrievalService)


Copyright © 2011. All Rights Reserved.