Class AbstractLoginModule
java.lang.Object
org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule
- All Implemented Interfaces:
LoginModule
Abstract implementation of the
LoginModule
interface that can act
as base class for login modules that aim to authenticate subjects against
information stored in the content repository.
LoginModule Methods
This base class provides a simple implementation for the following methods of theLoginModule
interface:
Initialize
: Initialization of this abstract module sets the following protected instance fields:- subject: The subject to be authenticated,
- callbackHandler: The callback handler passed to the login module,
- shareState: The map used to share state information with other login modules,
- options: The configuration options of this login module as specified
in the
Configuration
.
Logout
: If the authenticated subject is not empty this logout implementation attempts to clear both principals and public credentials and returnstrue
.Abort
: Clears the state of this login module by setting all private instance variables created in phase 1 or 2 tonull
. Subclasses are in charge of releasing their own state information by either overridingclearState()
.
Utility Methods
The following methods are provided in addition:
clearState()
: Clears all private state information that has be created during login. This method in called inabort()
and subclasses are expected to override this method.getSupportedCredentials()
: Abstract method used bygetCredentials()
that reveals which credential implementations are supported by theLoginModule
.getCredentials()
: Tries to retrieve valid (supported) Credentials in the following order:- using a
CredentialsCallback
, - looking for a
SHARED_KEY_CREDENTIALS
entry in the shared state (see alsogetSharedCredentials()
and finally by - searching for valid credentials in the subject.
- using a
getSharedCredentials()
: This method returns credentials passed to the login module with the share state. The key to share credentials with a another module extending from this base class isSHARED_KEY_CREDENTIALS
. Note, that this method does not verify if the credentials provided by the shared state aresupported
.getSharedLoginName()
: If the shared state contains an entry forSHARED_KEY_LOGIN_NAME
this method returns the value as login name.getSecurityProvider()
: Returns the configured security provider ornull
.getRoot()
: Provides access to the latest state of the repository in order to retrieve user or principal information required to authenticate the subject as well as to write back information duringLoginModule.commit()
.getUserManager()
: Returns an instance of the configuredUserManager
ornull
.getPrincipalProvider()
: Returns an instance of the configured principal provider ornull
.getPrincipals(String)
: Utility that returns all principals associated with a given user id. This method might be be called after successful authentication in order to be able to populate the subject duringLoginModule.commit()
. The implementation is a shortcut for callinggetPrincipals(String userId
on the provider exposed bygetPrincipalProvider()
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Key of the sharedState entry referring to public attributes that are shared between multiple login modules.static final String
Key of the sharedState entry referring to validated Credentials that is shared between multiple login modules.static final String
Key of the sharedState entry referring to a valid login ID that is shared between multiple login modules.static final String
Key of the sharedState entry referring to pre authenticated login information that is shared between multiple login modules. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
abort()
void
initialize
(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) boolean
logout()
Besteffort default implementation ofLoginModule.logout()
, which removes all principals and all public credentials of typeCredentials
andAuthInfo
from the subject.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.security.auth.spi.LoginModule
commit, login
-
Field Details
-
SHARED_KEY_CREDENTIALS
Key of the sharedState entry referring to validated Credentials that is shared between multiple login modules.- See Also:
-
SHARED_KEY_LOGIN_NAME
Key of the sharedState entry referring to a valid login ID that is shared between multiple login modules.- See Also:
-
SHARED_KEY_ATTRIBUTES
Key of the sharedState entry referring to public attributes that are shared between multiple login modules.- See Also:
-
SHARED_KEY_PRE_AUTH_LOGIN
Key of the sharedState entry referring to pre authenticated login information that is shared between multiple login modules.
-
-
Constructor Details
-
AbstractLoginModule
public AbstractLoginModule()
-
-
Method Details
-
initialize
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) - Specified by:
initialize
in interfaceLoginModule
-
logout
Besteffort default implementation ofLoginModule.logout()
, which removes all principals and all public credentials of typeCredentials
andAuthInfo
from the subject. It will returnfalse
, if either principal set or credentials set is empty. Note, that this implementation is not able to only remove those principals/credentials that have been added bythis
very login module instance. Therefore subclasses should overwrite this method to provide a fully compliant solution oflogout()
. They may however take advantage oflogout(Set, Set)
in order to simplify the implementation of a logout that is compatible with theLoginModule.logout()
contract incorporating the additional recommendations highlighted at JAAS LoginModule Dev Guide- Specified by:
logout
in interfaceLoginModule
- Returns:
true
if neither principals nor public credentials of typeCredentials
orAuthInfo
stored in theSubject
are empty;false
otherwise- Throws:
LoginException
- if the subject is readonly and destroyingDestroyable
credentials fails withDestroyFailedException
.
-
abort
- Specified by:
abort
in interfaceLoginModule
- Throws:
LoginException
-