197

Spring Security SAML ExtensionSpring Bootと統合しようとしています。

問題については、完全なサンプル アプリケーションを開発しました。そのソース コードは GitHub で入手できます。

Spring Boot アプリケーションとして実行する (SDK 組み込みのアプリケーション サーバーに対して実行する) ことで、WebApp は正常に動作します。

残念ながら、同じ AuthN プロセスはUndertow/WildFlyではまったく機能しません。

ログによると、IdP は実際にAuthNプロセスを実行します。カスタムUserDetails実装の命令は正しく実行されます。実行フローにもかかわらず、Spring は現在のユーザーの権限を設定および保持しません。

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

FilterChainProxyデバッグ中に、問題がクラスに依存していることがわかりました。実行時に、 の属性FILTER_APPLIEDnullServletRequest値を持つため、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 SeverおよびTomcatでは、すべて正常に動作します。この問題を解決するためのアイデアはありますか?

4

1 に答える 1

7

問題を調査していると、認証リクエストで Cookie とリファラーが混乱していることに気付きました。

現在、webapplication コンテキストをルート コンテキストに変更すると、wildfly 認証が機能します。

 <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 をクリアすると、すべてが期待どおりに動作するはずです

于 2015-05-27T08:27:22.197 に答える