Package org.pac4j.core.client
Class BaseClient
java.lang.Object
org.pac4j.core.util.InitializableObject
org.pac4j.core.client.BaseClient
- All Implemented Interfaces:
Client
- Direct Known Subclasses:
DirectClient
,IndirectClient
This class is the default implementation of an authentication client (whatever the mechanism). It has the core concepts:
- The initialization process is handled by the
InitializableObject
inheritance, theInitializableObject.internalInit(boolean)
must be implemented in sub-classes. TheInitializableObject.init()
method must be called implicitly by the main methods of theClient
interface, so that no explicit call is required to initialize the client - The name of the client is handled through the
setName(String)
andgetName()
methods - After retrieving the user profile, the client can generate the authorization information (roles, permissions and remember-me) by
using the appropriate
AuthorizationGenerator
- The credentials extraction and validation in the
Client.getCredentials(WebContext, SessionStore)
method are handled by thecredentialsExtractor
andauthenticator
components - The user profile retrieval in the
getUserProfile(Credentials, WebContext, SessionStore)
method is ensured by theprofileCreator
component.
- Since:
- 1.4.0
- Author:
- Jerome Leleu
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAuthorizationGenerator
(AuthorizationGenerator authorizationGenerator) void
addAuthorizationGenerators
(List<AuthorizationGenerator> authorizationGenerators) protected void
defaultAuthenticator
(Authenticator authenticator) protected void
defaultCredentialsExtractor
(CredentialsExtractor credentialsExtractor) protected void
defaultProfileCreator
(ProfileCreator profileCreator) getName()
Get the name of the client.getSaveProfileInSession
(WebContext context, UserProfile profile) final Optional<UserProfile>
getUserProfile
(Credentials credentials, WebContext context, SessionStore sessionStore) Get the user profile based on the provided credentials.boolean
isMultiProfile
(WebContext context, UserProfile profile) void
notifySessionRenewal
(String oldSessionId, WebContext context, SessionStore sessionStore) Notify of the web session renewal.renewUserProfile
(UserProfile profile, WebContext context, SessionStore sessionStore) Renew the user profile.protected Optional<Credentials>
retrieveCredentials
(WebContext context, SessionStore sessionStore) Retrieve the credentials.protected final Optional<UserProfile>
retrieveUserProfile
(Credentials credentials, WebContext context, SessionStore sessionStore) Retrieve a user profile.void
setAuthenticator
(Authenticator authenticator) void
setAuthorizationGenerator
(AuthorizationGenerator authorizationGenerator) Add an authorization generator.void
setAuthorizationGenerators
(List<AuthorizationGenerator> authorizationGenerators) void
setAuthorizationGenerators
(AuthorizationGenerator... authorizationGenerators) void
setCredentialsExtractor
(CredentialsExtractor credentialsExtractor) void
setCustomProperties
(Map<String, Object> customProperties) void
setMultiProfile
(boolean multiProfile) void
void
setProfileCreator
(ProfileCreator profileCreator) void
setProfileFactoryWhenNotAuthenticated
(ProfileFactory profileFactoryWhenNotAuthenticated) void
setSaveProfileInSession
(boolean saveProfileInSession) toString()
Methods inherited from class org.pac4j.core.util.InitializableObject
afterInternalInit, beforeInternalInit, getLastAttempt, getMaxAttempts, getMinTimeIntervalBetweenAttemptsInMilliseconds, getNbAttempts, init, init, internalInit, isInitialized, reinit, setMaxAttempts, setMinTimeIntervalBetweenAttemptsInMilliseconds, shouldInitialize
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.pac4j.core.client.Client
getCredentials, getLogoutAction, getRedirectionAction
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
saveProfileInSession
-
-
Constructor Details
-
BaseClient
public BaseClient()
-
-
Method Details
-
retrieveCredentials
Retrieve the credentials.- Parameters:
context
- the web context- Returns:
- the credentials
-
getUserProfile
public final Optional<UserProfile> getUserProfile(Credentials credentials, WebContext context, SessionStore sessionStore) Description copied from interface:Client
Get the user profile based on the provided credentials.- Specified by:
getUserProfile
in interfaceClient
- Parameters:
credentials
- credentialscontext
- web contextsessionStore
- the session store- Returns:
- the user profile (optional)
-
retrieveUserProfile
protected final Optional<UserProfile> retrieveUserProfile(Credentials credentials, WebContext context, SessionStore sessionStore) Retrieve a user profile.- Parameters:
credentials
- the credentialscontext
- the web context- Returns:
- the user profile
-
renewUserProfile
public Optional<UserProfile> renewUserProfile(UserProfile profile, WebContext context, SessionStore sessionStore) Description copied from interface:Client
Renew the user profile.- Specified by:
renewUserProfile
in interfaceClient
- Parameters:
profile
- the user profilecontext
- the current web contextsessionStore
- the session store- Returns:
- the renewed user profile (optional).
-
setName
-
getName
Description copied from interface:Client
Get the name of the client. -
notifySessionRenewal
public void notifySessionRenewal(String oldSessionId, WebContext context, SessionStore sessionStore) Notify of the web session renewal.- Parameters:
oldSessionId
- the old session identifiercontext
- the web contextsessionStore
- the session store
-
getAuthorizationGenerators
-
setAuthorizationGenerators
-
setAuthorizationGenerators
-
setAuthorizationGenerator
Add an authorization generator.- Parameters:
authorizationGenerator
- an authorizations generator
-
addAuthorizationGenerator
-
addAuthorizationGenerators
-
getCredentialsExtractor
-
defaultCredentialsExtractor
-
getAuthenticator
-
defaultAuthenticator
-
getProfileCreator
-
defaultProfileCreator
-
setCredentialsExtractor
-
setAuthenticator
-
setProfileCreator
-
getCustomProperties
-
setCustomProperties
-
getProfileFactoryWhenNotAuthenticated
-
setProfileFactoryWhenNotAuthenticated
public void setProfileFactoryWhenNotAuthenticated(ProfileFactory profileFactoryWhenNotAuthenticated) -
isMultiProfile
-
setMultiProfile
public void setMultiProfile(boolean multiProfile) -
getSaveProfileInSession
-
setSaveProfileInSession
public void setSaveProfileInSession(boolean saveProfileInSession) -
toString
-