弹簧安全Wild / Undertow:执行filter链时出错

我正在努力将Spring Security SAML扩展Spring Boot集成。

我开发了一个完整的示例应用程序,所有的源代码都在GitHub上发布:

  • spring-boot-saml-integration在GitHub上

通过运行WebApp作为Spring Boot应用程序(通过Spring工具集,使用embedded式应用程序服务器),它工作正常。 不幸的是,auth过程在Undertow / WildFly不起作用 (我必须将它用作生产AS)。

通过日志logging,我可以看到IdP执行AuthN进程,并且我的自定义UserDetails实现的指令正确执行。 尽pipeSpring没有为当前用户设置权限。

 @Component public class SAMLUserDetailsServiceImpl implements SAMLUserDetailsService { // Logger private static final Logger LOG = LoggerFactory.getLogger(SAMLUserDetailsServiceImpl.class); @Override public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException, SSOUserAccountNotExistsException { String userID = credential.getNameID().getValue(); if (userID.compareTo("jdoe@samplemail.com") != 0) { // We're simulating the data access. LOG.warn("SSO User Account not found into the system"); throw new SSOUserAccountNotExistsException("SSO User Account not found into the system", userID); } LOG.info(userID + " is logged in"); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER"); authorities.add(authority); ExtUser userDetails = new ExtUser(userID, "password", true, true, true, true, authorities, "John", "Doe"); return userDetails; } } 

通过debugging,我检查了问题从FilterChainProxy类开始。 当我在WildFly上运行webapp时,我可以看到ServletRequest的属性FILTER_APPLIEDnull ,因此Spring清除了SecurityContextHolder

 private final static String FILTER_APPLIED = FilterChainProxy.class.getName().concat(".APPLIED"); public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean clearContext = request.getAttribute(FILTER_APPLIED) == null; if (clearContext) { try { request.setAttribute(FILTER_APPLIED, Boolean.TRUE); doFilterInternal(request, response, chain); } finally { SecurityContextHolder.clearContext(); request.removeAttribute(FILTER_APPLIED); } } else { doFilterInternal(request, response, chain); } } 

VMware vFabric tc SeverTomcat上没有发生。 有没有办法解决这个问题?

调查问题我已经注意到,在validation请求中,Cookie和查阅者有一些混乱。

如果将Web应用程序上下文更改为根上下文,则当前野蛮身份validation将起作用:

  <server name="default-server" default-host="webapp"> <http-listener name="default" socket-binding="http"/> <host name="default-host" alias="localhost" default-web-module="sso.war"/> </server> 

重新启动wildfly并清除cookie后,所有应该按预期工作