com.force.sdk.oauth.context.store
Class SecurityContextCookieStore

java.lang.Object
  extended by com.force.sdk.oauth.context.store.SecurityContextCookieStore
All Implemented Interfaces:
SecurityContextStorageService

public class SecurityContextCookieStore
extends Object
implements SecurityContextStorageService

Handles the storage of a SecurityContext via browser cookies.

Author:
John Simone

Field Summary
static String SECURITY_CONTEXT_COOKIE_NAME
          Constant that stores the name of the security context cookie.
 
Constructor Summary
SecurityContextCookieStore()
           
 
Method Summary
static byte[] b64decode(String s)
          Decodes a base-64 encoded string and returns a byte array.
static String b64encode(byte[] b)
          Returns a base-64 encoded byte array.
 void clearSecurityContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Clears the security context cookies from the browser.
 SecretKeySpec getSecureKey()
          Retrieves the secret key if one is used in this security context store.
 boolean isContextStored(javax.servlet.http.HttpServletRequest request)
          Detects whether or not there is a security context stored via this storage method.
 SecurityContext retreiveSecurityContext(javax.servlet.http.HttpServletRequest request)
          Retrieves the security context from a browser cookie.
 void setCookiePath(String cookiePath)
          Sets the path for the cookie to use
 void setKey(String key)
          Sets the key directly
 void setKeyFileName(String fileName)
          Sets the key file name and reads the key from the file.
 void storeSecurityContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, SecurityContext securityContext)
          Saves the security context to a browser cookie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECURITY_CONTEXT_COOKIE_NAME

public static final String SECURITY_CONTEXT_COOKIE_NAME
Constant that stores the name of the security context cookie.

See Also:
Constant Field Values
Constructor Detail

SecurityContextCookieStore

public SecurityContextCookieStore()
Method Detail

storeSecurityContext

public void storeSecurityContext(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 SecurityContext securityContext)
                          throws ContextStoreException
Saves the security context to a browser cookie. Stores the security context. The means of storage will vary by implementation.

Specified by:
storeSecurityContext in interface SecurityContextStorageService
Parameters:
request - HttpServletRequest
response - HttpServletResponse
securityContext - SecurityContext
Throws:
ContextStoreException - ContextStoreException

retreiveSecurityContext

public SecurityContext retreiveSecurityContext(javax.servlet.http.HttpServletRequest request)
                                        throws ContextStoreException
Retrieves the security context from a browser cookie. Retrieves the security context. The means of storage will vary by implementation.

Specified by:
retreiveSecurityContext in interface SecurityContextStorageService
Parameters:
request - HttpServletRequest
Returns:
the stored SecurityContext
Throws:
ContextStoreException - ContextStoreException

getSecureKey

public SecretKeySpec getSecureKey()
                           throws ForceEncryptionException
Description copied from interface: SecurityContextStorageService
Retrieves the secret key if one is used in this security context store.

Specified by:
getSecureKey in interface SecurityContextStorageService
Returns:
SecretKeySpec
Throws:
ForceEncryptionException - ForceEncryptionException

setKeyFileName

public void setKeyFileName(String fileName)
                    throws ForceEncryptionException
Sets the key file name and reads the key from the file.

Parameters:
fileName - String
Throws:
ForceEncryptionException - ForceEncryptionException

setKey

public void setKey(String key)
            throws ForceEncryptionException
Sets the key directly

Parameters:
fileName - String
Throws:
ForceEncryptionException - ForceEncryptionException

b64encode

public static String b64encode(byte[] b)
Returns a base-64 encoded byte array.

Parameters:
b - - byte array
Returns:
b64 String representation

b64decode

public static byte[] b64decode(String s)
Decodes a base-64 encoded string and returns a byte array.

Parameters:
s - - the encoded string
Returns:
the byte array

clearSecurityContext

public void clearSecurityContext(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
Clears the security context cookies from the browser. Clears the security context from storage. This won't be relevant for all storage types.

Specified by:
clearSecurityContext in interface SecurityContextStorageService
Parameters:
request - HttpServletRequest
response - HttpServletResponse

isContextStored

public boolean isContextStored(javax.servlet.http.HttpServletRequest request)
Detects whether or not there is a security context stored via this storage method.

Specified by:
isContextStored in interface SecurityContextStorageService
Parameters:
request - HttpServletRequest
Returns:
whether or not the security context is stored using this storage method

setCookiePath

public void setCookiePath(String cookiePath)
Sets the path for the cookie to use

Parameters:
cookiePath -


Copyright © 2012. All Rights Reserved.