Class CompositePrincipal
- java.lang.Object
-
- org.wildfly.security.auth.principal.CompositePrincipal
-
- All Implemented Interfaces:
Serializable
,Iterable<Principal>
,Principal
public final class CompositePrincipal extends Object implements Principal, Serializable, Iterable<Principal>
A composite principal that consists of multiple elements of possibly disparate type. This may be used to locate a unique principal in a realm which is backed by a database that uses a composite key; in this case, the constituent principals may be names or numbers, or a combination of both.- Author:
- David M. Lloyd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CompositePrincipal(Principal... principals)
Construct a new instance.CompositePrincipal(Collection<Principal> principals)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(Class<? extends Principal> type)
Determine whether this composite principal contains the a nested principal of the given type class.boolean
contains(Principal principal)
Determine whether this composite principal contains the given nested principal.boolean
equals(Object obj)
Determine whether this principal is equal to the given object.boolean
equals(CompositePrincipal obj)
Determine whether this principal is equal to the given object.Principal
get(int idx)
Get the principal at the given index.<P extends Principal>
Pget(int idx, Class<P> type)
Get the principal at the given index, if it is of the given type.<P extends Principal>
Pget(Class<P> type)
Get the first principal with the given type, if any.String
getName()
Get the principal name.int
hashCode()
Get the hash code of this principal.Iterator<Principal>
iterator()
Get an iterator over this principal.int
size()
Get the number of nested principals.String
toString()
Get this principal as a string.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
CompositePrincipal
public CompositePrincipal(Collection<Principal> principals)
Construct a new instance.- Parameters:
principals
- the collection of principals to use (must not benull
)
-
CompositePrincipal
public CompositePrincipal(Principal... principals)
Construct a new instance.- Parameters:
principals
- the principals to use (must not benull
)
-
-
Method Detail
-
getName
public String getName()
Get the principal name.
-
contains
public boolean contains(Principal principal)
Determine whether this composite principal contains the given nested principal.- Parameters:
principal
- the nested principal (must not benull
)- Returns:
true
if this principal contains the nested principal,false
otherwise
-
contains
public boolean contains(Class<? extends Principal> type)
Determine whether this composite principal contains the a nested principal of the given type class.- Parameters:
type
- the nested principal type class (must not benull
)- Returns:
true
if this principal contains a nested principal of the given type,false
otherwise
-
size
public int size()
Get the number of nested principals.- Returns:
- the number of nested principals
-
get
public Principal get(int idx)
Get the principal at the given index.- Parameters:
idx
- the index- Returns:
- the principal at the given index (not
null
) - Throws:
IndexOutOfBoundsException
- if the given index is less than zero or greater than or equal tosize()
-
get
public <P extends Principal> P get(int idx, Class<P> type)
Get the principal at the given index, if it is of the given type.- Type Parameters:
P
- the principal type- Parameters:
idx
- the indextype
- the principal type class (must not benull
)- Returns:
- the principal at the given index or
null
if that principal is not of the given type - Throws:
IndexOutOfBoundsException
- if the given index is less than zero or greater than or equal tosize()
-
get
public <P extends Principal> P get(Class<P> type)
Get the first principal with the given type, if any.- Type Parameters:
P
- the principal type- Parameters:
type
- the principal type class (must not benull
)- Returns:
- the first principal with the given type, or
null
if none was found - Throws:
IndexOutOfBoundsException
- if the given index is less than zero or greater than or equal tosize()
-
equals
public boolean equals(Object obj)
Determine whether this principal is equal to the given object.
-
equals
public boolean equals(CompositePrincipal obj)
Determine whether this principal is equal to the given object.- Parameters:
obj
- the object- Returns:
true
if they are equal,false
otherwise
-
hashCode
public int hashCode()
Get the hash code of this principal.
-
-