Class Subject

java.lang.Object
io.helidon.security.Subject
All Implemented Interfaces:
AbacSupport

public final class Subject extends Object implements AbacSupport
A security subject, representing a user or a service.
  • Method Details

    • builder

      public static Subject.Builder builder()
      Creates a fluent API builder to build new instances of this class.
      Returns:
      a new builder instance
    • create

      public static Subject create(Principal principal)
      Create a new subject for a principal. If you want to configure additional details (Grants, public and/or private credentials, additional Principals), please use fluent API builder().
      Parameters:
      principal - principal this subject represents
      Returns:
      a new subject instance with the single principal
    • principal

      public Principal principal()
      Get the principal this subject is created for (e.g. the "main" principal of this subject).
      Returns:
      principal
    • principals

      public List<Principal> principals()
      Get all principals of this subject (including the one returned by principal()).
      Returns:
      all principals of this subject
    • grants

      public <T extends Grant> List<T> grants(Class<T> grantType)
      Get all grants of a specific type determined by type's class.
      Type Parameters:
      T - type of the grant's type (e.g. Role
      Parameters:
      grantType - type of grant (e.g. Role.class)
      Returns:
      list of grants of the specific type associated with this subject (may be empty)
    • grantsByType

      public List<Grant> grantsByType(String grantType)
      Get all grants of a specific type determined by type's name.
      Parameters:
      grantType - type of grant (e.g. "role" or "scope")
      Returns:
      list of grants of the specific type associated with this subject (may be empty)
    • abacAttributeRaw

      public Object abacAttributeRaw(String key)
      Description copied from interface: AbacSupport
      Return the actual property value or null if not present. This is the only method that needs to be implemented.
      Specified by:
      abacAttributeRaw in interface AbacSupport
      Parameters:
      key - key (name) of the property
      Returns:
      value of the property or null
    • abacAttributeNames

      public Collection<String> abacAttributeNames()
      Description copied from interface: AbacSupport
      A collection of all property names in this container.
      Specified by:
      abacAttributeNames in interface AbacSupport
      Returns:
      collection of keys
    • publicCredential

      public <T> Optional<T> publicCredential(Class<T> credential)
      Get public credential for the specified type.
      Type Parameters:
      T - credential type
      Parameters:
      credential - credential type's class
      Returns:
      optional of public credential of the type defined
    • privateCredential

      public <T> Optional<T> privateCredential(Class<T> credential)
      Get private credential for the specified type.
      Type Parameters:
      T - credential type
      Parameters:
      credential - credential type's class
      Returns:
      optional of private credential of the type defined
    • toJavaSubject

      public Subject toJavaSubject()
      Create a java Subject from this subject.
      Returns:
      an instance of Subject
    • combine

      public Subject combine(Subject another)
      Will add all principals and credentials from another subject to this subject, will not replace principals().
      Parameters:
      another - the other subject to combine with this subject
      Returns:
      a new subject that is a combination of this subject and the other subject, this subject is more significant
    • toString

      public String toString()
      Overrides:
      toString in class Object