I was earlier using pac4j version 2.3.1 with spring-security-pac4j 3.0.0 and it was working fine.
Now I am upgraded to pac4j version 5.3.1 and its not working properly with spring-security-pac4j 6.1.0 version, SecurityContextHolder.getContext().getAuthentication()
is comming as null
.
The SecurityFilter
class has changes in spring-security-pac4j 6.1.0
Can you please help me:
- pac4j version 5.3.1 is compatible with which versions of spring-security-pac4j
- Also if i need to use spring-security-pac4j 6.1.0 version, then what changes i need to do.
Below is test case failing for me, SecurityContextHolder.getContext().getAuthentication()
is null
with version of spring-security-pac4j 6.1.0
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
CommonSecurityFilter filter = new CommonSecurityFilter(config, "Test");
filter.doFilter(mockRequest(TEST_TOKEN), response, chain);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
CommonSecurityFilter
is custom class and its not even calling doFilter
method from below:
public class CommonSecurityFilter extends CompositeFilter {
public CommonSecurityFilter(Config config, String clients) {
List<Filter> filters = new ArrayList<>();
filters.add(new SecurityFilter(config, clients));
filters.add(new AuthenticationFilter());
setFilters(filters);
}
private static class AuthenticationFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
SecurityContext context = SecurityContextHolder.getContext();
Authentication auth = context.getAuthentication();
if (auth instanceof Pac4jAuthentication && auth.isAuthenticated()) {
CommonProfile profile = (CommonProfile)((Pac4jAuthentication)auth).getProfile();
if (profile instanceof CServUserProfile) {
CommonAuthenticationToken token = new CommonAuthenticationToken((CommonUserProfile)profile);
token.setAuthenticated(true);
context.setAuthentication(token);
}
}
chain.doFilter(request, response);
}
}
}