java.lang.Object
one.jpro.platform.auth.core.authentication.User
- All Implemented Interfaces:
Principal,Authentication
An implementation of the
Authentication interface to
be used on the client side to create authentication objects
from user data. The term client does not imply any particular
implementation characteristics (e.g., whether the application
executes on a server, a desktop, or other devices).-
Field Summary
Fields inherited from interface one.jpro.platform.auth.core.authentication.Authentication
KEY_ATTRIBUTES, KEY_NAME, KEY_ROLES -
Constructor Summary
ConstructorsConstructorDescriptionCreate a user holding a name.Create a user holding a name and attributes.Create a user holding a name and roles.Create a user holding a name, roles and attributes.User(@NotNull org.json.JSONObject json) Create a user from a JSON object. -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String key) Retrieves the value of a specific attribute.Any additional attributes in the authentication.getEmail()Retrieve the user's email from the user's attributes.@NotNull StringgetName()getRoles()Any roles associated with the authentication.booleanhasAttribute(String key) Checks if the user has a specific attribute.booleanChecks if the user has a specific role.Merges this user with another user, combining their roles and attributes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface one.jpro.platform.auth.core.authentication.Authentication
toJSON
-
Constructor Details
-
User
Create a user holding a name.- Parameters:
name- the user's name
-
User
Create a user holding a name and roles.- Parameters:
name- the user's nameroles- the user's roles
-
User
Create a user holding a name and attributes.- Parameters:
name- the user's nameattributes- the user's attributes
-
User
public User(@NotNull @NotNull String name, @Nullable @Nullable Set<String> roles, @Nullable @Nullable Map<String, Object> attributes) Create a user holding a name, roles and attributes.- Parameters:
name- the user's nameroles- the user's rolesattributes- the user's attributes
-
User
public User(@NotNull @NotNull org.json.JSONObject json) Create a user from a JSON object.- Parameters:
json- the JSON object
-
-
Method Details
-
getName
-
getRoles
Description copied from interface:AuthenticationAny roles associated with the authentication.- Specified by:
getRolesin interfaceAuthentication- Returns:
- a
Collectionof roles as string
-
getAttributes
Description copied from interface:AuthenticationAny additional attributes in the authentication.- Specified by:
getAttributesin interfaceAuthentication- Returns:
- a
Mapcontaining the attributes;
-
hasRole
Checks if the user has a specific role.- Parameters:
role- the role to check.- Returns:
- true if the user has the specified role, false otherwise.
-
hasAttribute
Checks if the user has a specific attribute.- Parameters:
key- the key of the attribute to check- Returns:
- true if the user has the specified attribute, false otherwise
-
merge
Merges this user with another user, combining their roles and attributes. The name of this user is retained.- Parameters:
other- the other user to merge with.- Returns:
- a new User instance combining the information of both users.
-
getAttribute
Retrieves the value of a specific attribute.- Parameters:
key- the key of the attribute to retrieve- Returns:
- the value of the attribute as a String, or null if the attribute does not exist
-
getEmail
Retrieve the user's email from the user's attributes.- Returns:
- the email as a string
-