Class HTTPServletGuiseContainer

  • All Implemented Interfaces:
    GuiseContainer

    public class HTTPServletGuiseContainer
    extends AbstractGuiseContainer
    A Guise container for Guise HTTP servlets. There will be one servlet Guise container per ServletContext, which usually corresponds to a single web application on a JVM.
    Author:
    Garret Wilson
    • Field Detail

      • RESOURCES_DIRECTORY_PATH

        public static final java.lang.String RESOURCES_DIRECTORY_PATH
        The absolute path, relative to the servlet context, of the resources directory.
    • Constructor Detail

      • HTTPServletGuiseContainer

        public HTTPServletGuiseContainer​(java.net.URI baseURI,
                                         javax.servlet.ServletContext servletContext)
        Servlet contains and container base URI constructor.
        Parameters:
        baseURI - The base URI of the container, an absolute URI that ends with the base path, which ends with a slash ('/'), indicating the base path of the application base paths.
        servletContext - The servlet context with which this container is associated.
        Throws:
        java.lang.NullPointerException - if the base URI and/or servlet context is null.
        java.lang.IllegalArgumentException - if the base URI is not absolute or does not end with a slash ('/') character.
    • Method Detail

      • getGuiseContainer

        public static HTTPServletGuiseContainer getGuiseContainer​(javax.servlet.ServletContext servletContext,
                                                                  java.net.URI baseURI)
        Retrieves the Guise container associated with the given servlet context. Because the Java Servlet architecture does not provide the context path to the servlet context, this method can only be called after the first request, which will provide the context path. If no Guise container is associated with the servlet context, one is created.
        Parameters:
        servletContext - The servlet context with which this container is associated.
        baseURI - The base URI of the container, an absolute URI that ends with the base path, which ends with a slash ('/'), indicating the base path of the application base paths.
        Returns:
        The Guise container associated with the given servlet context.
        Throws:
        java.lang.NullPointerException - if the servlet context and/or base URI is null.
        java.lang.IllegalArgumentException - if the base URI is not absolute or does not end with a slash ('/') character.
      • getServletContext

        protected final javax.servlet.ServletContext getServletContext()
        Returns:
        The servlet context with which this container is associated.
      • installApplication

        protected void installApplication​(AbstractGuiseApplication application,
                                          java.net.URI baseURI,
                                          java.io.File homeDirectory,
                                          java.io.File logDirectory,
                                          java.io.File tempDirectory)
                                   throws java.io.IOException
        Installs the given application at the given base path. If no theme is specified, the default theme will be loaded. This version ensures the home, log, and temp directories exist.

        This version is provided to expose the method to the servlet.

        Overrides:
        installApplication in class AbstractGuiseContainer
        Parameters:
        application - The application to install.
        baseURI - The base URI at which the application is being installed.
        homeDirectory - The home directory of the application.
        logDirectory - The log directory of the application.
        tempDirectory - The temporary directory of the application.
        Throws:
        java.io.IOException - if there is an I/O error when installing the application.
      • getGuiseSession

        protected GuiseSession getGuiseSession​(GuiseApplication guiseApplication,
                                               javax.servlet.http.HttpServletRequest httpRequest,
                                               javax.servlet.http.HttpSession httpSession)
        Retrieves a Guise session for the given HTTP session. A Guise session will be created if none is currently associated with the given HTTP session. When a Guise session is first created, its locale will be updated to match the language, if any, accepted by the HTTP request. This method should only be called by HTTP Guise session manager.
        Parameters:
        guiseApplication - The Guise application that will own the Guise session.
        httpRequest - The HTTP request with which the Guise session is associated.
        httpSession - The HTTP session for which a Guise session should be retrieved.
        Returns:
        The Guise session associated with the provided HTTP session.
        See Also:
        HTTPServletGuiseSessionManager
      • removeGuiseSessions

        protected java.util.Set<GuiseSession> removeGuiseSessions​(javax.servlet.http.HttpSession httpSession)
        Removes the Guise sessions for the given HTTP session. This method can only be accessed by classes in the same package. This method should only be called by HTTP Guise session manager.
        Parameters:
        httpSession - The HTTP session which should be removed along with its corresponding Guise session.
        Returns:
        The set of Guise sessions previously associated with the HTTP session.
        See Also:
        HTTPServletGuiseSessionManager
      • hasResource

        protected boolean hasResource​(java.lang.String resourcePath)
        Description copied from class: AbstractGuiseContainer
        Determines if the application has a resource available stored at the given resource path. The provided path is first normalized.
        Specified by:
        hasResource in class AbstractGuiseContainer
        Parameters:
        resourcePath - A container-relative path to a resource in the resource storage area.
        Returns:
        true if a resource exists at the given resource path.
      • getResourceInputStream

        protected java.io.InputStream getResourceInputStream​(java.lang.String resourcePath)
        Description copied from class: AbstractGuiseContainer
        Retrieves an input stream to the resource at the given path. The provided path is first normalized.
        Specified by:
        getResourceInputStream in class AbstractGuiseContainer
        Parameters:
        resourcePath - A container-relative path to a resource in the resource storage area.
        Returns:
        An input stream to the resource at the given resource path, or null if no resource exists at the given resource path.
      • getInputStream

        public java.io.InputStream getInputStream​(java.net.URI uri)
                                           throws java.io.IOException
        Retrieves an input stream to the entity at the given URI. The URI is first resolved to the container base URI.

        This version loads local resources directly through the servlet context.

        Specified by:
        getInputStream in interface GuiseContainer
        Overrides:
        getInputStream in class AbstractGuiseContainer
        Parameters:
        uri - A URI to the entity; either absolute or relative to the container.
        Returns:
        An input stream to the entity at the given resource URI, or null if no entity exists at the given resource path.
        Throws:
        java.io.IOException - if there was an error connecting to the entity at the given URI.
        See Also:
        AbstractGuiseContainer.getBaseURI()
      • getContextAbsoluteResourcePath

        protected java.lang.String getContextAbsoluteResourcePath​(java.lang.String containerRelativeResourcePath)
        Determines the servlet context-relative absolute path of the given container-relative path. The provided path is first normalized.
        Parameters:
        containerRelativeResourcePath - A container-relative path to a resource in the resource storage area.
        Returns:
        The absolute path to the resource relative to the servlet context.
        Throws:
        java.lang.IllegalArgumentException - if the given resource path is absolute.
      • getPrincipal

        protected java.security.Principal getPrincipal​(AbstractGuiseApplication application,
                                                       java.lang.String id)
        Looks up an application principal from the given ID. This version delegates to the given Guise application.

        This version is provided to allow package access.

        Overrides:
        getPrincipal in class AbstractGuiseContainer
        Parameters:
        application - The application for which a principal should be returned for the given ID.
        id - The ID of the principal.
        Returns:
        The principal corresponding to the given ID, or null if no principal could be determined.
      • getPassword

        protected char[] getPassword​(AbstractGuiseApplication application,
                                     java.security.Principal principal)
        Looks up the corresponding password for the given principal. This version delegates to the given Guise application.

        This version is provided to allow package access.

        Overrides:
        getPassword in class AbstractGuiseContainer
        Parameters:
        application - The application for which a password should e retrieved for the given principal.
        principal - The principal for which a password should be returned.
        Returns:
        The password associated with the given principal, or null if no password is associated with the given principal.
      • getRealm

        protected java.lang.String getRealm​(AbstractGuiseApplication application,
                                            java.net.URI resourceURI)
        Determines the realm applicable for the resource indicated by the given URI. This version delegates to the given Guise application.

        This version is provided to allow package access.

        Overrides:
        getRealm in class AbstractGuiseContainer
        Parameters:
        application - The application for which a realm should be returned for the given resource URI.
        resourceURI - The URI of the resource requested.
        Returns:
        The realm appropriate for the resource, or null if the given resource is not in a known realm.
        See Also:
        GuiseApplication.relativizeURI(URI)
      • isAuthorized

        protected boolean isAuthorized​(AbstractGuiseApplication application,
                                       java.net.URI resourceURI,
                                       java.security.Principal principal,
                                       java.lang.String realm)
        Checks whether the given principal is authorized to access the resource at the given application path. This version delegates to the given Guise application.

        This version is provided to allow package access.

        Overrides:
        isAuthorized in class AbstractGuiseContainer
        Parameters:
        application - The application for which a principal should be authorized for a given resource URI.
        resourceURI - The URI of the resource requested.
        principal - The principal requesting authentication, or null if the principal is not known.
        realm - The realm with which the resource is associated, or null if the realm is not known.
        Returns:
        true if the given principal is authorized to access the resource represented by the given resource URI.