|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.seraph.auth.AbstractAuthenticator com.atlassian.seraph.auth.DefaultAuthenticator
public abstract class DefaultAuthenticator
This authenticator stores the currently logged in user in the session as a Principal.
It also provides for cookie logins and creates cookies if needed. Includes code from Jive 1.2.4 (released under the Apache license)
Field Summary | |
---|---|
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. |
Fields inherited from interface com.atlassian.seraph.auth.Authenticator |
---|
DEFAULT_AUTHENTICATOR |
Constructor Summary | |
---|---|
DefaultAuthenticator()
|
Method Summary | |
---|---|
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: Session, only if one exists Cookie, only if no session exists Basic authentication, if the above fail, and authType=basic Warning: only in the case of cookie and basic auth will the user be authenticated. |
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 |
isUserInRole(javax.servlet.http.HttpServletRequest request,
String role)
Deprecated. Use RoleMapper directly |
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 |
Methods inherited from class com.atlassian.seraph.auth.AbstractAuthenticator |
---|
destroy, getConfig, getRemoteUser, getUser, login |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String LOGGED_IN_KEY
public static final String LOGGED_OUT_KEY
Constructor Detail |
---|
public DefaultAuthenticator()
Method Detail |
---|
public void init(Map<String,String> params, SecurityConfig config)
Initable
init
in interface Initable
init
in class AbstractAuthenticator
params
- 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.@Deprecated public boolean isUserInRole(javax.servlet.http.HttpServletRequest request, String role)
RoleMapper
directly
isUserInRole
in interface Authenticator
isUserInRole
in class AbstractAuthenticator
public boolean login(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, String userName, String password, boolean setRememberMeCookie) throws AuthenticatorException
login
in interface Authenticator
login
in class AbstractAuthenticator
httpServletRequest
- 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 login
AuthenticatorException
- 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 Authenticator
logout
in class AbstractAuthenticator
httpServletRequest
- the request in playhttpServletResponse
- the response in play
AuthenticatorException
- 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 authorise
protected boolean isAuthorised(javax.servlet.http.HttpServletRequest httpServletRequest, Principal principal)
httpServletRequest
- the request in playprincipal
- the principal to check
protected 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 session
protected RoleMapper getRoleMapper()
RoleMapper
to useprotected abstract Principal getUser(String username)
username
- the name of the user to find
protected 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 user
AuthenticatorException
- 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)
getUser
in interface Authenticator
getUser
in class AbstractAuthenticator
httpServletRequest
- the request in playhttpServletResponse
- a response object that may be modified if basic auth is enabled
protected Principal refreshPrincipalObtainedFromSession(javax.servlet.http.HttpServletRequest httpServletRequest, Principal principal)
getUser(String)
again to get a fresh user.
httpServletRequest
- the HTTP request in playprincipal
- the Principal in play
protected Principal getUserFromSession(javax.servlet.http.HttpServletRequest httpServletRequest)
Tries to get a logged in user from the session.
httpServletRequest
- the current HttpServletRequest
null
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 play
protected 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 found
Principal
or null if one cant be foundpublic String getAuthType()
protected List<LogoutInterceptor> getLogoutInterceptors()
protected ElevatedSecurityGuard getElevatedSecurityGuard()
protected RememberMeService getRememberMeService()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |