Package com.jalios.jcms.authentication
Class AuthenticationHandler
java.lang.Object
com.jalios.jcms.authentication.AuthenticationHandler
- All Implemented Interfaces:
PluginComponent,Comparable<AuthenticationHandler>
- Direct Known Subclasses:
AuthKeyAuthenticationHandler,ClientCertificateAuthenticationHandler,CookieAuthenticationHandler,DelegationAuthenticationHandler,HttpBasicAuthenticationHandler,HttpDigestAuthenticationHandler,JWTAuthenticationHandler,LoggingAuthenticationHandler,SessionAuthenticationHandler,SilentParamsAuthenticationHandler,SimpleAuthenticationHandler
public abstract class AuthenticationHandler
extends Object
implements Comparable<AuthenticationHandler>, PluginComponent
An AuthenticationHandler is an object that perform user authentification.
JCMS manages a list of AuthenticationHandler sorted using the natural order provided by this abstract class using the order parameter of the constructor.
Use this order parameter to modify the position of your handler in the authentication chain.
Override one or both of the following methods to provide your own authentication mecanism : When implementing any of those method, make sure you either call the super method or either invoke the chain yourself, NOT BOTH!
The
JCMS manages a list of AuthenticationHandler sorted using the natural order provided by this abstract class using the order parameter of the constructor.
Use this order parameter to modify the position of your handler in the authentication chain.
Override one or both of the following methods to provide your own authentication mecanism : When implementing any of those method, make sure you either call the super method or either invoke the chain yourself, NOT BOTH!
The
loadProperties() method can be overridden to load/reload properties as needed.- Since:
- jcms-5.7.0
- Author:
- Olivier Jaquemet
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Channelstatic final StringUse this constant withAuthenticationContext.setWarningMsg(String)to provide a generic authentication failure message. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new AuthenticationHandler.
The default order of this new handler is 0.AuthenticationHandler(int order) Constructs a AuthenticationHandler with the specified order. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanLogout(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Locale userLocale, Member loggedMember, boolean isAuthorized) This methods is invoked on allAuthenticationHandler, BEFORE a logout action, to check security context authorize the logout chain to be invoked.final intcompareTo(AuthenticationHandler authHdlr) Compare this object with the specified AuthenticationHandler for order.final booleanIndicates wheter some other object is "equal to" this one.intgetOrder()Retrieve the order used by this AuthenticationHandler.booleanInitialize the component with the given plugin configurationvoidThis 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.voidsetOrder(int order) Modify the order used by this AuthenticationHandler.
-
Field Details
-
GENERIC_BAD_AUTHENTICATION_MSG
Use this constant withAuthenticationContext.setWarningMsg(String)to provide a generic authentication failure message.- See Also:
-
channel
-
-
Constructor Details
-
AuthenticationHandler
public AuthenticationHandler()Creates a new AuthenticationHandler.
The default order of this new handler is 0.- Since:
- jcms-5.7.0
-
AuthenticationHandler
public AuthenticationHandler(int order) Constructs a AuthenticationHandler with the specified order.- Parameters:
order- an integer used by the natural comparator of this AuthenticationHandler to sort all AuthenticationHandler managed by theAuthenticationManager.- Since:
- jcms-5.7.0
-
-
Method Details
-
loadProperties
public void loadProperties()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 AuthenticationManager -
init
Description copied from interface:PluginComponentInitialize the component with the given plugin configuration- Specified by:
initin interfacePluginComponent- Parameters:
plugin- the calling plugin- Returns:
- true if the component has been correctly initialized.
-
login
Authenticate 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.- Parameters:
ctxt- theAuthenticationContextused for this login- Throws:
IOException- Since:
- jcms-5.7.0
- Examine informations required to perform the authentication through
the
-
canLogout
public boolean canLogout(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Locale userLocale, Member loggedMember, boolean isAuthorized) This methods is invoked on allAuthenticationHandler, BEFORE a logout action, to check security context authorize the logout chain to be invoked.Core implementation is to authorize logout only when a valid CSRF token was received (since JCMS-8092).
Each AuthenticationHandler SSO may authorize logout under additionnal circumstances by implementing this method.Default implementation is to return the samed isAuthorized value received in parameter.
- Parameters:
request- the current HttpServletRequest being processedresponse- the HttpServletResponse bound to current requestuserLocale- the current Locale guessed from browser preference or sessionloggedMember- the member currently logged inisAuthorized- true if logout has been authorized by default JCMS behavior or by any other AuthenticationHandler, false otherwise- Returns:
- the authorization state decided by your handler (default implementation is to return the isAuthorized parameter value)
- Since:
- jcms-10.0.5 / JCMS-8093
-
logout
This 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.- Parameters:
ctxt- theAuthenticationContextused for this login- Throws:
IOException- Since:
- jcms-5.7.0
-
compareTo
Compare this object with the specified AuthenticationHandler for order.- Specified by:
compareToin interfaceComparable<AuthenticationHandler>- Parameters:
authHdlr- the AuthenticationHandler to be compared.- Since:
- jcms-5.7.0
- See Also:
-
equals
Indicates wheter some other object is "equal to" this one. The comparison is performed with compareTo() method. -
getOrder
public int getOrder()Retrieve the order used by this AuthenticationHandler. This value is used by the natural comparator of AuthenticationHandler to provides the ordering in any AuthenticationHandler collection, specially the collection of handler managed by AuthenticationManager.- Returns:
- an int indicating the order relative to other handlers.
-
setOrder
public void setOrder(int order) Modify the order used by this AuthenticationHandler. This value is used by the natural comparator of AuthenticationHandler to provides the ordering in any AuthenticationHandler collection, specially the collection of handler managed by AuthenticationManager.- Parameters:
order- the new order to use for this AuthenticationHandler
-