public abstract class DefaultAuthenticator extends AbstractAuthenticator
It also provides for cookie logins and creates cookies if needed.
Includes code from Jive 1.2.4 (released under the Apache license)
| Modifier and Type | Field and Description |
|---|---|
static String |
LOGGED_IN_KEY
The key used to store the user object in the session
|
static String |
LOGGED_OUT_KEY
The key used to indicate that the user has logged out and session regarding of it containing a cookie is not
logged in.
|
| Constructor and Description |
|---|
DefaultAuthenticator() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
authenticate(Principal user,
String password)
Authenticates the given user and password.
|
protected boolean |
authoriseUserAndEstablishSession(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse,
Principal principal)
This is called to authorise the user with the application.
|
String |
getAuthType() |
protected ElevatedSecurityGuard |
getElevatedSecurityGuard() |
protected List<LogoutInterceptor> |
getLogoutInterceptors() |
protected RememberMeService |
getRememberMeService() |
protected RoleMapper |
getRoleMapper()
override this method if you need to retrieve the role mapper from elsewhere than the singleton-factory (injected
dependency for instance)
|
Principal |
getUser(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Returns the currently logged in user, trying in order:
|
protected abstract Principal |
getUser(String username)
Retrieve a Principal for the given username.
|
protected Principal |
getUserFromBasicAuthentication(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Checks the Authorization header to see whether basic auth token is provided.
|
protected Principal |
getUserFromCookie(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Extracts the username and password from the cookie and calls login to authenticate, and if successful store the
token in the session.
|
protected Principal |
getUserFromSession(javax.servlet.http.HttpServletRequest httpServletRequest)
Tries to get a logged in user from the session.
|
void |
init(Map<String,String> params,
SecurityConfig config)
Initialise the configuration object with the given "init-params".
|
protected boolean |
isAuthorised(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
This method is called to estblish if the principal is authorised to use the appliction url in play
|
protected boolean |
isPrincipalAlreadyInSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
This is called to determine if the Principal is already in the HttpSession in a Seraph ready manner.
|
boolean |
login(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse,
String userName,
String password,
boolean setRememberMeCookie)
Tries to authenticate a user.
|
boolean |
logout(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Called to remove the current principal from the HttpSession and will also to remove any remember me cookies that
may be in effect.
|
protected void |
putPrincipalInSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
This can be called to put the principal into the HttpSession in a Seraph ready manner
|
protected Principal |
refreshPrincipalObtainedFromSession(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
This is called to refresh the Principal object that has been retreived from the HTTP session.
|
protected void |
removePrincipalFromSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest)
This can be called to remove the principal into the HttpSession in a Seraph ready manner
|
destroy, getConfig, getRemoteUser, getUser, loginpublic static final String LOGGED_IN_KEY
public static final String LOGGED_OUT_KEY
public void init(Map<String,String> params, SecurityConfig config)
Initableinit in interface Initableinit in class AbstractAuthenticatorparams - The map of "init-params" extracted from the Seraph config file. This is guaranteed not null.config - The Seraph SecurityConfig class that is initialising the config objects. This object will only be partially initialised at this time.public boolean login(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse,
String userName,
String password,
boolean setRememberMeCookie)
throws AuthenticatorException
login in interface Authenticatorlogin in class AbstractAuthenticatorhttpServletRequest - the request in playhttpServletResponse - the response in playuserName - the user name to check against the passwordpassword - the password to authenticate the user withsetRememberMeCookie - whether to set a remember me cookie on sucessful loginAuthenticatorException - actualy this class does not throw any exceptions however the interface says we
must and other classes may override uspublic boolean logout(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
throws AuthenticatorException
logout in interface Authenticatorlogout in class AbstractAuthenticatorhttpServletRequest - the request in playhttpServletResponse - the response in playAuthenticatorException - this implementation never doesprotected boolean authoriseUserAndEstablishSession(javax.servlet.http.HttpServletRequest httpServletRequest,
javax.servlet.http.HttpServletResponse httpServletResponse,
Principal principal)
RoleMapper is invoked to see if the user
is authorised to user this request via a call to isAuthorised(javax.servlet.http.HttpServletRequest,
java.security.Principal)
If successful, then the HttpSession will contain the attribute marking that the user is logged in
httpServletRequest - the request in playhttpServletResponse - the response in playprincipal - the principal to authoriseprotected boolean isAuthorised(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
httpServletRequest - the request in playprincipal - the principal to checkprotected void putPrincipalInSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
httpServletRequest - the request in playprincipal - the principal to put in the sessionprotected void removePrincipalFromSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest)
httpServletRequest - the request in playprotected boolean isPrincipalAlreadyInSessionContext(javax.servlet.http.HttpServletRequest httpServletRequest,
Principal principal)
httpServletRequest - the request in playprincipal - the principal to put in the sessionprotected RoleMapper getRoleMapper()
RoleMapper to useprotected abstract Principal getUser(String username)
username - the name of the user to findprotected abstract boolean authenticate(Principal user, String password) throws AuthenticatorException
user - the user to authenticate. This object only stores the username of the user.password - the password of the userAuthenticatorException - if an error occurs that stops the user from being authenticated (eg remote communication failure).public Principal getUser(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
Warning: only in the case of cookie and basic auth will the user be authenticated.
getUser in interface AuthenticatorgetUser in class AbstractAuthenticatorhttpServletRequest - the request in playhttpServletResponse - a response object that may be modified if basic auth is enabledprotected Principal refreshPrincipalObtainedFromSession(javax.servlet.http.HttpServletRequest httpServletRequest, Principal principal)
By default this will called getUser(String) again to get a fresh user.
httpServletRequest - the HTTP request in playprincipal - the Principal in playprotected Principal getUserFromSession(javax.servlet.http.HttpServletRequest httpServletRequest)
Tries to get a logged in user from the session.
httpServletRequest - the current HttpServletRequestnull if there is no logged in user in the session, or the
LOGGED_OUT_KEY is set because the user has logged out.protected Principal getUserFromCookie(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
httpServletRequest - the HTTP request in playhttpServletResponse - the HTTP respone in playprotected Principal getUserFromBasicAuthentication(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
httpServletRequest - the HTTP request in playhttpServletResponse - a response object that will be modified if no token foundPrincipal or null if one cant be foundpublic String getAuthType()
protected List<LogoutInterceptor> getLogoutInterceptors()
protected ElevatedSecurityGuard getElevatedSecurityGuard()
protected RememberMeService getRememberMeService()
Copyright © 2018 Atlassian. All rights reserved.