Class AbstractLoginModule
- java.lang.Object
-
- org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule
-
- All Implemented Interfaces:
LoginModule
- Direct Known Subclasses:
ExternalLoginModule,LoginModuleImpl,TokenLoginModule
@ProviderType public abstract class AbstractLoginModule extends Object implements LoginModule
Abstract implementation of theLoginModuleinterface 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 theLoginModuleinterface: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_CREDENTIALSentry 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_NAMEthis 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 configuredUserManagerornull.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 userIdon the provider exposed bygetPrincipalProvider()
-
-
Field Summary
Fields Modifier and Type Field Description protected CallbackHandlercallbackHandlerprotected ConfigurationParametersoptionsstatic StringSHARED_KEY_ATTRIBUTESKey of the sharedState entry referring to public attributes that are shared between multiple login modules.static StringSHARED_KEY_CREDENTIALSKey of the sharedState entry referring to validated Credentials that is shared between multiple login modules.static StringSHARED_KEY_LOGIN_NAMEKey of the sharedState entry referring to a valid login ID that is shared between multiple login modules.static StringSHARED_KEY_PRE_AUTH_LOGINKey of the sharedState entry referring to pre authenticated login information that is shared between multiple login modules.protected MapsharedStateprotected Subjectsubject
-
Constructor Summary
Constructors Constructor Description AbstractLoginModule()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanabort()protected voidclearState()Clear state information that has been created duringLoginModule.login().protected voidcloseSystemSession()Close the system session acquired upongetRoot()and reset the associated root field.protected @Nullable CredentialsgetCredentials()Tries to retrieve valid (supported) Credentials: using aCredentialsCallback, looking for aSHARED_KEY_CREDENTIALSentry in the shared state (see alsogetSharedCredentials()and finally by searching for valid credentials in the subject.protected @NotNull LoginModuleMonitorgetLoginModuleMonitor()protected @Nullable PrincipalProvidergetPrincipalProvider()Retrieves thePrincipalProviderthat should be used to handle this authentication.protected @NotNull Set<? extends Principal>getPrincipals(@NotNull String userId)Retrieves all principals associated with the specifieduserIdfor the configured principal provider.protected @NotNull Set<? extends Principal>getPrincipals(@NotNull Principal userPrincipal)protected @Nullable RootgetRoot()Tries to obtain aRootobject from the callback handler using a new RepositoryCallback and keeps the value as private field.protected @Nullable SecurityProvidergetSecurityProvider()Tries to obtain theSecurityProviderobject from the callback handler using a new SecurityProviderCallback and keeps the value as private field.protected @Nullable CredentialsgetSharedCredentials()protected @Nullable StringgetSharedLoginName()protected @Nullable PreAuthenticatedLogingetSharedPreAuthLogin()protected abstract @NotNull Set<Class>getSupportedCredentials()protected @Nullable UserManagergetUserManager()Retrieves theUserManagerthat should be used to handle this authentication.protected @Nullable WhiteboardgetWhiteboard()Tries to obtain theWhiteboardobject from the callback handler using a new WhiteboardCallback and keeps the value as private field.voidinitialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)booleanlogout()Besteffort default implementation ofLoginModule.logout(), which removes all principals and all public credentials of typeCredentialsandAuthInfofrom the subject.protected booleanlogout(@Nullable Set<Object> credentials, @Nullable Set<? extends Principal> principals)General logout-helper that will returnfalseif bothcredentialsandprincipalsarenull.protected voidonError()protected static voidsetAuthInfo(@NotNull AuthInfo authInfo, @NotNull Subject subject)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.security.auth.spi.LoginModule
commit, login
-
-
-
-
Field Detail
-
SHARED_KEY_CREDENTIALS
public static final String SHARED_KEY_CREDENTIALS
Key of the sharedState entry referring to validated Credentials that is shared between multiple login modules.- See Also:
- Constant Field Values
-
SHARED_KEY_LOGIN_NAME
public static final String SHARED_KEY_LOGIN_NAME
Key of the sharedState entry referring to a valid login ID that is shared between multiple login modules.- See Also:
- Constant Field Values
-
SHARED_KEY_ATTRIBUTES
public static final String SHARED_KEY_ATTRIBUTES
Key of the sharedState entry referring to public attributes that are shared between multiple login modules.- See Also:
- Constant Field Values
-
SHARED_KEY_PRE_AUTH_LOGIN
public static final String SHARED_KEY_PRE_AUTH_LOGIN
Key of the sharedState entry referring to pre authenticated login information that is shared between multiple login modules.
-
subject
protected Subject subject
-
callbackHandler
protected CallbackHandler callbackHandler
-
sharedState
protected Map sharedState
-
options
protected ConfigurationParameters options
-
-
Method Detail
-
initialize
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)
- Specified by:
initializein interfaceLoginModule
-
logout
public boolean logout() throws LoginExceptionBesteffort default implementation ofLoginModule.logout(), which removes all principals and all public credentials of typeCredentialsandAuthInfofrom 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 bythisvery 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:
logoutin interfaceLoginModule- Returns:
trueif neither principals nor public credentials of typeCredentialsorAuthInfostored in theSubjectare empty;falseotherwise- Throws:
LoginException- if the subject is readonly and destroyingDestroyablecredentials fails withDestroyFailedException.
-
abort
public boolean abort() throws LoginException- Specified by:
abortin interfaceLoginModule- Throws:
LoginException
-
clearState
protected void clearState()
Clear state information that has been created duringLoginModule.login().
-
closeSystemSession
protected void closeSystemSession()
Close the system session acquired upongetRoot()and reset the associated root field. This method should be used instead ofclearState(), ifLoginModule.login()andLoginModule.commit()were successfully completed but the system session is not needed for a successfullogout()
-
logout
protected boolean logout(@Nullable @Nullable Set<Object> credentials, @Nullable @Nullable Set<? extends Principal> principals) throws LoginExceptionGeneral logout-helper that will returnfalseif bothcredentialsandprincipalsarenull. Note, that this implementation will only throwLoginExceptionif thesubjectis marked readonly and destroyingDestroyablecredentials fails.- Parameters:
credentials- The set of credentials extracted by this instance during login/commit to be removed fromSubject.getPublicCredentials()principals- A set of principals extracted by this instance during login/commit to be removed fromSubject.getPrincipals()- Returns:
trueif either the credential set or the principal set is notnull,falseotherwise.- Throws:
LoginException- If the subject is readonly and an error occurs while destroying any of the given credentials.- See Also:
- JAASLMDevGuide
-
getSupportedCredentials
@NotNull protected abstract @NotNull Set<Class> getSupportedCredentials()
- Returns:
- A set of supported credential classes.
-
getCredentials
@Nullable protected @Nullable Credentials getCredentials()
Tries to retrieve valid (supported) Credentials:- using a
CredentialsCallback, - looking for a
SHARED_KEY_CREDENTIALSentry in the shared state (see alsogetSharedCredentials()and finally by - searching for valid credentials in the subject.
- Returns:
- Valid (supported) credentials or
null.
- using a
-
getSharedCredentials
@Nullable protected @Nullable Credentials getSharedCredentials()
- Returns:
- The credentials passed to this login module with the shared state.
- See Also:
SHARED_KEY_CREDENTIALS
-
getSharedLoginName
@Nullable protected @Nullable String getSharedLoginName()
- Returns:
- The login name passed to this login module with the shared state.
- See Also:
SHARED_KEY_LOGIN_NAME
-
getSharedPreAuthLogin
@Nullable protected @Nullable PreAuthenticatedLogin getSharedPreAuthLogin()
- Returns:
- The pre authenticated login or
null - See Also:
SHARED_KEY_PRE_AUTH_LOGIN
-
getSecurityProvider
@Nullable protected @Nullable SecurityProvider getSecurityProvider()
Tries to obtain theSecurityProviderobject from the callback handler using a new SecurityProviderCallback and keeps the value as private field. If the callback handler isn't able to handle the SecurityProviderCallback this method returnsnull.- Returns:
- The
SecurityProviderassociated with thisLoginModuleornull.
-
getWhiteboard
@Nullable protected @Nullable Whiteboard getWhiteboard()
Tries to obtain theWhiteboardobject from the callback handler using a new WhiteboardCallback and keeps the value as private field. If the callback handler isn't able to handle the WhiteboardCallback this method returnsnull.- Returns:
- The
Whiteboardassociated with thisLoginModuleornull.
-
getRoot
@Nullable protected @Nullable Root getRoot()
Tries to obtain aRootobject from the callback handler using a new RepositoryCallback and keeps the value as private field. If the callback handler isn't able to handle the RepositoryCallback this method returnsnull.- Returns:
- The
Rootassociated with thisLoginModuleornull.
-
getUserManager
@Nullable protected @Nullable UserManager getUserManager()
Retrieves theUserManagerthat should be used to handle this authentication. If no user manager has been configure this method returnsnull.- Returns:
- A instance of
UserManagerornull.
-
getPrincipalProvider
@Nullable protected @Nullable PrincipalProvider getPrincipalProvider()
Retrieves thePrincipalProviderthat should be used to handle this authentication. If no principal provider has been configure this method returnsnull.- Returns:
- A instance of
PrincipalProviderornull.
-
getPrincipals
@NotNull protected @NotNull Set<? extends Principal> getPrincipals(@NotNull @NotNull String userId)
Retrieves all principals associated with the specifieduserIdfor the configured principal provider.- Parameters:
userId- The id of the user.- Returns:
- The set of principals associated with the given
userId. - See Also:
getPrincipalProvider()
-
getPrincipals
@NotNull protected @NotNull Set<? extends Principal> getPrincipals(@NotNull @NotNull Principal userPrincipal)
-
setAuthInfo
protected static void setAuthInfo(@NotNull @NotNull AuthInfo authInfo, @NotNull @NotNull Subject subject)
-
getLoginModuleMonitor
@NotNull protected @NotNull LoginModuleMonitor getLoginModuleMonitor()
-
onError
protected void onError()
-
-