java.lang.Object
one.jpro.platform.auth.core.authentication.User
All Implemented Interfaces:
Principal, Authentication

public class User extends Object implements 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).
  • Constructor Details

    • User

      public User(@NotNull @NotNull String name)
      Create a user holding a name.
      Parameters:
      name - the user's name
    • User

      public User(@NotNull @NotNull String name, @Nullable @Nullable Set<String> roles)
      Create a user holding a name and roles.
      Parameters:
      name - the user's name
      roles - the user's roles
    • User

      public User(@NotNull @NotNull String name, @Nullable @Nullable Map<String,Object> attributes)
      Create a user holding a name and attributes.
      Parameters:
      name - the user's name
      attributes - 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 name
      roles - the user's roles
      attributes - 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

      @NotNull public @NotNull String getName()
      Specified by:
      getName in interface Principal
    • getRoles

      @NotNull public @NotNull @Unmodifiable Set<String> getRoles()
      Description copied from interface: Authentication
      Any roles associated with the authentication.
      Specified by:
      getRoles in interface Authentication
      Returns:
      a Collection of roles as string
    • getAttributes

      @NotNull public @NotNull @Unmodifiable Map<String,Object> getAttributes()
      Description copied from interface: Authentication
      Any additional attributes in the authentication.
      Specified by:
      getAttributes in interface Authentication
      Returns:
      a Map containing the attributes;
    • hasRole

      public boolean hasRole(String role)
      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

      public boolean hasAttribute(String key)
      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

      public User merge(User other)
      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

      public Optional<String> getAttribute(String key)
      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

      public String getEmail()
      Retrieve the user's email from the user's attributes.
      Returns:
      the email as a string