Class DefaultEnvironment
java.lang.Object
org.apache.shiro.env.DefaultEnvironment
- All Implemented Interfaces:
Environment,NamedObjectEnvironment,org.apache.shiro.lang.util.Destroyable
- Direct Known Subclasses:
BasicIniEnvironment
public class DefaultEnvironment
extends Object
implements NamedObjectEnvironment, org.apache.shiro.lang.util.Destroyable
Simple/default
Environment implementation that stores Shiro objects as key-value pairs in a
Map instance. The key is the object name, the value is the object itself.- Since:
- 1.2
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with a thread-safeConcurrentHashMapbacking map.DefaultEnvironment(Map<String, ?> seed) Creates a new instance with the specified backing map. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()<T> TReturns the object in Shiro's environment with the specified name and type ornullif no object with that name was found.Returns the live (modifiable) internal objects collection.Returns the application'sSecurityManagerinstance accessible in the backing map using thesecurityManagerNameproperty as the lookup key.Returns the name of theSecurityManagerinstance in the backing map.protected SecurityManagerLooks up theSecurityManagerinstance in the backing map without performing any non-null guarantees.voidvoidsetSecurityManager(SecurityManager securityManager) voidsetSecurityManagerName(String securityManagerName) Sets the name of theSecurityManagerinstance in the backing map.
-
Field Details
-
DEFAULT_SECURITY_MANAGER_KEY
The default name under which the application'sSecurityManagerinstance may be acquired, equal tosecurityManager.- See Also:
-
objects
-
-
Constructor Details
-
DefaultEnvironment
public DefaultEnvironment()Creates a new instance with a thread-safeConcurrentHashMapbacking map. -
DefaultEnvironment
Creates a new instance with the specified backing map.- Parameters:
seed- backing map to use to maintain Shiro objects.
-
-
Method Details
-
getSecurityManager
Returns the application'sSecurityManagerinstance accessible in the backing map using thesecurityManagerNameproperty as the lookup key. This implementation guarantees that a non-null instance is always returned, as this is expected for Environment API end-users. If subclasses have the need to perform the map lookup without this guarantee (for example, during initialization when the instance may not have been added to the map yet), thelookupSecurityManager()method is provided as an alternative.- Specified by:
getSecurityManagerin interfaceEnvironment- Returns:
- the application's
SecurityManagerinstance accessible in the backing map using thesecurityManagerNameproperty as the lookup key. - Throws:
IllegalStateException
-
setSecurityManager
-
lookupSecurityManager
Looks up theSecurityManagerinstance in the backing map without performing any non-null guarantees.- Returns:
- the
SecurityManagerin the backing map, ornullif it has not yet been populated.
-
getSecurityManagerName
Returns the name of theSecurityManagerinstance in the backing map. Used as a key to lookup the instance. Unless set otherwise, the default issecurityManager.- Returns:
- the name of the
SecurityManagerinstance in the backing map. Used as a key to lookup the instance.
-
setSecurityManagerName
Sets the name of theSecurityManagerinstance in the backing map. Used as a key to lookup the instance. Unless set otherwise, the default issecurityManager.- Parameters:
securityManagerName- the name of theSecurityManagerinstance in the backing map. Used as a key to lookup the instance.
-
getObjects
Returns the live (modifiable) internal objects collection.- Returns:
- the live (modifiable) internal objects collection.
-
getObject
Description copied from interface:NamedObjectEnvironmentReturns the object in Shiro's environment with the specified name and type ornullif no object with that name was found.- Specified by:
getObjectin interfaceNamedObjectEnvironment- Type Parameters:
T- the type of the class- Parameters:
name- the assigned name of the object.requiredType- the class to which the discovered object must be assignable.- Returns:
- the object in Shiro's environment with the specified name (of the specified type) or
nullif no object with that name was found. - Throws:
RequiredTypeException- if the discovered object does not equal, extend, or implement the specified class.
-
setObject
-
destroy
-