Package org.apache.shiro.subject
Class SimplePrincipalMap
-
- org.apache.shiro.subject.SimplePrincipalMap
-
- All Implemented Interfaces:
,
,
<,>
,PrincipalCollection
,PrincipalMap
public class SimplePrincipalMap extends implements PrincipalMap
Default implementation of thePrincipalMap
interface. *EXPERIMENTAL for Shiro 1.2 - DO NOT USE YET*- Since:
- 1.2
- Author:
- Les Hazlewood
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SimplePrincipalMap()
<,<,>> backingMap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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()
boolean
o)
boolean
o)
protected <,>
ensureCombinedPrincipals()
<<,>>
entrySet()
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.o)
getPrimaryPrincipal()
Returns the primary principal used application-wide to uniquely identify the owning account/Subject.<>
getRealmNames()
Returns the realm names that this collection has principals for.realmName, principalName)
<,>
name)
boolean
isEmpty()
Returnstrue
if this collection is empty,false
otherwise.iterator()
<>
keySet()
<T> T
<T> type)
Returns the first discovered principal assignable from the specified type, ornull
if there are none of the specified type.s, o)
void
<? extends ,?> map)
o)
realmName, principalName)
realmName, principalName, principal)
<,>
realmName, <,> principals)
int
size()
<>
values()
-
-
-
Method Detail
-
size
public int size()
- Specified by:
in interface
<,>
-
ensureCombinedPrincipals
protected <,> ensureCombinedPrincipals()
-
containsKey
public boolean containsKey( o)
- Specified by:
in interface
<,>
-
containsValue
public boolean containsValue( o)
- Specified by:
in interface
<,>
-
get
public get( o)
- Specified by:
in interface
<,>
-
put
public put( s, o)
- Specified by:
in interface
<,>
-
remove
public remove( o)
- Specified by:
in interface
<,>
-
putAll
public void putAll(<? extends ,?> map)
- Specified by:
in interface
<,>
-
keySet
public <> keySet()
- Specified by:
in interface
<,>
-
values
public <> values()
- Specified by:
in interface
<,>
-
entrySet
public <<,>> entrySet()
- Specified by:
in interface
<,>
-
clear
public void clear()
- Specified by:
in interface
<,>
-
getPrimaryPrincipal
public getPrimaryPrincipal()
Description copied from interface:PrincipalCollection
Returns the primary principal used application-wide to uniquely identify the owning account/Subject. The value is usually always a uniquely identifying attribute specific to the data source that retrieved the account data. Some examples:- a
- a
long
value such as a surrogate primary key in a relational database - an LDAP UUID or static DN
- a String username unique across all user accounts
Multi-Realm Applications
In a single-Realm
application, typically there is only ever one unique principal to retain and that is the value returned from this method. However, in a multi-Realm
application, where thePrincipalCollection
might retain principals across more than one realm, the value returned from this method should be the single principal that uniquely identifies the subject for the entire application. That value is of course application specific, but most applications will typically choose one of the primary principals from one of theRealm
s. Shiro's default implementations of this interface make this assumption by usually simply returning ., which just returns the first returned principal obtained from the first consulted/configuredRealm
during the authentication attempt. This means in a multi-Realm
application,Realm
configuration order matters if you want to retain this default heuristic. If this heuristic is not sufficient, most Shiro end-users will need to implement a customAuthenticationStrategy
. AnAuthenticationStrategy
has exact control over thePrincipalCollection
returned at the end of an authentication attempt via theAuthenticationStrategy#
implementation.afterAllAttempts
- Specified by:
getPrimaryPrincipal
in interfacePrincipalCollection
- Returns:
- the primary principal used to uniquely identify the owning account/Subject
-
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:
in interface
<,>
- Specified by:
isEmpty
in interfacePrincipalCollection
- Returns:
true
if this collection is empty,false
otherwise.
-
iterator
public iterator()
- Specified by:
in interface
-
getRealmPrincipals
public <,> getRealmPrincipals( name)
- Specified by:
getRealmPrincipals
in interfacePrincipalMap
-
setRealmPrincipals
public <,> setRealmPrincipals( realmName, <,> principals)
- Specified by:
setRealmPrincipals
in interfacePrincipalMap
-
setRealmPrincipal
public setRealmPrincipal( realmName, principalName, principal)
- Specified by:
setRealmPrincipal
in interfacePrincipalMap
-
getRealmPrincipal
public getRealmPrincipal( realmName, principalName)
- Specified by:
getRealmPrincipal
in interfacePrincipalMap
-
removeRealmPrincipal
public removeRealmPrincipal( realmName, principalName)
- Specified by:
removeRealmPrincipal
in interfacePrincipalMap
-
-