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
FieldsModifier and TypeFieldDescriptionprotected String[]static final Stringstatic final Stringprotected final org.slf4j.Loggerstatic final StringFields inherited from interface org.pac4j.core.credentials.authenticator.Authenticator
ALWAYS_VALIDATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UConvert 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.voidCreate a profile with the associated password in the storage.Define the attributes to read in the storage.protected abstract voiddeleteById(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 voidInsert the attributes in the storage.protected voidinternalInit(boolean forceReinit) Internal initialization of the object.protected booleanRead the list of defined attributes in the storage for key=value query.voidRmove a profile in the storage.voidremoveById(String id) Remove a profile by its identifier in the storage.voidsetAttributes(String attributes) Since version 2.0 of pac4j, the profile can be saved, updated and deleted in the storage by serializing the profile (in theserializedprofileattribute).voidsetIdAttribute(String idAttribute) voidsetPasswordAttribute(String passwordAttribute) voidsetPasswordEncoder(PasswordEncoder passwordEncoder) voidsetSerializer(Serializer serializer) voidsetUsernameAttribute(String usernameAttribute) protected abstract voidUpdate the attributes in the storage.voidUpdate a profile (with the associated password) in the storage.voidvalidate(Credentials cred, WebContext context, SessionStore sessionStore) Validate the credentials.Methods inherited from class org.pac4j.core.profile.definition.ProfileDefinitionAware
defaultProfileDefinition, getProfileDefinition, setProfileDefinitionMethods 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:InitializableObjectInternal initialization of the object.- Specified by:
internalInitin classInitializableObject
-
create
Description copied from interface:ProfileServiceCreate a profile with the associated password in the storage.- Specified by:
createin interfaceProfileService<U extends CommonProfile>- Parameters:
profile- the profilepassword- the password
-
update
Description copied from interface:ProfileServiceUpdate a profile (with the associated password) in the storage.- Specified by:
updatein interfaceProfileService<U extends CommonProfile>- Parameters:
profile- the profilepassword- the optional password
-
remove
Description copied from interface:ProfileServiceRmove a profile in the storage.- Specified by:
removein interfaceProfileService<U extends CommonProfile>- Parameters:
profile- the profile
-
removeById
Description copied from interface:ProfileServiceRemove a profile by its identifier in the storage.- Specified by:
removeByIdin 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:ProfileServiceFind a profile by its identifier.- Specified by:
findByIdin interfaceProfileService<U extends CommonProfile>- Parameters:
id- the identifier- Returns:
- the found profile
-
findByLinkedId
Description copied from interface:ProfileServiceFind a profile by its linked identifier.- Specified by:
findByLinkedIdin 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:AuthenticatorValidate the credentials. It should throw aCredentialsExceptionin case of failure.- Specified by:
validatein 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
serializedprofileattribute).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
serializedprofileattribute.- Parameters:
attributes- the attributes
-
getSerializer
-
setSerializer
-
getUsernameAttribute
-
setUsernameAttribute
-
getPasswordAttribute
-
setPasswordAttribute
-
getIdAttribute
-
setIdAttribute
-