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 theProfileService
for the storage: LDAP, SQL and MongoDB.- Since:
- 2.0.0
- Author:
- Jerome Leleu
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]
attributeNames
static java.lang.String
ID
static java.lang.String
LINKEDID
protected org.slf4j.Logger
logger
static java.lang.String
SERIALIZED_PROFILE
-
Constructor Summary
Constructors Constructor Description AbstractProfileService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected U
convertAttributesToProfile(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> listStorageAttributes, java.lang.String username)
Convert the list of map of attributes from the storage into a profile.protected java.util.Map<java.lang.String,java.lang.Object>
convertProfileAndPasswordToAttributes(U profile, java.lang.String password)
Convert a profile and a password into a map of attributes for the storage.void
create(U profile, java.lang.String password)
Create a profile with the associated password in the storage.protected java.util.List<java.lang.String>
defineAttributesToRead()
Define the attributes to read in the storage.protected abstract void
deleteById(java.lang.String id)
Delete a profile by its identifier in the storage.U
findById(java.lang.String id)
Find a profile by its identifier.U
findByLinkedId(java.lang.String linkedId)
Find a profile by its linked identifier.java.lang.String
getAttributes()
java.lang.String
getIdAttribute()
java.lang.String
getPasswordAttribute()
PasswordEncoder
getPasswordEncoder()
Serializer
getSerializer()
java.lang.String
getUsernameAttribute()
protected abstract void
insert(java.util.Map<java.lang.String,java.lang.Object> attributes)
Insert the attributes in the storage.protected void
internalInit(boolean forceReinit)
Internal initialization of the object.protected boolean
isLegacyMode()
protected abstract java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
read(java.util.List<java.lang.String> names, java.lang.String key, java.lang.String value)
Read the list of defined attributes in the storage for key=value query.void
remove(U profile)
Rmove a profile in the storage.void
removeById(java.lang.String id)
Remove a profile by its identifier in the storage.void
setAttributes(java.lang.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(java.lang.String idAttribute)
void
setPasswordAttribute(java.lang.String passwordAttribute)
void
setPasswordEncoder(PasswordEncoder passwordEncoder)
void
setSerializer(Serializer serializer)
void
setUsernameAttribute(java.lang.String usernameAttribute)
protected abstract void
update(java.util.Map<java.lang.String,java.lang.Object> attributes)
Update the attributes in the storage.void
update(U profile, java.lang.String password)
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 Detail
-
ID
public static final java.lang.String ID
- See Also:
- Constant Field Values
-
LINKEDID
public static final java.lang.String LINKEDID
- See Also:
- Constant Field Values
-
SERIALIZED_PROFILE
public static final java.lang.String SERIALIZED_PROFILE
- See Also:
- Constant Field Values
-
logger
protected final org.slf4j.Logger logger
-
attributeNames
protected java.lang.String[] attributeNames
-
-
Method Detail
-
internalInit
protected void internalInit(boolean forceReinit)
Description copied from class:InitializableObject
Internal initialization of the object.- Specified by:
internalInit
in classInitializableObject
-
create
public void create(U profile, java.lang.String password)
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
public void update(U profile, java.lang.String password)
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
public void remove(U profile)
Description copied from interface:ProfileService
Rmove a profile in the storage.- Specified by:
remove
in interfaceProfileService<U extends CommonProfile>
- Parameters:
profile
- the profile
-
removeById
public void removeById(java.lang.String id)
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
protected java.util.Map<java.lang.String,java.lang.Object> convertProfileAndPasswordToAttributes(U profile, java.lang.String password)
Convert a profile and a password into a map of attributes for the storage.- Parameters:
profile
- the profilepassword
- the password- Returns:
- the attributes
-
insert
protected abstract void insert(java.util.Map<java.lang.String,java.lang.Object> attributes)
Insert the attributes in the storage.- Parameters:
attributes
- the attributes
-
update
protected abstract void update(java.util.Map<java.lang.String,java.lang.Object> attributes)
Update the attributes in the storage.- Parameters:
attributes
- the attributes
-
deleteById
protected abstract void deleteById(java.lang.String id)
Delete a profile by its identifier in the storage.- Parameters:
id
- the identifier
-
findById
public U findById(java.lang.String id)
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
public U findByLinkedId(java.lang.String linkedId)
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
protected java.util.List<java.lang.String> defineAttributesToRead()
Define the attributes to read in the storage.- Returns:
- the attributes
-
convertAttributesToProfile
protected U convertAttributesToProfile(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> listStorageAttributes, java.lang.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
protected abstract java.util.List<java.util.Map<java.lang.String,java.lang.Object>> read(java.util.List<java.lang.String> names, java.lang.String key, java.lang.String value)
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
public void validate(Credentials cred, WebContext context, SessionStore sessionStore)
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
public PasswordEncoder getPasswordEncoder()
-
setPasswordEncoder
public void setPasswordEncoder(PasswordEncoder passwordEncoder)
-
getAttributes
public java.lang.String getAttributes()
-
setAttributes
public void setAttributes(java.lang.String attributes)
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
public Serializer getSerializer()
-
setSerializer
public void setSerializer(Serializer serializer)
-
getUsernameAttribute
public java.lang.String getUsernameAttribute()
-
setUsernameAttribute
public void setUsernameAttribute(java.lang.String usernameAttribute)
-
getPasswordAttribute
public java.lang.String getPasswordAttribute()
-
setPasswordAttribute
public void setPasswordAttribute(java.lang.String passwordAttribute)
-
getIdAttribute
public java.lang.String getIdAttribute()
-
setIdAttribute
public void setIdAttribute(java.lang.String idAttribute)
-
-