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
public abstract class BaseClient extends InitializableObject implements Client
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()
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
Fields Modifier and Type Field Description protected org.slf4j.Logger
logger
protected java.lang.Boolean
saveProfileInSession
-
Constructor Summary
Constructors Constructor Description BaseClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAuthorizationGenerator(AuthorizationGenerator authorizationGenerator)
void
addAuthorizationGenerators(java.util.List<AuthorizationGenerator> authorizationGenerators)
protected void
defaultAuthenticator(Authenticator authenticator)
protected void
defaultCredentialsExtractor(CredentialsExtractor credentialsExtractor)
protected void
defaultProfileCreator(ProfileCreator profileCreator)
Authenticator
getAuthenticator()
java.util.List<AuthorizationGenerator>
getAuthorizationGenerators()
CredentialsExtractor
getCredentialsExtractor()
java.util.Map<java.lang.String,java.lang.Object>
getCustomProperties()
java.lang.String
getName()
Get the name of the client.ProfileCreator
getProfileCreator()
ProfileFactory
getProfileFactoryWhenNotAuthenticated()
java.lang.Boolean
getSaveProfileInSession(WebContext context, UserProfile profile)
java.util.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(java.lang.String oldSessionId, WebContext context, SessionStore sessionStore)
Notify of the web session renewal.java.util.Optional<UserProfile>
renewUserProfile(UserProfile profile, WebContext context, SessionStore sessionStore)
Renew the user profile.protected java.util.Optional<Credentials>
retrieveCredentials(WebContext context, SessionStore sessionStore)
Retrieve the credentials.protected java.util.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(java.util.List<AuthorizationGenerator> authorizationGenerators)
void
setAuthorizationGenerators(AuthorizationGenerator... authorizationGenerators)
void
setCredentialsExtractor(CredentialsExtractor credentialsExtractor)
void
setCustomProperties(java.util.Map<java.lang.String,java.lang.Object> customProperties)
void
setMultiProfile(boolean multiProfile)
void
setName(java.lang.String name)
void
setProfileCreator(ProfileCreator profileCreator)
void
setProfileFactoryWhenNotAuthenticated(ProfileFactory profileFactoryWhenNotAuthenticated)
void
setSaveProfileInSession(boolean saveProfileInSession)
java.lang.String
toString()
-
Methods inherited from class org.pac4j.core.util.InitializableObject
afterInternalInit, beforeInternalInit, init, internalInit, isInitialized
-
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
-
-
-
-
Method Detail
-
retrieveCredentials
protected java.util.Optional<Credentials> retrieveCredentials(WebContext context, SessionStore sessionStore)
Retrieve the credentials.- Parameters:
context
- the web context- Returns:
- the credentials
-
getUserProfile
public final java.util.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 java.util.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 java.util.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
public void setName(java.lang.String name)
-
getName
public java.lang.String getName()
Description copied from interface:Client
Get the name of the client.
-
notifySessionRenewal
public void notifySessionRenewal(java.lang.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
public java.util.List<AuthorizationGenerator> getAuthorizationGenerators()
-
setAuthorizationGenerators
public void setAuthorizationGenerators(java.util.List<AuthorizationGenerator> authorizationGenerators)
-
setAuthorizationGenerators
public void setAuthorizationGenerators(AuthorizationGenerator... authorizationGenerators)
-
setAuthorizationGenerator
public void setAuthorizationGenerator(AuthorizationGenerator authorizationGenerator)
Add an authorization generator.- Parameters:
authorizationGenerator
- an authorizations generator
-
addAuthorizationGenerator
public void addAuthorizationGenerator(AuthorizationGenerator authorizationGenerator)
-
addAuthorizationGenerators
public void addAuthorizationGenerators(java.util.List<AuthorizationGenerator> authorizationGenerators)
-
getCredentialsExtractor
public CredentialsExtractor getCredentialsExtractor()
-
defaultCredentialsExtractor
protected void defaultCredentialsExtractor(CredentialsExtractor credentialsExtractor)
-
getAuthenticator
public Authenticator getAuthenticator()
-
defaultAuthenticator
protected void defaultAuthenticator(Authenticator authenticator)
-
getProfileCreator
public ProfileCreator getProfileCreator()
-
defaultProfileCreator
protected void defaultProfileCreator(ProfileCreator profileCreator)
-
setCredentialsExtractor
public void setCredentialsExtractor(CredentialsExtractor credentialsExtractor)
-
setAuthenticator
public void setAuthenticator(Authenticator authenticator)
-
setProfileCreator
public void setProfileCreator(ProfileCreator profileCreator)
-
getCustomProperties
public java.util.Map<java.lang.String,java.lang.Object> getCustomProperties()
-
setCustomProperties
public void setCustomProperties(java.util.Map<java.lang.String,java.lang.Object> customProperties)
-
getProfileFactoryWhenNotAuthenticated
public ProfileFactory getProfileFactoryWhenNotAuthenticated()
-
setProfileFactoryWhenNotAuthenticated
public void setProfileFactoryWhenNotAuthenticated(ProfileFactory profileFactoryWhenNotAuthenticated)
-
isMultiProfile
public boolean isMultiProfile(WebContext context, UserProfile profile)
-
setMultiProfile
public void setMultiProfile(boolean multiProfile)
-
getSaveProfileInSession
public java.lang.Boolean getSaveProfileInSession(WebContext context, UserProfile profile)
-
setSaveProfileInSession
public void setSaveProfileInSession(boolean saveProfileInSession)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-