Class CookieAuthenticationHandler
- java.lang.Object
- 
- com.jalios.jcms.authentication.AuthenticationHandler
- 
- com.jalios.jcms.authentication.handlers.CookieAuthenticationHandler
 
 
- 
- All Implemented Interfaces:
- PluginComponent,- java.lang.Comparable<AuthenticationHandler>
 
 public final class CookieAuthenticationHandler extends AuthenticationHandler Save authentification made by other handlers into cookie and use it later on to re-authenticate.
 
 You can disable this handler by modifiying property"auth-mgr.cookie-enabled". Cookie can be disabled for admin by modifiying property"auth-mgr.allow-admin-cookie".- Since:
- jcms-5.7.0
- Version:
- $Revision: 135756 $
- Author:
- Olivier Jaquemet
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classCookieAuthenticationHandler.CookieAuthStatePossible Cookie authentication state after handler invocation.
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringAUTHENTICATION_COOKIE_NAMEName of cookie used for authentication.static java.lang.StringCOOKIE_EXPECTEDParameter named used by CookieAuthenticationHandler to check that cookie has correctly been received by browser and has been sent back.static intORDER_COOKIE_HANDLEROrder used by the CookieAuthenticationHandlerstatic java.lang.StringREVISION- 
Fields inherited from class com.jalios.jcms.authentication.AuthenticationHandlerchannel, GENERIC_BAD_AUTHENTICATION_MSG
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static javax.servlet.http.CookieaddAuthenticationCookie(Member mbr, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean isPersistent)Add a new AuthenticationCookie for the specified member.static MembercheckAuthenticationFromCookie(javax.servlet.http.Cookie[] cookies)Returns the member corresponding to the member id which is contains in memberId cookie.static booleancheckCookieDigest(java.lang.String digest, java.lang.String timeStr, Member member)Check if the specified time and password matches the encoded digest.static voiddeleteAuthenticationCookie(javax.servlet.http.Cookie[] cookies)Delete all AuthenticationCookie instance from the DB matching the specified coookiesstatic javax.servlet.http.CookiegetAuthenticationCookie(Member member, java.lang.String domain, java.lang.String path, boolean isPersistent)Returns a cookie for a given memberstatic java.lang.StringgetCookieDigest(java.lang.String timeStr, Member member)Returns the cookie digest for the specified time and Member.static java.lang.StringgetCookieDigest(java.lang.String timeStr, java.lang.String password)Deprecated.static javax.servlet.http.CookiegetEmptyAuthenticationCookie(java.lang.String domain, java.lang.String path)Returns an empty authentication cookie (used for logout)static CookieAuthenticationHandlergetInstance()voidloadProperties()This method will be called by the AuthenticationManager each time the Channel properties are loaded/reloaded.
 You can use it to reload properties that might have been changed.
 This method is called during initialization of the AuthenticationManagervoidlogin(AuthenticationContext ctxt)Authenticate a member.voidlogout(AuthenticationContext ctxt)This methods is called when users logout from JCMS.
 
- 
- 
- 
Field Detail- 
REVISIONpublic static final java.lang.String REVISION - See Also:
- Constant Field Values
 
 - 
ORDER_COOKIE_HANDLERpublic static final int ORDER_COOKIE_HANDLER Order used by the CookieAuthenticationHandler- See Also:
- Constant Field Values
 
 - 
COOKIE_EXPECTEDpublic static final java.lang.String COOKIE_EXPECTED Parameter named used by CookieAuthenticationHandler to check that cookie has correctly been received by browser and has been sent back.- See Also:
- Constant Field Values
 
 - 
AUTHENTICATION_COOKIE_NAMEpublic static final java.lang.String AUTHENTICATION_COOKIE_NAME Name of cookie used for authentication.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getInstancepublic static final CookieAuthenticationHandler getInstance() 
 - 
loadPropertiespublic void loadProperties() Description copied from class:AuthenticationHandlerThis method will be called by the AuthenticationManager each time the Channel properties are loaded/reloaded.
 You can use it to reload properties that might have been changed.
 This method is called during initialization of the AuthenticationManager- Overrides:
- loadPropertiesin class- AuthenticationHandler
 
 - 
loginpublic void login(AuthenticationContext ctxt) throws java.io.IOException Description copied from class:AuthenticationHandlerAuthenticate a member.
 This method is invoked by the authentication chain on each request.
 A typical implementation of this method would follow the following pattern :- Examine informations required to perform the authentication through
       the AuthenticationContextobject (request, response, login.. etc)
- Perform your authentication before chain invokation and set the logged Member
       AuthenticationContext.setLoggedMember(com.jalios.jcms.Member)
