Skip to content

Commit

Permalink
Merge pull request #499 from julian-computes/shiro_filter_config_npe_fix
Browse files Browse the repository at this point in the history
[SHIRO-893] - Fix NPE in ShiroFilter.init()
  • Loading branch information
bmarwell authored Oct 26, 2022
2 parents 396c88f + 97b4222 commit efbd28c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class DefaultWebEnvironment extends DefaultEnvironment implements Mutable

private ServletContext servletContext;

private ShiroFilterConfiguration filterConfiguration;

public DefaultWebEnvironment() {
super();
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit efbd28c

Please sign in to comment.