public class DefaultEnvironment extends Object implements NamedObjectEnvironment, Destroyable
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.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_SECURITY_MANAGER_KEY
The default name under which the application's
SecurityManager instance may be acquired, equal to
securityManager . |
protected Map<String,Object> |
objects |
Constructor and Description |
---|
DefaultEnvironment()
Creates a new instance with a thread-safe
ConcurrentHashMap backing map. |
DefaultEnvironment(Map<String,?> seed)
Creates a new instance with the specified backing map.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Called when this object is being destroyed, allowing any necessary cleanup of internal resources.
|
<T> T |
getObject(String name,
Class<T> requiredType)
Returns the object in Shiro's environment with the specified name and type or
null if
no object with that name was found. |
Map<String,Object> |
getObjects()
Returns the live (modifiable) internal objects collection.
|
SecurityManager |
getSecurityManager()
Returns the application's
SecurityManager instance accessible in the backing map using the
securityManagerName property as the lookup key. |
String |
getSecurityManagerName()
Returns the name of the
SecurityManager instance in the backing map. |
protected SecurityManager |
lookupSecurityManager()
Looks up the
SecurityManager instance in the backing map without performing any non-null guarantees. |
void |
setObject(String name,
Object instance) |
void |
setSecurityManager(SecurityManager securityManager) |
void |
setSecurityManagerName(String securityManagerName)
Sets the name of the
SecurityManager instance in the backing map. |
public static final String DEFAULT_SECURITY_MANAGER_KEY
SecurityManager
instance may be acquired, equal to
securityManager
.public DefaultEnvironment()
ConcurrentHashMap
backing map.public DefaultEnvironment(Map<String,?> seed)
seed
- backing map to use to maintain Shiro objects.public SecurityManager getSecurityManager() throws IllegalStateException
SecurityManager
instance accessible in the backing map using the
securityManagerName
property 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), the
lookupSecurityManager()
method is provided as an alternative.getSecurityManager
in interface Environment
SecurityManager
instance accessible in the backing map using the
securityManagerName
property as the lookup key.IllegalStateException
public void setSecurityManager(SecurityManager securityManager)
protected SecurityManager lookupSecurityManager()
SecurityManager
instance in the backing map without performing any non-null guarantees.SecurityManager
in the backing map, or null
if it has not yet been populated.public String getSecurityManagerName()
SecurityManager
instance in the backing map. Used as a key to lookup the
instance. Unless set otherwise, the default is securityManager
.SecurityManager
instance in the backing map. Used as a key to lookup the
instance.public void setSecurityManagerName(String securityManagerName)
SecurityManager
instance in the backing map. Used as a key to lookup the
instance. Unless set otherwise, the default is securityManager
.securityManagerName
- the name of the SecurityManager
instance in the backing map. Used as a key
to lookup the instance. public Map<String,Object> getObjects()
public <T> T getObject(String name, Class<T> requiredType) throws RequiredTypeException
NamedObjectEnvironment
null
if
no object with that name was found.getObject
in interface NamedObjectEnvironment
T
- the type of the classname
- the assigned name of the object.requiredType
- the class to which the discovered object must be assignable.null
if
no object with that name was found.RequiredTypeException
- if the discovered object does not equal, extend, or implement the specified class.public void destroy() throws Exception
Destroyable
destroy
in interface Destroyable
Exception
- if an exception occurs during object destruction.Copyright © 2004–2019 The Apache Software Foundation. All rights reserved.