Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SHIRO-893] Fix NPE in ShiroFilter.init() #515

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -63,6 +65,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()
public void multipleServiceTest() throws Exception {

Expand Down