Class DefaultAuthenticatedIdentity

java.lang.Object
cloud.piranha.core.impl.DefaultAuthenticatedIdentity
All Implemented Interfaces:
AuthenticatedIdentity, Principal

public class DefaultAuthenticatedIdentity extends Object implements AuthenticatedIdentity
Default implementation of AuthenticatedIdentity.

This implementation is an immutable structure, with a facility to store it in TLS. It's the responsibility of the context, e.g. the HTTP request handler, to remove the identity from TLS at the end of the context (e.g. end of the HTTP request), or at any other appropriate time (e.g. when logging out mid-request).

Author:
Arjan Tijms
  • Constructor Details

    • DefaultAuthenticatedIdentity

      public DefaultAuthenticatedIdentity(Principal callerPrincipal, Set<String> groups)
      Constructor.
      Parameters:
      callerPrincipal - the caller principal.
      groups - the groups.
  • Method Details

    • setCurrentIdentity

      public static void setCurrentIdentity(Principal callerPrincipal, Set<String> groups)
      Set the current identity.
      Parameters:
      callerPrincipal - the caller principal.
      groups - the groups.
    • setCurrentIdentity

      public static void setCurrentIdentity(AuthenticatedIdentity identity)
      Set the current identity.
      Parameters:
      identity - the identity.
    • getCurrentSubject

      public static Subject getCurrentSubject()
      Returns the current subject.
      Returns:
      the current subject
    • getCurrentIdentity

      public static AuthenticatedIdentity getCurrentIdentity()
      Returns the current identity.
      Returns:
      the current identity
    • clear

      public static void clear()
      Clear identity and subject.
    • getCallerPrincipal

      public Principal getCallerPrincipal()
      Description copied from interface: AuthenticatedIdentity
      Returns the caller principal, which represents the primary name of the calling entity (aka the "caller") to a server.
      Specified by:
      getCallerPrincipal in interface AuthenticatedIdentity
      Returns:
      the caller principal, or null if authentication has not (yet) completed successfully.
    • getGroups

      public Set<String> getGroups()
      Description copied from interface: AuthenticatedIdentity
      The groups the caller is in.

      If group to role mapping is not active (the default) groups are equal to roles.

      Specified by:
      getGroups in interface AuthenticatedIdentity
      Returns:
      the set of groups the caller is in, never null.