1
0
mirror of synced 2026-08-06 10:18:52 +00:00

SEC-3047: SecurityContextHolderAwareRequestFactory update RequestFactory

This commit is contained in:
Rob Winch
2015-07-20 14:06:44 -05:00
parent 9b92d5a1e7
commit 7c725a60e2
2 changed files with 16 additions and 0 deletions
@@ -94,6 +94,7 @@ public class SecurityContextHolderAwareRequestFilter extends GenericFilterBean {
public void setRolePrefix(String rolePrefix) {
Assert.notNull(rolePrefix, "Role prefix must not be null");
this.rolePrefix = rolePrefix;
updateFactory();
}
/**
@@ -172,6 +173,10 @@ public class SecurityContextHolderAwareRequestFilter extends GenericFilterBean {
@Override
public void afterPropertiesSet() throws ServletException {
super.afterPropertiesSet();
updateFactory();
}
private void updateFactory() {
requestFactory = isServlet3() ? createServlet3Factory(rolePrefix)
: new HttpServlet25RequestFactory(trustResolver, rolePrefix);
}
@@ -186,6 +191,7 @@ public class SecurityContextHolderAwareRequestFilter extends GenericFilterBean {
public void setTrustResolver(AuthenticationTrustResolver trustResolver) {
Assert.notNull(trustResolver, "trustResolver cannot be null");
this.trustResolver = trustResolver;
updateFactory();
}
private HttpServletRequestFactory createServlet3Factory(String rolePrefix) {
@@ -379,6 +379,16 @@ public class SecurityContextHolderAwareRequestFilterTests {
.isEqualTo(runnable);
}
// SEC-3047
@Test
public void updateRequestFactory() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user",
"password", "PREFIX_USER"));
filter.setRolePrefix("PREFIX_");
assertThat(wrappedRequest().isUserInRole("PREFIX_USER")).isTrue();;
}
private HttpServletRequest wrappedRequest() throws Exception {
filter.doFilter(request, response, filterChain);
verify(filterChain).doFilter(requestCaptor.capture(),