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, client name and linked identifier.
- Since:
- 1.0.0
- Author:
- Jerome Leleu
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructor for BasicUserProfile.BasicUserProfile
(boolean canAttributesBeMerged) Create a profile with possibility to merge attributes with the same name and collection-type values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String key, Object value) addAttribute.void
addAttributes
(Map<String, Object> attributes) Add attributes.void
addAuthenticationAttribute
(String key, Object value) addAuthenticationAttribute.void
addAuthenticationAttributes
(Map<String, Object> attributeMap) Add authentication attributes.void
addRole.void
addRoles
(Collection<String> roles) addRoles.asPrincipal.void
Build a profile from user identifier and attributes.void
Build a profile from user identifier, attributes, and authentication attributes.boolean
containsAttribute
(String name) containsAttribute.boolean
Check to see if profile contains attribute name.extractAttributeValues
(String name) Return the attribute values with name.getAttribute
(String name) getAttribute.<T> T
getAttribute
(String name, Class<T> clazz) Return the attribute with name.getAttributes.Return the authentication attribute with name.<T> T
getAuthenticationAttribute
(String name, Class<T> clazz) Return authentication attribute with nameGet all authentication attributes as an immutable mapgetRoles()
getRoles.getTypedId.getUsername.boolean
isExpired.void
void
removeAttribute
(String key) removeAttribute.void
removeAuthenticationAttribute.void
Remove the specific data retrieved during the login process to only keep the user attributes and roles.void
setId.void
Setter for the fieldroles
.void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.pac4j.core.profile.UserProfile
getClientName, getId, getLinkedId, isRemembered, setClientName, setLinkedId, setRemembered
-
Field Details
-
logger
protected final transient org.slf4j.Logger logger
-
-
Constructor Details
-
BasicUserProfile
public BasicUserProfile()Constructor for 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
setId.
Set the identifier.- Specified by:
setId
in interfaceUserProfile
- Parameters:
id
- aString
object
-
getTypedId
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:
getTypedId
in interfaceUserProfile
- Returns:
- a
String
object
-
getUsername
getUsername.
- Specified by:
getUsername
in interfaceUserProfile
- Returns:
- a
String
object
-
addAttribute
addAttribute.
Add an attribute. If existing attribute value is collection and the new value is collection - merge the collections- Specified by:
addAttribute
in interfaceUserProfile
- Parameters:
key
- aString
objectvalue
- aObject
object
-
addAuthenticationAttribute
addAuthenticationAttribute.
Add an authentication-related attribute- Specified by:
addAuthenticationAttribute
in interfaceUserProfile
- Parameters:
key
- aString
objectvalue
- aObject
object
-
addAttributes
Add attributes.- Parameters:
attributes
- use attributes
-
addAuthenticationAttributes
Add authentication attributes.- Parameters:
attributeMap
- the authentication attributes
-
removeAttribute
removeAttribute.
Remove an attribute by its key.- Specified by:
removeAttribute
in interfaceUserProfile
- Parameters:
key
- aString
object
-
removeAuthenticationAttribute
removeAuthenticationAttribute.
Remove an authentication attribute by its key- Specified by:
removeAuthenticationAttribute
in interfaceUserProfile
- Parameters:
key
- aString
object
-
getAttributes
getAttributes.
Get all attributes as immutable map.- Specified by:
getAttributes
in interfaceUserProfile
- Returns:
- a
Map
object
-
getAuthenticationAttributes
Get all authentication attributes as an immutable map- Returns:
- the immutable authentication attributes
-
getAttribute
getAttribute.
Return the attribute with name.- Specified by:
getAttribute
in interfaceUserProfile
- Parameters:
name
- aString
object- Returns:
- a
Object
object
-
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
containsAttribute.
Check to see if profile contains attribute name.- Specified by:
containsAttribute
in interfaceUserProfile
- Parameters:
name
- aString
object- Returns:
- a boolean
-
containsAuthenticationAttribute
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
addRole.
Add a role.- Specified by:
addRole
in interfaceUserProfile
- Parameters:
role
- aString
object
-
addRoles
addRoles.
Add roles.- Specified by:
addRoles
in interfaceUserProfile
- Parameters:
roles
- aCollection
object
-
getRoles
getRoles.
Get the roles of the user.- Specified by:
getRoles
in interfaceUserProfile
- Returns:
- a
Set
object
-
setRoles
Setter for the field
roles
.- Parameters:
roles
- aSet
object
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
removeLoginData
public void removeLoginData()Remove the specific data retrieved during the login process to only keep the user attributes and roles. -
isExpired
public boolean isExpired()isExpired.
- Specified by:
isExpired
in interfaceUserProfile
- Returns:
- a boolean
-
asPrincipal
asPrincipal.
- Specified by:
asPrincipal
in interfaceUserProfile
- Returns:
- a
Principal
object
-