Package io.helidon.security
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSubject.BuilderA fluent API builder forSubject.-
Nested classes/interfaces inherited from interface io.helidon.security.util.AbacSupport
AbacSupport.BasicAttributes
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<String>abacAttributeNames()A collection of all property names in this container.ObjectabacAttributeRaw(String key)Return the actual property value or null if not present.static Subject.Builderbuilder()Creates a fluent API builder to build new instances of this class.Subjectcombine(Subject another)Will add all principals and credentials from another subject to this subject, will not replaceprincipals().static Subjectcreate(Principal principal)Create a new subject for a principal.<T extends Grant>
List<T>grants(Class<T> grantType)Get all grants of a specific type determined by type's class.List<Grant>grantsByType(String grantType)Get all grants of a specific type determined by type's name.Principalprincipal()Get the principal this subject is created for (e.g.List<Principal>principals()Get all principals of this subject (including the one returned byprincipal()).<T> Optional<T>privateCredential(Class<T> credential)Get private credential for the specified type.<T> Optional<T>publicCredential(Class<T> credential)Get public credential for the specified type.SubjecttoJavaSubject()Create a javaSubjectfrom this subject.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.helidon.security.util.AbacSupport
abacAttribute
-
-
-
-
Method Detail
-
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, additionalPrincipals), please use fluent APIbuilder().- 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 byprincipal()).- 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:AbacSupportReturn the actual property value or null if not present. This is the only method that needs to be implemented.- Specified by:
abacAttributeRawin interfaceAbacSupport- Parameters:
key- key (name) of the property- Returns:
- value of the property or null
-
abacAttributeNames
public Collection<String> abacAttributeNames()
Description copied from interface:AbacSupportA collection of all property names in this container.- Specified by:
abacAttributeNamesin interfaceAbacSupport- 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 javaSubjectfrom 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 replaceprincipals().- 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
-
-