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
public class BasicUserProfile extends Object implements UserProfile, Externalizable
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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BasicUserProfile()
BasicUserProfile(boolean canAttributesBeMerged)
Create a profile with possibility to merge attributes with the same name and collection-type values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(String key, Object value)
Add an attribute.void
addAttributes(Map<String,Object> attributes)
Add attributes.void
addAuthenticationAttribute(String key, Object value)
Add an authentication-related attributevoid
addAuthenticationAttributes(Map<String,Object> attributeMap)
Add authentication attributes.void
addPermission(String permission)
Add a permission.void
addPermissions(Collection<String> permissions)
Add permissions.void
addRole(String role)
Add a role.void
addRoles(Collection<String> roles)
Add roles.void
build(Object id, Map<String,Object> attributes)
Build a profile from user identifier and attributes.void
build(Object id, Map<String,Object> attributes, Map<String,Object> authenticationAttributes)
Build a profile from user identifier, attributes, and authentication attributes.void
clearSensitiveData()
boolean
containsAttribute(String name)
Check to see if profile contains attribute name.boolean
containsAuthenicationAttribute(String name)
Check to see if profile contains attribute name.Object
getAttribute(String name)
Return the attribute with name.<T> T
getAttribute(String name, Class<T> clazz)
Return the attribute with name.Map<String,Object>
getAttributes()
Get all attributes as immutable map.Object
getAuthenticationAttribute(String name)
Return the authentication attribute with name.<T> T
getAuthenticationAttribute(String name, Class<T> clazz)
Return authentication attribute with nameMap<String,Object>
getAuthenticationAttributes()
Get all authentication attributes as an immutable mapString
getClientName()
String
getId()
Get the user identifier.String
getLinkedId()
Set<String>
getPermissions()
Get the permissions of the user.Set<String>
getRoles()
Get the roles of the user.String
getTypedId()
Get the user identifier with a prefix which is the profile type (full class name with package).boolean
isRemembered()
Is the user remembered?void
readExternal(ObjectInput in)
void
removeAttribute(String key)
Remove an attribute by its key.void
removeAuthenticationAttribute(String key)
Remove an authentication attribute by its keyvoid
setClientName(String clientName)
void
setId(String id)
Set the identifier.void
setLinkedId(String linkedId)
void
setPermissions(Set<String> permissions)
void
setRemembered(boolean rme)
Define if this profile is remembered.void
setRoles(Set<String> roles)
String
toString()
void
writeExternal(ObjectOutput out)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.pac4j.core.profile.UserProfile
asPrincipal, getUsername, isExpired
-
-
-
-
Field Detail
-
logger
protected final transient org.slf4j.Logger logger
-
SEPARATOR
public static final transient String SEPARATOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
build
public void build(Object id, Map<String,Object> attributes)
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
public void setId(String id)
Set the identifier.- Parameters:
id
- user identifier
-
getId
public String getId()
Get the user identifier. This identifier is unique for this provider but not necessarily through all providers.- Specified by:
getId
in interfaceUserProfile
- Returns:
- the user identifier
-
getTypedId
public String 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.- Returns:
- the typed user identifier
-
addAttribute
public void addAttribute(String key, Object value)
Add an attribute. If existing attribute value is collection and the new value is collection - merge the collections- Parameters:
key
- key of the attributevalue
- value of the attribute
-
addAuthenticationAttribute
public void addAuthenticationAttribute(String key, Object value)
Add an authentication-related attribute- Parameters:
key
- the attribute keyvalue
- the attribute value
-
addAttributes
public void addAttributes(Map<String,Object> attributes)
Add attributes.- Parameters:
attributes
- use attributes
-
addAuthenticationAttributes
public void addAuthenticationAttributes(Map<String,Object> attributeMap)
Add authentication attributes.- Parameters:
attributeMap
- the authentication attributes
-
removeAttribute
public void removeAttribute(String key)
Remove an attribute by its key.- Parameters:
key
- the key
-
removeAuthenticationAttribute
public void removeAuthenticationAttribute(String key)
Remove an authentication attribute by its key- Parameters:
key
- the key
-
getAttributes
public Map<String,Object> getAttributes()
Get all attributes as immutable map.- Returns:
- the immutable attributes
-
getAuthenticationAttributes
public Map<String,Object> getAuthenticationAttributes()
Get all authentication attributes as an immutable map- Returns:
- the immutable authentication attributes
-
getAttribute
public Object getAttribute(String name)
Return the attribute with name.- Specified by:
getAttribute
in interfaceUserProfile
- Parameters:
name
- attribute name- Returns:
- the attribute with name
-
getAuthenticationAttribute
public Object getAuthenticationAttribute(String name)
Return the authentication attribute with name.- Parameters:
name
- authentication attribute name- Returns:
- the authentication attribute with name
-
containsAttribute
public boolean containsAttribute(String name)
Check to see if profile contains attribute name.- Specified by:
containsAttribute
in interfaceUserProfile
- Parameters:
name
- the name- Returns:
- true/false
-
containsAuthenicationAttribute
public boolean containsAuthenicationAttribute(String name)
Check to see if profile contains attribute name.- Parameters:
name
- the name- Returns:
- true/false
-
getAttribute
public <T> T getAttribute(String name, Class<T> clazz)
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
public <T> T getAuthenticationAttribute(String name, Class<T> clazz)
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
public void addRole(String role)
Add a role.- Specified by:
addRole
in interfaceUserProfile
- Parameters:
role
- the role to add.
-
addRoles
public void addRoles(Collection<String> roles)
Add roles.- Specified by:
addRoles
in interfaceUserProfile
- Parameters:
roles
- the roles to add.
-
getRoles
public Set<String> getRoles()
Get the roles of the user.- Specified by:
getRoles
in interfaceUserProfile
- Returns:
- the user roles.
-
addPermission
public void addPermission(String permission)
Add a permission.- Specified by:
addPermission
in interfaceUserProfile
- Parameters:
permission
- the permission to add.
-
addPermissions
public void addPermissions(Collection<String> permissions)
Add permissions.- Specified by:
addPermissions
in interfaceUserProfile
- Parameters:
permissions
- the permissions to add.
-
getPermissions
public Set<String> getPermissions()
Get the permissions of the user.- Specified by:
getPermissions
in interfaceUserProfile
- Returns:
- the user permissions.
-
setRemembered
public void setRemembered(boolean rme)
Define if this profile is remembered.- Specified by:
setRemembered
in interfaceUserProfile
- Parameters:
rme
- whether the user is remembered.
-
isRemembered
public boolean isRemembered()
Is the user remembered?- Specified by:
isRemembered
in interfaceUserProfile
- Returns:
- whether the user is remembered.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
clearSensitiveData
public void clearSensitiveData()
-
getClientName
public String getClientName()
- Specified by:
getClientName
in interfaceUserProfile
-
setClientName
public void setClientName(String clientName)
- Specified by:
setClientName
in interfaceUserProfile
-
getLinkedId
public String getLinkedId()
-
setLinkedId
public void setLinkedId(String linkedId)
-
-