Class DefaultEnvironment

  • All Implemented Interfaces:
    Environment, NamedObjectEnvironment, org.apache.shiro.util.Destroyable
    Direct Known Subclasses:
    BasicIniEnvironment

    public class DefaultEnvironment
    extends 
    implements NamedObjectEnvironment, org.apache.shiro.util.Destroyable
    Simple/default Environment implementation that stores Shiro objects as key-value pairs in a instance. The key is the object name, the value is the object itself.
    Since:
    1.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static DEFAULT_SECURITY_MANAGER_KEY
      The default name under which the application's SecurityManager instance may be acquired, equal to securityManager.
      protected <,​> objects  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultEnvironment()
      Creates a new instance with a thread-safe backing map.
      <,​?> seed)
      Creates a new instance with the specified backing map.
    • Field Detail

      • DEFAULT_SECURITY_MANAGER_KEY

        public static final  DEFAULT_SECURITY_MANAGER_KEY
        The default name under which the application's SecurityManager instance may be acquired, equal to securityManager.
        See Also:
        Constant Field Values
      • objects

        protected final <,​> objects
    • Constructor Detail

      • DefaultEnvironment

        public DefaultEnvironment()
        Creates a new instance with a thread-safe backing map.
      • DefaultEnvironment

        public DefaultEnvironment​(<,​?> seed)
        Creates a new instance with the specified backing map.
        Parameters:
        seed - backing map to use to maintain Shiro objects.
    • Method Detail

      • getSecurityManager

        public SecurityManager getSecurityManager()
                                           throws 
        Returns the application's 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.

        Specified by:
        getSecurityManager in interface Environment
        Returns:
        the application's SecurityManager instance accessible in the backing map using the securityManagerName property as the lookup key.
        Throws:
      • setSecurityManager

        public void setSecurityManager​(SecurityManager securityManager)
      • lookupSecurityManager

        protected SecurityManager lookupSecurityManager()
        Looks up the SecurityManager instance in the backing map without performing any non-null guarantees.
        Returns:
        the SecurityManager in the backing map, or null if it has not yet been populated.
      • getSecurityManagerName

        public  getSecurityManagerName()
        Returns the name of the SecurityManager instance in the backing map. Used as a key to lookup the instance. Unless set otherwise, the default is securityManager.
        Returns:
        the name of the SecurityManager instance in the backing map. Used as a key to lookup the instance.
      • setSecurityManagerName

        public void setSecurityManagerName​( securityManagerName)
        Sets the name of the SecurityManager instance in the backing map. Used as a key to lookup the instance. Unless set otherwise, the default is securityManager.
        Parameters:
        securityManagerName - the name of the SecurityManager instance in the backing map. Used as a key to lookup the instance. 
      • getObjects

        public <,​> getObjects()
        Returns the live (modifiable) internal objects collection.
        Returns:
        the live (modifiable) internal objects collection.
      • getObject

        public <T> T getObject​( name,
                               <T> requiredType)
                        throws RequiredTypeException
        Description copied from interface: NamedObjectEnvironment
        Returns the object in Shiro's environment with the specified name and type or null if no object with that name was found.
        Specified by:
        getObject in interface NamedObjectEnvironment
        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 null if no object with that name was found.
        Throws:
        RequiredTypeException - if the discovered object does not equal, extend, or implement the specified class.
      • setObject

        public void setObject​( name,
                               instance)
      • destroy

        public void destroy()
                     throws 
        Specified by:
        destroy in interface org.apache.shiro.util.Destroyable
        Throws: