Class SimplePrincipalCollection
java.lang.Object
org.apache.shiro.subject.SimplePrincipalCollection
- All Implemented Interfaces:
Serializable,Iterable,MutablePrincipalCollection,PrincipalCollection
A simple implementation of the
MutablePrincipalCollection interface that tracks principals internally
by storing them in a LinkedHashMap.- Since:
- 0.9
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSimplePrincipalCollection(Object principal, String realmName) SimplePrincipalCollection(Collection principals, String realmName) SimplePrincipalCollection(PrincipalCollection principals) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given principal to this collection.voidaddAll(Collection principals, String realmName) Adds all of the principals in the given collection to this collection.voidaddAll(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> Collection<T> Returns all principals assignable from the specified type, or an empty Collection if no principals of that type are contained.voidclear()Removes all Principals in this collection.booleanReturns 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.Returns the first available principal from any of theRealmprincipals, ornullif there are no principals yet.protected CollectiongetPrincipalsLazy(String realmName) Returns the realm names that this collection has principals for.inthashCode()booleanisEmpty()Returnstrueif this collection is empty,falseotherwise.iterator()<T> TReturns the first discovered principal assignable from the specified type, ornullif there are none of the specified type.toString()Returns a simple string representation suitable for printing.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SimplePrincipalCollection
public SimplePrincipalCollection() -
SimplePrincipalCollection
-
SimplePrincipalCollection
-
SimplePrincipalCollection
-
-
Method Details
-
getPrincipalsLazy
-
getPrimaryPrincipal
Returns the first available principal from any of theRealmprincipals, ornullif there are no principals yet. The 'first available principal' is interpreted as the principal that would be returned byiterator().next().- Specified by:
getPrimaryPrincipalin interfacePrincipalCollection- Returns:
- the primary principal used to uniquely identify the owning account/Subject
-
add
Description copied from interface:MutablePrincipalCollectionAdds the given principal to this collection.- Specified by:
addin interfaceMutablePrincipalCollection- Parameters:
principal- the principal to be added.realmName- the realm this principal came from.
-
addAll
Description copied from interface:MutablePrincipalCollectionAdds all of the principals in the given collection to this collection.- Specified by:
addAllin interfaceMutablePrincipalCollection- Parameters:
principals- the principals to be added.realmName- the realm these principals came from.
-
addAll
Description copied from interface:MutablePrincipalCollectionAdds all of the principals from the given principal collection to this collection.- Specified by:
addAllin interfaceMutablePrincipalCollection- Parameters:
principals- the principals to add.
-
oneByType
Description copied from interface:PrincipalCollectionReturns the first discovered principal assignable from the specified type, ornullif there are none of the specified type. Note that this will returnnullif the 'owning' subject has not yet logged in.- Specified by:
oneByTypein interfacePrincipalCollection- Parameters:
type- the type of the principal that should be returned.- Returns:
- a principal of the specified type or
nullif there isn't one of the specified type.
-
byType
Description copied from interface:PrincipalCollectionReturns 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:
byTypein 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
Description copied from interface:PrincipalCollectionReturns 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:
asListin interfacePrincipalCollection- Returns:
- a single Subject's principals retrieved from all configured Realms as a List.
-
asSet
Description copied from interface:PrincipalCollectionReturns 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:
asSetin interfacePrincipalCollection- Returns:
- a single Subject's principals retrieved from all configured Realms as a Set.
-
fromRealm
Description copied from interface:PrincipalCollectionReturns 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:
fromRealmin 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
Description copied from interface:PrincipalCollectionReturns the realm names that this collection has principals for.- Specified by:
getRealmNamesin interfacePrincipalCollection- Returns:
- the names of realms that this collection has one or more principals for.
-
isEmpty
Description copied from interface:PrincipalCollectionReturnstrueif this collection is empty,falseotherwise.- Specified by:
isEmptyin interfacePrincipalCollection- Returns:
trueif this collection is empty,falseotherwise.
-
clear
Description copied from interface:MutablePrincipalCollectionRemoves all Principals in this collection.- Specified by:
clearin interfaceMutablePrincipalCollection
-
iterator
-
equals
-
hashCode
-
toString
-