[jira] [Commented] (SHIRO-617) ShiroFilter initialize WebEnvironment on startup

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SHIRO-617) ShiroFilter initialize WebEnvironment on startup

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/SHIRO-617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15940245#comment-15940245 ]

Marco Descher commented on SHIRO-617:
-------------------------------------

Would the following change meet expectations (Nevermind missing JavaDoc)?

{code:title=ShiroFilter.java|borderStyle=solid}
public class ShiroFilter extends AbstractShiroFilter {

        private boolean instantiateDefaultWebEnvironment;
       
        public ShiroFilter() {
                this(false);
        }
       
        public ShiroFilter(boolean instantiateWebEnvironment) {
                this.instantiateDefaultWebEnvironment = instantiateWebEnvironment;
        }
       
    /**
     * Configures this instance based on the existing {@link org.apache.shiro.web.env.WebEnvironment} instance
     * available to the currently accessible {@link #getServletContext() servletContext}.
     *
     * @see org.apache.shiro.web.env.EnvironmentLoaderListener
     * @since 1.2
     */
    @Override
    public void init() throws Exception {
   
    WebEnvironment env = null;
   
                if (instantiateDefaultWebEnvironment) {
                        env = WebUtils.getWebEnvironment(getServletContext());
                        if (env == null) {
                                env = new EnvironmentLoader().initEnvironment(getServletContext());
                        }
                } else {
                        env = WebUtils.getRequiredWebEnvironment(getServletContext());
                }

        setSecurityManager(env.getWebSecurityManager());

        FilterChainResolver resolver = env.getFilterChainResolver();
        if (resolver != null) {
            setFilterChainResolver(resolver);
        }
    }
}
{code}


> ShiroFilter initialize WebEnvironment on startup
> ------------------------------------------------
>
>                 Key: SHIRO-617
>                 URL: https://issues.apache.org/jira/browse/SHIRO-617
>             Project: Shiro
>          Issue Type: Improvement
>            Reporter: Marco Descher
>            Priority: Minor
>
> Following up to http://shiro-developer.582600.n2.nabble.com/Deprecation-of-org-apache-shiro-web-servlet-IniShiroFilter-td7205283.html
> I am integrating shiro into our OSGI based product. The requirement to register the WebEnvironment listener on startup is a real problem.
> ""it would be extremely easy to create a subclass of ShiroFilter that
> initializes the necessary WebEnvironment at filter startup.  If you
> can't use a servlet context listener, this would be the next best
> thing and would work as expected.  The EnvironmentLoaderListener is
> extremely minimal on purpose - the real work is done in the parent
> class, which can be used from a Filter easily. ""



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)