Class JndiLocator

  • Direct Known Subclasses:
    JndiObjectFactory, JndiRealmFactory

    public class JndiLocator
    extends 
    Convenient superclass for JNDI accessors, providing "jndiTemplate" and "jndiEnvironment" bean properties.

    Note that this implementation is an almost exact combined copy of the Spring Framework's 'JndiAccessor' and 'JndiLocatorSupport' classes from their 2.5.4 distribution - we didn't want to re-invent the wheel, but not require a full dependency on the Spring framework, nor does Spring make available only its JNDI classes in a small jar, or we would have used that. Since Shiro is also Apache 2.0 licensed, all regular licenses and conditions and authors have remained in tact.

    Since:
    1.1
    See Also:
    setJndiTemplate(org.apache.shiro.jndi.JndiTemplate), setJndiEnvironment(java.util.Properties), setResourceRef(boolean)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static CONTAINER_PREFIX
      JNDI prefix used in a J2EE container
    • Constructor Summary

      Constructors 
      Constructor Description
      JndiLocator()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected  jndiName)
      Convert the given JNDI name into the actual JNDI name to use.
      getJndiEnvironment()
      Return the JNDI environment to use for JNDI lookups.
      JndiTemplate getJndiTemplate()
      Return the JNDI template to use for JNDI lookups.
      boolean isResourceRef()
      Return whether the lookup occurs in a J2EE container.
      protected  jndiName)
      Perform an actual JNDI lookup for the given name via the JndiTemplate.
      protected  jndiName,  requiredType)
      Perform an actual JNDI lookup for the given name via the JndiTemplate.
      void  jndiEnvironment)
      Set the JNDI environment to use for JNDI lookups.
      void setJndiTemplate​(JndiTemplate jndiTemplate)
      Set the JNDI template to use for JNDI lookups.
      void setResourceRef​(boolean resourceRef)
      Set whether the lookup occurs in a J2EE container, i.e.
      • Methods inherited from class java.lang.

        , , , , , , , , , ,
    • Field Detail

      • CONTAINER_PREFIX

        public static final  CONTAINER_PREFIX
        JNDI prefix used in a J2EE container
        See Also:
        Constant Field Values
    • Constructor Detail

      • JndiLocator

        public JndiLocator()
    • Method Detail

      • getJndiTemplate

        public JndiTemplate getJndiTemplate()
        Return the JNDI template to use for JNDI lookups.
      • getJndiEnvironment

        public  getJndiEnvironment()
        Return the JNDI environment to use for JNDI lookups.
      • setResourceRef

        public void setResourceRef​(boolean resourceRef)
        Set whether the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is "false".

        Note: Will only get applied if no other scheme (e.g. "java:") is given.

      • isResourceRef

        public boolean isResourceRef()
        Return whether the lookup occurs in a J2EE container.
      • lookup

        protected  lookup​( jndiName)
                         throws 
        Perform an actual JNDI lookup for the given name via the JndiTemplate.

        If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

        Parameters:
        jndiName - the JNDI name to look up
        Returns:
        the obtained object
        Throws:
        - if the JNDI lookup failed
        See Also:
        setResourceRef(boolean)
      • lookup

        protected  lookup​( jndiName,
                                 requiredType)
                         throws 
        Perform an actual JNDI lookup for the given name via the JndiTemplate.

        If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

        Parameters:
        jndiName - the JNDI name to look up
        requiredType - the required type of the object
        Returns:
        the obtained object
        Throws:
        - if the JNDI lookup failed
        See Also:
        setResourceRef(boolean)
      • convertJndiName

        protected  convertJndiName​( jndiName)
        Convert the given JNDI name into the actual JNDI name to use.

        The default implementation applies the "java:comp/env/" prefix if "resourceRef" is "true" and no other scheme (e.g. "java:") is given.

        Parameters:
        jndiName - the original JNDI name
        Returns:
        the JNDI name to use
        See Also:
        CONTAINER_PREFIX, setResourceRef(boolean)