Spring Security on Wildfly / Undertow: error executing the filter chain

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

I'm working in order to integrate Spring Security SAML Extension with Spring Boot.

I developed a complete sample application, all the source code is published on GitHub:

By running the WebApp as Spring Boot application (through Spring Tool Set, by using an embedded Application Server), it works fine. Unfortunately, the auth process doesn't work on Undertow/WildFly (and I must use it as production AS).

By logging, I can see that the IdP performs the AuthN process and the instructions of my custom UserDetails implementation are correctly executed. Despite that Spring doesn't set up the privileges for the current user.

@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;     } } 

By debugging, I checked that the problem starts from the FilterChainProxy class. When I run the webapp on WildFly, I can see that the attribute FILTER_APPLIED of ServletRequest is null, thus Spring clears the 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);     } } 

On VMware vFabric tc Sever and Tomcat that doesn't happen. Is there a way to resolve this issue?

回答1:

Investigating the problem I have noticed that there is some mess with cookies and referers in the auth request.

Currently wildfly authentication will work if you change webapplication context to the Root Context:

 <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> 

After restarting wildfly and clearing cookies all should work as expected



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!