public abstract class AbstractProfileService<U extends CommonProfile> extends ProfileDefinitionAware<U> implements ProfileService<U>, Authenticator<UsernamePasswordCredentials>
ProfileService
for the storage: LDAP, SQL and MongoDB.Modifier and Type | Field and Description |
---|---|
protected String[] |
attributeNames |
static String |
ID |
static String |
LINKEDID |
protected org.slf4j.Logger |
logger |
static String |
SERIALIZED_PROFILE |
Constructor and Description |
---|
AbstractProfileService() |
Modifier and Type | Method and 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(WebContext context)
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 the
serializedprofile 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.
|
defaultProfileDefinition, getProfileDefinition, setProfileDefinition
init, reinit
public static final String ID
public static final String LINKEDID
public static final String SERIALIZED_PROFILE
protected final org.slf4j.Logger logger
protected String[] attributeNames
protected void internalInit(WebContext context)
InitializableWebObject
internalInit
in class InitializableWebObject
context
- the web contextpublic void create(U profile, String password)
ProfileService
create
in interface ProfileService<U extends CommonProfile>
profile
- the profilepassword
- the passwordpublic void update(U profile, String password)
ProfileService
update
in interface ProfileService<U extends CommonProfile>
profile
- the profilepassword
- the optional passwordpublic void remove(U profile)
ProfileService
remove
in interface ProfileService<U extends CommonProfile>
profile
- the profilepublic void removeById(String id)
ProfileService
removeById
in interface ProfileService<U extends CommonProfile>
id
- the profile identifierprotected Map<String,Object> convertProfileAndPasswordToAttributes(U profile, String password)
profile
- the profilepassword
- the passwordprotected abstract void insert(Map<String,Object> attributes)
attributes
- the attributesprotected abstract void update(Map<String,Object> attributes)
attributes
- the attributesprotected abstract void deleteById(String id)
id
- the identifierpublic U findById(String id)
ProfileService
findById
in interface ProfileService<U extends CommonProfile>
id
- the identifierpublic U findByLinkedId(String linkedId)
ProfileService
findByLinkedId
in interface ProfileService<U extends CommonProfile>
linkedId
- the linked identifierprotected List<String> defineAttributesToRead()
protected U convertAttributesToProfile(List<Map<String,Object>> listStorageAttributes, String username)
listStorageAttributes
- the list of map of attributesusername
- the username used for loginprotected abstract List<Map<String,Object>> read(List<String> names, String key, String value)
names
- the attribute names to readkey
- the key for the queryvalue
- the value for the querypublic void validate(UsernamePasswordCredentials credentials, WebContext context) throws HttpAction, CredentialsException
Authenticator
CredentialsException
in case of failure.validate
in interface Authenticator<UsernamePasswordCredentials>
credentials
- the given credentialscontext
- the web contextHttpAction
- requires a specific HTTP action if necessaryCredentialsException
- the credentials are invalidprotected boolean isLegacyMode()
public PasswordEncoder getPasswordEncoder()
public void setPasswordEncoder(PasswordEncoder passwordEncoder)
public String getAttributes()
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.
attributes
- the attributespublic JavaSerializationHelper getJavaSerializationHelper()
public void setJavaSerializationHelper(JavaSerializationHelper javaSerializationHelper)
public String getUsernameAttribute()
public void setUsernameAttribute(String usernameAttribute)
public String getPasswordAttribute()
public void setPasswordAttribute(String passwordAttribute)
public String getIdAttribute()
public void setIdAttribute(String idAttribute)
Copyright © 2018. All rights reserved.