Class PrincipalExtended

java.lang.Object
de.fraunhofer.iosb.ilt.frostserver.util.user.PrincipalExtended
All Implemented Interfaces:
Principal

public class PrincipalExtended extends Object implements Principal
A user Principal with role information.
  • Field Details

  • Constructor Details

    • PrincipalExtended

      public PrincipalExtended(String name, boolean admin, Set<String> roles)
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface Principal
    • isAdmin

      public boolean isAdmin()
    • getRoles

      public Set<String> getRoles()
    • hasRole

      public boolean hasRole(String role)
    • toString

      public String toString()
      Specified by:
      toString in interface Principal
      Overrides:
      toString in class Object
    • getContext

      public Map<String,Object> getContext()
      Get the current context map.
      Returns:
      the current context map.
    • addContextItem

      public PrincipalExtended addContextItem(String key, Object value)
      Add an item to the context, or replace an existing item if an item with the given key already exists.
      Parameters:
      key - The key to store the item under.
      value - The value to associate with the given key.
      Returns:
      this.
    • hasContextItem

      public boolean hasContextItem(String key)
      Check if the context has an item for the given key.
      Parameters:
      key - the key to check.
      Returns:
      true if there is a context item for the given key, false otherwise.
    • getContextItem

      public Object getContextItem(String key, Object dflt)
      Get the context item with the given key, or dflt if there is no such item.
      Parameters:
      key - The key to get the item for.
      dflt - The value to return if there is no value for the given key.
      Returns:
      The value for the given key, or dflt if there is no such item.
    • getContextItem

      public Object getContextItem(String key)
      Get the context item with the given key, or null if there is no such item.
      Parameters:
      key - The key to get the item for.
      Returns:
      The value for the given key, or null if there is no such item.
    • setContext

      public PrincipalExtended setContext(Map<String,Object> context)
      Replace the current context with the given value.
      Parameters:
      context - The context map to replace the current context with.
      Returns:
      this
    • fromPrincipal

      public static final PrincipalExtended fromPrincipal(Principal principal)
      Turns the given principal into a PrincipalExtended. A null value will turn into an anonymous principal extended.
      Parameters:
      principal - the principal to check, or null.
      Returns:
      A principalExtended.
    • getLocalPrincipal

      public static PrincipalExtended getLocalPrincipal()
    • setLocalPrincipal

      public static void setLocalPrincipal(PrincipalExtended localPrincipal)
    • removeLocalPrincipal

      public static void removeLocalPrincipal()