Package org.pac4j.core.client
Class BaseClient<C extends Credentials>
- java.lang.Object
-
- org.pac4j.core.util.InitializableObject
-
- org.pac4j.core.client.BaseClient<C>
-
- All Implemented Interfaces:
Client<C>
- Direct Known Subclasses:
DirectClient
,IndirectClient
public abstract class BaseClient<C extends Credentials> extends InitializableObject implements Client<C>
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)
method are handled by thecredentialsExtractor
andauthenticator
components - The user profile retrieval in the
getUserProfile(Credentials, WebContext)
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
-
Constructor Summary
Constructors Constructor Description BaseClient()
-
Method Summary
-
Methods inherited from class org.pac4j.core.util.InitializableObject
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 Optional<C> retrieveCredentials(WebContext context)
Retrieve the credentials.- Parameters:
context
- the web context- Returns:
- the credentials
-
getUserProfile
public final Optional<UserProfile> getUserProfile(C credentials, WebContext context)
Description copied from interface:Client
Get the user profile based on the provided credentials.- Specified by:
getUserProfile
in interfaceClient<C extends Credentials>
- Parameters:
credentials
- credentialscontext
- web context- Returns:
- the user profile (optional)
-
retrieveUserProfile
protected final Optional<UserProfile> retrieveUserProfile(C credentials, WebContext context)
Retrieve a user profile.- Parameters:
credentials
- the credentialscontext
- the web context- Returns:
- the user profile
-
renewUserProfile
public Optional<UserProfile> renewUserProfile(UserProfile profile, WebContext context)
Description copied from interface:Client
Renew the user profile.- Specified by:
renewUserProfile
in interfaceClient<C extends Credentials>
- Parameters:
profile
- the user profilecontext
- the current web context- Returns:
- the renewed user profile (optional).
-
setName
public void setName(String name)
-
getName
public String getName()
Description copied from interface:Client
Get the name of the client.- Specified by:
getName
in interfaceClient<C extends Credentials>
- Returns:
- the name of the client
-
notifySessionRenewal
public void notifySessionRenewal(String oldSessionId, WebContext context)
Notify of the web session renewal.- Parameters:
oldSessionId
- the old session identifiercontext
- the web context
-
getAuthorizationGenerators
public List<AuthorizationGenerator> getAuthorizationGenerators()
-
setAuthorizationGenerators
public void setAuthorizationGenerators(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(List<AuthorizationGenerator> authorizationGenerators)
-
getCredentialsExtractor
public CredentialsExtractor<C> getCredentialsExtractor()
-
defaultCredentialsExtractor
protected void defaultCredentialsExtractor(CredentialsExtractor<C> credentialsExtractor)
-
getAuthenticator
public Authenticator<C> getAuthenticator()
-
defaultAuthenticator
protected void defaultAuthenticator(Authenticator<C> authenticator)
-
getProfileCreator
public ProfileCreator<C> getProfileCreator()
-
defaultProfileCreator
protected void defaultProfileCreator(ProfileCreator<C> profileCreator)
-
setCredentialsExtractor
public void setCredentialsExtractor(CredentialsExtractor<C> credentialsExtractor)
-
setAuthenticator
public void setAuthenticator(Authenticator<C> authenticator)
-
setProfileCreator
public void setProfileCreator(ProfileCreator<C> profileCreator)
-
-