Class DefaultLoginModule
- java.lang.Object
-
- org.apache.jackrabbit.core.security.authentication.AbstractLoginModule
-
- org.apache.jackrabbit.core.security.authentication.DefaultLoginModule
-
- All Implemented Interfaces:
LoginModule
public class DefaultLoginModule extends AbstractLoginModule
TheDefaultLoginModule
authenticates Credentials related to aUser
of the Repository
In any other case it is marked to be ignored.This Module can deal with the following credentials
SimpleCredentials
-> handled bySimpleCredentialsAuthentication
.TokenCredentials
-> handled byTokenBasedAuthentication
.
Correspondingly impersonation is delegated to the
User
'sImpersonation
object.- See Also:
AbstractLoginModule
-
-
Field Summary
Fields Modifier and Type Field Description protected User
user
The user object retrieved during the authentication process.-
Fields inherited from class org.apache.jackrabbit.core.security.authentication.AbstractLoginModule
adminId, anonymousId, callbackHandler, credentials, principal, principalProvider, sharedState, subject
-
-
Constructor Summary
Constructors Constructor Description DefaultLoginModule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
commit()
Method to commit the authentication process (phase 2).protected void
doInit(CallbackHandler callbackHandler, Session session, Map options)
Retrieves the user manager from the specified session.protected Authentication
getAuthentication(Principal principal, Credentials creds)
Retrieve theAuthentication
.protected Principal
getPrincipal(Credentials credentials)
Resolves the userID from the given credentials and obtains the principal from the User object associated with the given userID.long
getTokenExpiration()
protected String
getUserID(Credentials credentials)
Method supports tries to acquire a UserID in the following order: If passed credentials areGuestCredentials
the anonymous user id is returned. Try to access it from theCredentials
viaSimpleCredentials.getUserID()
Ask CallbackHandler for User-ID with use ofNameCallback
. Test if the 'sharedState' contains a login name. Fallback: return the anonymous UserID.protected boolean
impersonate(Principal principal, Credentials credentials)
Handles the impersonation of given Credentials.boolean
isDisableTokenAuth()
Return a flag indicating if token based authentication is disabled.void
setDisableTokenAuth(boolean disableTokenAuth)
Set a flag indicating if token based authentication is disabled.void
setTokenExpiration(long tokenExpiration)
protected boolean
supportsCredentials(Credentials creds)
Return a flag indicating whether the credentials are supported by this login module.-
Methods inherited from class org.apache.jackrabbit.core.security.authentication.AbstractLoginModule
abort, authenticate, getAdminId, getAnonymousId, getCredentials, getImpersonatorSubject, getPreAuthAttributeName, getPrincipalProvider, getPrincipals, initialize, isAnonymous, isImpersonation, isInitialized, isPreAuthenticated, login, logout, setAdminId, setAnonymousId, setPrincipalProvider
-
-
-
-
Field Detail
-
user
protected User user
The user object retrieved during the authentication process.
-
-
Method Detail
-
commit
public boolean commit() throws LoginException
Description copied from class:AbstractLoginModule
Method to commit the authentication process (phase 2).This method is called if the LoginContext's overall authentication succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules succeeded).
If this LoginModule's own authentication attempt succeeded (checked by retrieving the private state saved by the
login
method), then this method associates relevant Principals and Credentials with theSubject
located in theLoginModule
. If this LoginModule's own authentication attempted failed, then this method removes/destroys any state that was originally saved.The login is considered as succeeded if there is a principal set.
The implementation stores the principal associated to the UserID and all the Groups it is member of with the Subject and in addition adds an instance of (#link SimpleCredentials} to the Subject's public credentials.
- Specified by:
commit
in interfaceLoginModule
- Overrides:
commit
in classAbstractLoginModule
- Returns:
- true if this method succeeded, or false if this
LoginModule
should be ignored. - Throws:
LoginException
- if the commit fails- See Also:
LoginModule.commit()
-
doInit
protected void doInit(CallbackHandler callbackHandler, Session session, Map options) throws LoginException
Retrieves the user manager from the specified session. If this fails this login modules initialization must fail.- Specified by:
doInit
in classAbstractLoginModule
- Parameters:
callbackHandler
- as passed byLoginContext
session
- to security-workspace of Jackrabbitoptions
- options from LoginModule config- Throws:
LoginException
- in case initialization fails.- See Also:
AbstractLoginModule.doInit(CallbackHandler, Session, Map)
-
getPrincipal
protected Principal getPrincipal(Credentials credentials)
Resolves the userID from the given credentials and obtains the principal from the User object associated with the given userID. If the the userID cannot be resolved to a User or if obtaining the principal fail,null
is returned.- Specified by:
getPrincipal
in classAbstractLoginModule
- Parameters:
credentials
- Credentials to retrieve the principal for.- Returns:
- a user principal or
null
. - See Also:
AbstractLoginModule.getPrincipal(Credentials)
-
supportsCredentials
protected boolean supportsCredentials(Credentials creds)
Description copied from class:AbstractLoginModule
Return a flag indicating whether the credentials are supported by this login module. Default implementation supportsSimpleCredentials
andGuestCredentials
.- Overrides:
supportsCredentials
in classAbstractLoginModule
- Parameters:
creds
- credentials- Returns:
true
if the credentials are supported;false
otherwise- See Also:
AbstractLoginModule.supportsCredentials(javax.jcr.Credentials)
-
getUserID
protected String getUserID(Credentials credentials)
Description copied from class:AbstractLoginModule
Method supports tries to acquire a UserID in the following order:- If passed credentials are
GuestCredentials
the anonymous user id is returned. - Try to access it from the
Credentials
viaSimpleCredentials.getUserID()
- Ask CallbackHandler for User-ID with use of
NameCallback
. - Test if the 'sharedState' contains a login name.
- Fallback: return the anonymous UserID.
- Overrides:
getUserID
in classAbstractLoginModule
- Parameters:
credentials
- which, may contain a User-ID- Returns:
- The userId retrieved from the credentials or by any other means described above.
- See Also:
AbstractLoginModule.getUserID(javax.jcr.Credentials)
- If passed credentials are
-
getAuthentication
protected Authentication getAuthentication(Principal principal, Credentials creds) throws RepositoryException
Description copied from class:AbstractLoginModule
Retrieve theAuthentication
.- Specified by:
getAuthentication
in classAbstractLoginModule
- Parameters:
principal
- A principal.creds
- The Credentials used for the login.- Returns:
- Authentication object for the given principal / credentials.
- Throws:
RepositoryException
- If an error occurs.- See Also:
AbstractLoginModule.getAuthentication(Principal, Credentials)
-
impersonate
protected boolean impersonate(Principal principal, Credentials credentials) throws RepositoryException, FailedLoginException
Handles the impersonation of given Credentials.Current implementation takes
User
for the given Principal and delegates the check toImpersonation.allows(javax.security.auth.Subject)
- Specified by:
impersonate
in classAbstractLoginModule
- Parameters:
principal
- Principal to impersonate.credentials
- Credentials used to create the impersonation subject.- Returns:
- false, if there is no User to impersonate, true if impersonation is allowed
- Throws:
RepositoryException
FailedLoginException
- if credentials don't allow to impersonate to principal- See Also:
AbstractLoginModule.impersonate(Principal, Credentials)
-
isDisableTokenAuth
public boolean isDisableTokenAuth()
Return a flag indicating if token based authentication is disabled.- Returns:
true
if token based authentication is disabled;false
otherwise.
-
setDisableTokenAuth
public void setDisableTokenAuth(boolean disableTokenAuth)
Set a flag indicating if token based authentication is disabled.- Parameters:
disableTokenAuth
-true
to disable token based authentication;false
otherwise
-
getTokenExpiration
public long getTokenExpiration()
- Returns:
- The configured expiration time for login tokens in milliseconds.
-
setTokenExpiration
public void setTokenExpiration(long tokenExpiration)
- Parameters:
tokenExpiration
- Sets the configured expiration time (in milliseconds) of login tokens.
-
-