- a) Either invoke the next entity in the chain using AuthenticationContext.doChain(),
- b) or else skip the chain invokation and block other authentication handler of the chain (do this with caution...)
- Perform redirection, set information/warning/error message or any
       other process, after chain invokation, using AuthenticationContext.
 
 Default implementation is to invoke the next handler in the chain.- Overrides:
- loginin class- AuthenticationHandler
- Parameters:
- ctxt- the- AuthenticationContextused for this login
- Throws:
- java.io.IOException
 
- Examine informations required to perform the authentication through
       the 
 - 
logoutpublic void logout(AuthenticationContext ctxt) throws java.io.IOException Description copied from class:AuthenticationHandlerThis methods is called when users logout from JCMS.
 It may not be called if user simply close its browser. Don't rely on this for critical operation
 
 Default implementation is to invoke the next handler in the chain.- Overrides:
- logoutin class- AuthenticationHandler
- Parameters:
- ctxt- the- AuthenticationContextused for this login
- Throws:
- java.io.IOException
 
 - 
getCookieDigestpublic static final java.lang.String getCookieDigest(java.lang.String timeStr, java.lang.String password)Deprecated.Returns the cookie digest (MD5) composed of concatenation of the time (in millis) and the password of the member- Parameters:
- timeStr- a time as a string (e.g.- String.valueOf(System.currentTimeMillis()))
- password- the Member's password in its crypted version (e.g.- member.getPassword())
- Returns:
- an authentication digest
 
 - 
getCookieDigestpublic static final java.lang.String getCookieDigest(java.lang.String timeStr, Member member)Returns the cookie digest for the specified time and Member.- Parameters:
- timeStr- the time at which this cookie was emited, as a string (e.g.- String.valueOf(System.currentTimeMillis()))
- member- the Member for which the digest is computed
- Returns:
- an authentication digest
- Since:
- jcms-7.1
 
 - 
checkCookieDigestpublic static final boolean checkCookieDigest(java.lang.String digest, java.lang.String timeStr, Member member)Check if the specified time and password matches the encoded digest.- Parameters:
- digest- the digest to check (as returned by- getCookieDigest(String, String)
- timeStr- a time as a string (e.g.- String.valueOf(System.currentTimeMillis()))
- member- the Member against which the digest is verified
- Returns:
- true if the specified digest matches the timeStr and Member
- Since:
- jcms-7.1
 
 - 
checkAuthenticationFromCookiepublic static final Member checkAuthenticationFromCookie(javax.servlet.http.Cookie[] cookies) Returns the member corresponding to the member id which is contains in memberId cookie.- Parameters:
- cookies- an array of cookies (request.getCookies())
- Returns:
- the member or null if not found
 
 - 
addAuthenticationCookiepublic static final javax.servlet.http.Cookie addAuthenticationCookie(Member mbr, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean isPersistent) Add a new AuthenticationCookie for the specified member.- Parameters:
- mbr- the Member for which authentication Cookie is created and added, required, must not be null
- request- the current HTTP request leading to creation of cookie, required, must not be null
- response- the response in which cookie must be sent, required, must not be null
- isPersistent- set to false to create/add a cookie valid for the browser session, true to create/add a cookie valid until expiration is reached
- Returns:
- a new Cookie instance of null if cookie was not created
- Since:
- JCMS-5813
 
 - 
getAuthenticationCookiepublic static final javax.servlet.http.Cookie getAuthenticationCookie(Member member, java.lang.String domain, java.lang.String path, boolean isPersistent) throws java.net.UnknownHostException Returns a cookie for a given member- Parameters:
- member- the member to use to generate the cookie.
- domain- an optional String containing the domain name within which the cookie is visible; form is according to RFC 2109
- path- the cookie path
- isPersistent- if true the cookie will persist on the user disk beyond the browser shutdown ; otherwise it will persist until browser shutdown.
- Returns:
- a new Cookie instance
- Throws:
- java.net.UnknownHostException- if the specified domain could not be resolved
 
 - 
getEmptyAuthenticationCookiepublic static final javax.servlet.http.Cookie getEmptyAuthenticationCookie(java.lang.String domain, java.lang.String path) throws java.net.UnknownHostExceptionReturns an empty authentication cookie (used for logout)- Parameters:
- domain- the cookie domain (can be null)
- path- the cookie path
- Returns:
- a new Cookie instance
- Throws:
- java.net.UnknownHostException- if the specified domain could not be resolved
 
 - 
deleteAuthenticationCookiepublic static final void deleteAuthenticationCookie(javax.servlet.http.Cookie[] cookies) Delete all AuthenticationCookie instance from the DB matching the specified coookies- Parameters:
- cookies- the cookies received from the browser
 
 
- 
 
-