Spring Security SAML ExtensionをSpring 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_APPLIED
はnullServletRequest
値を持つため、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では、すべて正常に動作します。この問題を解決するためのアイデアはありますか?