Package org.pac4j.core.profile
Class BasicUserProfile
java.lang.Object
org.pac4j.core.profile.BasicUserProfile
- All Implemented Interfaces:
Externalizable,Serializable,UserProfile
- Direct Known Subclasses:
CommonProfile
This class is the user profile retrieved from a provider after successful authentication: it's an identifier (string) and attributes
(objects). Additional concepts are the "remember me" nature of the user profile, the associated roles, permissions, client name and
linked identifier.
- Since:
- 1.0.0
- Author:
- Jerome Leleu
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBasicUserProfile(boolean canAttributesBeMerged) Create a profile with possibility to merge attributes with the same name and collection-type values. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String key, Object value) Add an attribute.voidaddAttributes(Map<String, Object> attributes) Add attributes.voidaddAuthenticationAttribute(String key, Object value) Add an authentication-related attributevoidaddAuthenticationAttributes(Map<String, Object> attributeMap) Add authentication attributes.voidaddPermission(String permission) Add a permission.voidaddPermissions(Collection<String> permissions) Add permissions.voidAdd a role.voidaddRoles(Collection<String> roles) Add roles.voidBuild a profile from user identifier and attributes.voidBuild a profile from user identifier, attributes, and authentication attributes.booleancontainsAttribute(String name) Check to see if profile contains attribute name.booleanCheck to see if profile contains attribute name.extractAttributeValues(String name) Return the attribute values with name.getAttribute(String name) Return the attribute with name.<T> TgetAttribute(String name, Class<T> clazz) Return the attribute with name.Get all attributes as immutable map.Return the authentication attribute with name.<T> TgetAuthenticationAttribute(String name, Class<T> clazz) Return authentication attribute with nameGet all authentication attributes as an immutable mapgetId()Get the user identifier.Get the permissions of the user.getRoles()Get the roles of the user.Get the user identifier with a prefix which is the profile type (full class name with package).booleanbooleanIs the user remembered?voidvoidremoveAttribute(String key) Remove an attribute by its key.voidRemove an authentication attribute by its keyvoidRemove the specific data retrieved during the login process to only keep the user attributes, roles and permissions.voidsetClientName(String clientName) voidSet the identifier.voidsetLinkedId(String linkedId) voidsetPermissions(Set<String> permissions) voidsetRemembered(boolean rme) Define if this profile is remembered.voidtoString()void
-
Field Details
-
logger
protected final transient org.slf4j.Logger logger
-
-
Constructor Details
-
BasicUserProfile
public BasicUserProfile() -
BasicUserProfile
public BasicUserProfile(boolean canAttributesBeMerged) Create a profile with possibility to merge attributes with the same name and collection-type values.- Parameters:
canAttributesBeMerged- if true - merge attributes with the same name and collection-type values, if false - overwrite them- Since:
- 3.1.0
-
-
Method Details
-
build
Build a profile from user identifier and attributes.- Parameters:
id- user identifierattributes- user attributes
-
build
public void build(Object id, Map<String, Object> attributes, Map<String, Object> authenticationAttributes) Build a profile from user identifier, attributes, and authentication attributes.- Parameters:
id- user identifierattributes- user attributesauthenticationAttributes- authentication attributes
-
setId
Set the identifier.- Specified by:
setIdin interfaceUserProfile- Parameters:
id- user identifier
-
getId
Get the user identifier. This identifier is unique for this provider but not necessarily through all providers.- Specified by:
getIdin interfaceUserProfile- Returns:
- the user identifier
-
getTypedId
Get the user identifier with a prefix which is the profile type (full class name with package). This identifier is unique through all providers.- Specified by:
getTypedIdin interfaceUserProfile- Returns:
- the typed user identifier
-
getUsername
- Specified by:
getUsernamein interfaceUserProfile
-
addAttribute
Add an attribute. If existing attribute value is collection and the new value is collection - merge the collections- Specified by:
addAttributein interfaceUserProfile- Parameters:
key- key of the attributevalue- value of the attribute
-
addAuthenticationAttribute
Add an authentication-related attribute- Specified by:
addAuthenticationAttributein interfaceUserProfile- Parameters:
key- the attribute keyvalue- the attribute value
-
addAttributes
Add attributes.- Parameters:
attributes- use attributes
-
addAuthenticationAttributes
Add authentication attributes.- Parameters:
attributeMap- the authentication attributes
-
removeAttribute
Remove an attribute by its key.- Specified by:
removeAttributein interfaceUserProfile- Parameters:
key- the key
-
removeAuthenticationAttribute
Remove an authentication attribute by its key- Specified by:
removeAuthenticationAttributein interfaceUserProfile- Parameters:
key- the key
-
getAttributes
Get all attributes as immutable map.- Specified by:
getAttributesin interfaceUserProfile- Returns:
- the immutable attributes
-
getAuthenticationAttributes
Get all authentication attributes as an immutable map- Returns:
- the immutable authentication attributes
-
getAttribute
Return the attribute with name.- Specified by:
getAttributein interfaceUserProfile- Parameters:
name- attribute name- Returns:
- the attribute with name
-
extractAttributeValues
Return the attribute values with name.- Parameters:
name- attribute name- Returns:
- the attribute values as List of strings.
-
getAuthenticationAttribute
Return the authentication attribute with name.- Parameters:
name- authentication attribute name- Returns:
- the authentication attribute with name
-
containsAttribute
Check to see if profile contains attribute name.- Specified by:
containsAttributein interfaceUserProfile- Parameters:
name- the name- Returns:
- true/false
-
containsAuthenicationAttribute
Check to see if profile contains attribute name.- Parameters:
name- the name- Returns:
- true/false
-
getAttribute
Return the attribute with name.- Type Parameters:
T- the type of the attribute- Parameters:
name- the attribute nameclazz- the class of the attribute- Returns:
- the attribute by its name
- Since:
- 1.8
-
getAuthenticationAttribute
Return authentication attribute with name- Type Parameters:
T- The type of the authentication attribute- Parameters:
name- Name of authentication attributeclazz- The class of the authentication attribute- Returns:
- the named attribute
-
addRole
Add a role.- Specified by:
addRolein interfaceUserProfile- Parameters:
role- the role to add.
-
addRoles
Add roles.- Specified by:
addRolesin interfaceUserProfile- Parameters:
roles- the roles to add.
-
getRoles
Get the roles of the user.- Specified by:
getRolesin interfaceUserProfile- Returns:
- the user roles.
-
setRoles
-
addPermission
Add a permission.- Specified by:
addPermissionin interfaceUserProfile- Parameters:
permission- the permission to add.
-
addPermissions
Add permissions.- Specified by:
addPermissionsin interfaceUserProfile- Parameters:
permissions- the permissions to add.
-
getPermissions
Get the permissions of the user.- Specified by:
getPermissionsin interfaceUserProfile- Returns:
- the user permissions.
-
setPermissions
-
setRemembered
public void setRemembered(boolean rme) Define if this profile is remembered.- Specified by:
setRememberedin interfaceUserProfile- Parameters:
rme- whether the user is remembered.
-
isRemembered
public boolean isRemembered()Is the user remembered?- Specified by:
isRememberedin interfaceUserProfile- Returns:
- whether the user is remembered.
-
toString
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
removeLoginData
public void removeLoginData()Remove the specific data retrieved during the login process to only keep the user attributes, roles and permissions. -
getClientName
- Specified by:
getClientNamein interfaceUserProfile
-
setClientName
- Specified by:
setClientNamein interfaceUserProfile
-
getLinkedId
- Specified by:
getLinkedIdin interfaceUserProfile
-
setLinkedId
- Specified by:
setLinkedIdin interfaceUserProfile
-
isExpired
public boolean isExpired()- Specified by:
isExpiredin interfaceUserProfile
-
asPrincipal
- Specified by:
asPrincipalin interfaceUserProfile
-