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<U>
-
- org.pac4j.core.profile.service.AbstractProfileService<U>
-
- All Implemented Interfaces:
Authenticator<UsernamePasswordCredentials>
,ProfileService<U>
- Direct Known Subclasses:
InMemoryProfileService
public abstract class AbstractProfileService<U extends CommonProfile> extends ProfileDefinitionAware<U> implements ProfileService<U>, Authenticator<UsernamePasswordCredentials>
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 String[]
attributeNames
static String
ID
static String
LINKEDID
protected org.slf4j.Logger
logger
static 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(List<Map<String,Object>> listStorageAttributes, String username)
Convert the list of map of attributes from the storage into a profile.protected Map<String,Object>
convertProfileAndPasswordToAttributes(U profile, String password)
Convert a profile and a password into a map of attributes for the storage.void
create(U profile, String password)
Create a profile with the associated password in the storage.protected List<String>
defineAttributesToRead()
Define the attributes to read in the storage.protected abstract void
deleteById(String id)
Delete a profile by its identifier in the storage.U
findById(String id)
Find a profile by its identifier.U
findByLinkedId(String linkedId)
Find a profile by its linked identifier.String
getAttributes()
String
getIdAttribute()
JavaSerializationHelper
getJavaSerializationHelper()
String
getPasswordAttribute()
PasswordEncoder
getPasswordEncoder()
String
getUsernameAttribute()
protected abstract void
insert(Map<String,Object> attributes)
Insert the attributes in the storage.protected void
internalInit()
Internal initialization of the object.protected boolean
isLegacyMode()
protected abstract List<Map<String,Object>>
read(List<String> names, String key, 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(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
setJavaSerializationHelper(JavaSerializationHelper javaSerializationHelper)
void
setPasswordAttribute(String passwordAttribute)
void
setPasswordEncoder(PasswordEncoder passwordEncoder)
void
setUsernameAttribute(String usernameAttribute)
protected abstract void
update(Map<String,Object> attributes)
Update the attributes in the storage.void
update(U profile, String password)
Update a profile (with the associated password) in the storage.void
validate(UsernamePasswordCredentials credentials, WebContext context)
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
init, isInitialized
-
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
LINKEDID
public static final String LINKEDID
- See Also:
- Constant Field Values
-
SERIALIZED_PROFILE
public static final String SERIALIZED_PROFILE
- See Also:
- Constant Field Values
-
logger
protected final org.slf4j.Logger logger
-
attributeNames
protected String[] attributeNames
-
-
Method Detail
-
internalInit
protected void internalInit()
Description copied from class:InitializableObject
Internal initialization of the object.- Specified by:
internalInit
in classInitializableObject
-
create
public void create(U profile, 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, 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(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 Map<String,Object> convertProfileAndPasswordToAttributes(U profile, 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(Map<String,Object> attributes)
Insert the attributes in the storage.- Parameters:
attributes
- the attributes
-
update
protected abstract void update(Map<String,Object> attributes)
Update the attributes in the storage.- Parameters:
attributes
- the attributes
-
deleteById
protected abstract void deleteById(String id)
Delete a profile by its identifier in the storage.- Parameters:
id
- the identifier
-
findById
public U findById(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(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 List<String> 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
protected abstract List<Map<String,Object>> read(List<String> names, String key, 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(UsernamePasswordCredentials credentials, WebContext context)
Description copied from interface:Authenticator
Validate the credentials. It should throw aCredentialsException
in case of failure.- Specified by:
validate
in interfaceAuthenticator<U extends CommonProfile>
- Parameters:
credentials
- the given credentialscontext
- the web context
-
isLegacyMode
protected boolean isLegacyMode()
-
getPasswordEncoder
public PasswordEncoder getPasswordEncoder()
-
setPasswordEncoder
public void setPasswordEncoder(PasswordEncoder passwordEncoder)
-
getAttributes
public String getAttributes()
-
setAttributes
public 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 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
-
getJavaSerializationHelper
public JavaSerializationHelper getJavaSerializationHelper()
-
setJavaSerializationHelper
public void setJavaSerializationHelper(JavaSerializationHelper javaSerializationHelper)
-
getUsernameAttribute
public String getUsernameAttribute()
-
setUsernameAttribute
public void setUsernameAttribute(String usernameAttribute)
-
getPasswordAttribute
public String getPasswordAttribute()
-
setPasswordAttribute
public void setPasswordAttribute(String passwordAttribute)
-
getIdAttribute
public String getIdAttribute()
-
setIdAttribute
public void setIdAttribute(String idAttribute)
-
-