diff --git a/web/src/main/java/org/apache/shiro/web/env/DefaultWebEnvironment.java b/web/src/main/java/org/apache/shiro/web/env/DefaultWebEnvironment.java index 7ce3d870e6..692f1c36f5 100644 --- a/web/src/main/java/org/apache/shiro/web/env/DefaultWebEnvironment.java +++ b/web/src/main/java/org/apache/shiro/web/env/DefaultWebEnvironment.java @@ -39,8 +39,6 @@ public class DefaultWebEnvironment extends DefaultEnvironment implements Mutable private ServletContext servletContext; - private ShiroFilterConfiguration filterConfiguration; - public DefaultWebEnvironment() { super(); } @@ -97,6 +95,12 @@ public void setShiroFilterConfiguration(ShiroFilterConfiguration filterConfigura @Override public ShiroFilterConfiguration getShiroFilterConfiguration() { - return getObject(SHIRO_FILTER_CONFIG_NAME, ShiroFilterConfiguration.class); + ShiroFilterConfiguration config = getObject(SHIRO_FILTER_CONFIG_NAME, ShiroFilterConfiguration.class); + // Use the default configuration if config is null + if (config == null) { + config = MutableWebEnvironment.super.getShiroFilterConfiguration(); + setShiroFilterConfiguration(config); + } + return config; } } diff --git a/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java b/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java index 2fbc0a1a63..13df5d7195 100644 --- a/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java +++ b/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java @@ -30,6 +30,8 @@ import static org.easymock.EasyMock.expect; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.stringContainsInOrder; @@ -60,6 +62,24 @@ public void singleServiceTest() throws Exception { assertThat(environmentStub.getServletContext(), sameInstance(servletContext)); } + @Test + public void testDefaultWebEnvironment() { + ServletContext servletContext = EasyMock.mock(ServletContext.class); + expect(servletContext.getInitParameter("shiroEnvironmentClass")) + .andReturn(DefaultWebEnvironment.class.getName()); + expect(servletContext.getInitParameter("shiroConfigLocations")).andReturn(null); + + EasyMock.replay(servletContext); + + WebEnvironment environment = new EnvironmentLoader().createEnvironment(servletContext); + + EasyMock.verify(servletContext); + + assertThat(environment, instanceOf(DefaultWebEnvironment.class)); + assertThat(environment.getShiroFilterConfiguration(), is(notNullValue())); + assertThat(environment.getServletContext(), sameInstance(servletContext)); + } + @Test() @Ignore public void multipleServiceTest() throws Exception {