Package org.apache.shiro.subject
Class SimplePrincipalCollection
-
- org.apache.shiro.subject.SimplePrincipalCollection
-
- All Implemented Interfaces:
,
,
MutablePrincipalCollection
,PrincipalCollection
public class SimplePrincipalCollection extends implements MutablePrincipalCollection
A simple implementation of theMutablePrincipalCollection
interface that tracks principals internally by storing them in a .- Since:
- 0.9
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SimplePrincipalCollection()
principal, realmName)
principals, realmName)
SimplePrincipalCollection(PrincipalCollection principals)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
principal, realmName)
Adds the given principal to this collection.void
principals, realmName)
Adds all of the principals in the given collection to this collection.void
addAll(PrincipalCollection principals)
Adds all of the principals from the given principal collection to this collection.asList()
Returns a single Subject's principals retrieved from all configured Realms as a List, or an empty List if there are not any principals.asSet()
Returns a single Subject's principals retrieved from all configured Realms as a Set, or an empty Set if there are not any principals.<T> <T>
<T> type)
Returns all principals assignable from the specified type, or an empty Collection if no principals of that type are contained.void
clear()
Removes all Principals in this collection.boolean
o)
realmName)
Returns a single Subject's principals retrieved from the specified Realm only as a Collection, or an empty Collection if there are not any principals from that realm.getPrimaryPrincipal()
Returns the first available principal from any of theRealm
principals, ornull
if there are no principals yet.protected
realmName)
<>
getRealmNames()
Returns the realm names that this collection has principals for.int
hashCode()
boolean
isEmpty()
Returnstrue
if this collection is empty,false
otherwise.iterator()
<T> T
<T> type)
Returns the first discovered principal assignable from the specified type, ornull
if there are none of the specified type.toString()
Returns a simple string representation suitable for printing.
-
-
-
Constructor Detail
-
SimplePrincipalCollection
public SimplePrincipalCollection()
-
SimplePrincipalCollection
public SimplePrincipalCollection( principal, realmName)
-
SimplePrincipalCollection
public SimplePrincipalCollection( principals, realmName)
-
SimplePrincipalCollection
public SimplePrincipalCollection(PrincipalCollection principals)
-
-
Method Detail
-
getPrincipalsLazy
protected getPrincipalsLazy( realmName)
-
getPrimaryPrincipal
public getPrimaryPrincipal()
Returns the first available principal from any of theRealm
principals, ornull
if there are no principals yet. The 'first available principal' is interpreted as the principal that would be returned by.
- Specified by:
getPrimaryPrincipal
in interfacePrincipalCollection
- Returns:
- the primary principal used to uniquely identify the owning account/Subject
-
add
public void add( principal, realmName)
Description copied from interface:MutablePrincipalCollection
Adds the given principal to this collection.- Specified by:
add
in interfaceMutablePrincipalCollection
- Parameters:
principal
- the principal to be added.realmName
- the realm this principal came from.
-
addAll
public void addAll( principals, realmName)
Description copied from interface:MutablePrincipalCollection
Adds all of the principals in the given collection to this collection.- Specified by:
addAll
in interfaceMutablePrincipalCollection
- Parameters:
principals
- the principals to be added.realmName
- the realm these principals came from.
-
addAll
public void addAll(PrincipalCollection principals)
Description copied from interface:MutablePrincipalCollection
Adds all of the principals from the given principal collection to this collection.- Specified by:
addAll
in interfaceMutablePrincipalCollection
- Parameters:
principals
- the principals to add.
-
oneByType
public <T> T oneByType(<T> type)
Description copied from interface:PrincipalCollection
Returns the first discovered principal assignable from the specified type, ornull
if there are none of the specified type. Note that this will returnnull
if the 'owning' subject has not yet logged in.- Specified by:
oneByType
in interfacePrincipalCollection
- Parameters:
type
- the type of the principal that should be returned.- Returns:
- a principal of the specified type or
null
if there isn't one of the specified type.
-
byType
public <T> <T> byType(<T> type)
Description copied from interface:PrincipalCollection
Returns all principals assignable from the specified type, or an empty Collection if no principals of that type are contained. Note that this will return an empty Collection if the 'owning' subject has not yet logged in.- Specified by:
byType
in interfacePrincipalCollection
- Parameters:
type
- the type of the principals that should be returned.- Returns:
- a Collection of principals that are assignable from the specified type, or an empty Collection if no principals of this type are associated.
-
asList
public asList()
Description copied from interface:PrincipalCollection
Returns a single Subject's principals retrieved from all configured Realms as a List, or an empty List if there are not any principals. Note that this will return an empty List if the 'owning' subject has not yet logged in.- Specified by:
asList
in interfacePrincipalCollection
- Returns:
- a single Subject's principals retrieved from all configured Realms as a List.
-
asSet
public asSet()
Description copied from interface:PrincipalCollection
Returns a single Subject's principals retrieved from all configured Realms as a Set, or an empty Set if there are not any principals. Note that this will return an empty Set if the 'owning' subject has not yet logged in.- Specified by:
asSet
in interfacePrincipalCollection
- Returns:
- a single Subject's principals retrieved from all configured Realms as a Set.
-
fromRealm
public fromRealm( realmName)
Description copied from interface:PrincipalCollection
Returns a single Subject's principals retrieved from the specified Realm only as a Collection, or an empty Collection if there are not any principals from that realm. Note that this will return an empty Collection if the 'owning' subject has not yet logged in.- Specified by:
fromRealm
in interfacePrincipalCollection
- Parameters:
realmName
- the name of the Realm from which the principals were retrieved.- Returns:
- the Subject's principals from the specified Realm only as a Collection or an empty Collection if there are not any principals from that realm.
-
getRealmNames
public <> getRealmNames()
Description copied from interface:PrincipalCollection
Returns the realm names that this collection has principals for.- Specified by:
getRealmNames
in interfacePrincipalCollection
- Returns:
- the names of realms that this collection has one or more principals for.
-
isEmpty
public boolean isEmpty()
Description copied from interface:PrincipalCollection
Returnstrue
if this collection is empty,false
otherwise.- Specified by:
isEmpty
in interfacePrincipalCollection
- Returns:
true
if this collection is empty,false
otherwise.
-
clear
public void clear()
Description copied from interface:MutablePrincipalCollection
Removes all Principals in this collection.- Specified by:
clear
in interfaceMutablePrincipalCollection
-
iterator
public iterator()
- Specified by:
in interface
-
equals
public boolean equals( o)
- Overrides:
in class
-
hashCode
public int hashCode()
- Overrides:
in class
-
toString
public toString()
Returns a simple string representation suitable for printing.- Overrides:
in class
- Returns:
- a simple string representation suitable for printing.
- Since:
- 1.0
-
-