Package org.pac4j.core.profile.service
Class AbstractProfileService<U extends CommonProfile>
java.lang.Object
org.pac4j.core.util.InitializableObject
org.pac4j.core.profile.definition.ProfileDefinitionAware
org.pac4j.core.profile.service.AbstractProfileService<U>
- All Implemented Interfaces:
Authenticator
,ProfileService<U>
- Direct Known Subclasses:
InMemoryProfileService
public abstract class AbstractProfileService<U extends CommonProfile>
extends ProfileDefinitionAware
implements ProfileService<U>, Authenticator
Abstract implementation of the
ProfileService
for the storage: LDAP, SQL and MongoDB.- Since:
- 2.0.0
- Author:
- Jerome Leleu
-
Field Summary
Modifier and TypeFieldDescriptionprotected String[]
static final String
static final String
protected final org.slf4j.Logger
static final String
Fields inherited from interface org.pac4j.core.credentials.authenticator.Authenticator
ALWAYS_VALIDATE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected U
Convert the list of map of attributes from the storage into a profile.convertProfileAndPasswordToAttributes
(U profile, String password) Convert a profile and a password into a map of attributes for the storage.void
Create a profile with the associated password in the storage.Define the attributes to read in the storage.protected abstract void
deleteById
(String id) Delete a profile by its identifier in the storage.Find a profile by its identifier.findByLinkedId
(String linkedId) Find a profile by its linked identifier.protected abstract void
Insert the attributes in the storage.protected void
internalInit
(boolean forceReinit) Internal initialization of the object.protected boolean
Read the list of defined attributes in the storage for key=value query.void
Rmove a profile in the storage.void
removeById
(String id) Remove a profile by its identifier in the storage.void
setAttributes
(String attributes) Since version 2.0 of pac4j, the profile can be saved, updated and deleted in the storage by serializing the profile (in theserializedprofile
attribute).void
setIdAttribute
(String idAttribute) void
setPasswordAttribute
(String passwordAttribute) void
setPasswordEncoder
(PasswordEncoder passwordEncoder) void
setSerializer
(Serializer serializer) void
setUsernameAttribute
(String usernameAttribute) protected abstract void
Update the attributes in the storage.void
Update a profile (with the associated password) in the storage.void
validate
(Credentials cred, WebContext context, SessionStore sessionStore) Validate the credentials.Methods inherited from class org.pac4j.core.profile.definition.ProfileDefinitionAware
defaultProfileDefinition, getProfileDefinition, setProfileDefinition
Methods inherited from class org.pac4j.core.util.InitializableObject
afterInternalInit, beforeInternalInit, getLastAttempt, getMaxAttempts, getMinTimeIntervalBetweenAttemptsInMilliseconds, getNbAttempts, init, init, isInitialized, reinit, setMaxAttempts, setMinTimeIntervalBetweenAttemptsInMilliseconds, shouldInitialize
-
Field Details
-
ID
- See Also:
-
LINKEDID
- See Also:
-
SERIALIZED_PROFILE
- See Also:
-
logger
protected final org.slf4j.Logger logger -
attributeNames
-
-
Constructor Details
-
AbstractProfileService
public AbstractProfileService()
-
-
Method Details
-
internalInit
protected void internalInit(boolean forceReinit) Description copied from class:InitializableObject
Internal initialization of the object.- Specified by:
internalInit
in classInitializableObject
-
create
Description copied from interface:ProfileService
Create a profile with the associated password in the storage.- Specified by:
create
in interfaceProfileService<U extends CommonProfile>
- Parameters:
profile
- the profilepassword
- the password
-
update
Description copied from interface:ProfileService
Update a profile (with the associated password) in the storage.- Specified by:
update
in interfaceProfileService<U extends CommonProfile>
- Parameters:
profile
- the profilepassword
- the optional password
-
remove
Description copied from interface:ProfileService
Rmove a profile in the storage.- Specified by:
remove
in interfaceProfileService<U extends CommonProfile>
- Parameters:
profile
- the profile
-
removeById
Description copied from interface:ProfileService
Remove a profile by its identifier in the storage.- Specified by:
removeById
in interfaceProfileService<U extends CommonProfile>
- Parameters:
id
- the profile identifier
-
convertProfileAndPasswordToAttributes
Convert a profile and a password into a map of attributes for the storage.- Parameters:
profile
- the profilepassword
- the password- Returns:
- the attributes
-
insert
Insert the attributes in the storage.- Parameters:
attributes
- the attributes
-
update
Update the attributes in the storage.- Parameters:
attributes
- the attributes
-
deleteById
Delete a profile by its identifier in the storage.- Parameters:
id
- the identifier
-
findById
Description copied from interface:ProfileService
Find a profile by its identifier.- Specified by:
findById
in interfaceProfileService<U extends CommonProfile>
- Parameters:
id
- the identifier- Returns:
- the found profile
-
findByLinkedId
Description copied from interface:ProfileService
Find a profile by its linked identifier.- Specified by:
findByLinkedId
in interfaceProfileService<U extends CommonProfile>
- Parameters:
linkedId
- the linked identifier- Returns:
- the found profile
-
defineAttributesToRead
Define the attributes to read in the storage.- Returns:
- the attributes
-
convertAttributesToProfile
protected U convertAttributesToProfile(List<Map<String, Object>> listStorageAttributes, String username) Convert the list of map of attributes from the storage into a profile.- Parameters:
listStorageAttributes
- the list of map of attributesusername
- the username used for login- Returns:
- the profile
-
read
Read the list of defined attributes in the storage for key=value query.- Parameters:
names
- the attribute names to readkey
- the key for the queryvalue
- the value for the query- Returns:
- the list of map of attributes
-
validate
Description copied from interface:Authenticator
Validate the credentials. It should throw aCredentialsException
in case of failure.- Specified by:
validate
in interfaceAuthenticator
- Parameters:
cred
- the given credentialscontext
- the web contextsessionStore
- the session store
-
isLegacyMode
protected boolean isLegacyMode() -
getPasswordEncoder
-
setPasswordEncoder
-
getAttributes
-
setAttributes
Since version 2.0 of pac4j, the profile can be saved, updated and deleted in the storage by serializing the profile (in the
serializedprofile
attribute).In addition to what existed in previous versions, the profile was built from existing attributes. Setting this attribute with a list of attributes separated by commas (no aliasing) allows you to use different attributes of the storage instead of the
serializedprofile
attribute.- Parameters:
attributes
- the attributes
-
getSerializer
-
setSerializer
-
getUsernameAttribute
-
setUsernameAttribute
-
getPasswordAttribute
-
setPasswordAttribute
-
getIdAttribute
-
setIdAttribute
-