我正在使用 Spring Security v5.5.1 SAML2 代码来支持 SAML。我有一个使用较旧的 Spring 安全扩展的工作解决方案,但我正在“升级”。
我已使 SP 启动和 IDP 启动的流程正常工作,但我不知道如何配置成功处理程序重定向 URL。它默认为“/”。我不明白如何访问 Saml2WebSsoAuthenticationFilter
和/或 SavedRequestAwareAuthenticationSuccessHandler
来覆盖 URL。
我在 IDP 上设置了默认的 RelayState
,它确实与断言一起发送,但 Spring 似乎没有使用它。
此外,使用旧的扩展,我可以将 SAML 请求存储在数据库中,并在响应到来时检索它,因为我的应用程序不使用 session 。我在这里还没有找到同样的方法。
这是我从我找到的文档和示例中收集到的身份验证提供者和中继方注册:
OpenSaml4AuthenticationProvider authenticationProvider = new OpenSaml4AuthenticationProvider();
authenticationProvider.setAssertionValidator( OpenSaml4AuthenticationProvider.createDefaultAssertionValidator( assertionToken -> {
Map<String, Object> params = new HashMap<>();
params.put( CLOCK_SKEW, Duration.ofMinutes(10).toMillis());
String recipient = assertionToken.getToken().getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
params.put( SAML2AssertionValidationParameters.SC_VALID_RECIPIENTS, Collections.singleton(recipient));
String audience = assertionToken.getToken().getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
params.put( SAML2AssertionValidationParameters.COND_VALID_AUDIENCES, Collections.singleton( "blah"));
return new ValidationContext( params);
})
);
Converter<HttpServletRequest, RelyingPartyRegistration> relyingPartyRegistrationResolver =
new DefaultRelyingPartyRegistrationResolver( relyingPartyRegistrationRepository);
Saml2MetadataFilter filter = new Saml2MetadataFilter(
relyingPartyRegistrationResolver,
new OpenSamlMetadataResolver());
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers( "/saml2/**").permitAll()
.antMatchers( "/login/**").permitAll()
.and()
.saml2Login( saml2 -> saml2.authenticationManager( new ProviderManager( authenticationProvider)))
.addFilterBefore( filter, Saml2WebSsoAuthenticationFilter.class);
RelyingPartyRegistration registration = RelyingPartyRegistration
.withRegistrationId("blah")
.assertionConsumerServiceLocation( getAssertionRecipient( environment, "blah"))
.signingX509Credentials( c -> c.add( credentialSp))
.decryptionX509Credentials( c -> c.add( decryptSp))
.assertingPartyDetails(party -> party
.entityId("blah")
.singleSignOnServiceLocation("https://sso.stuff/samlstuff")
.wantAuthnRequestsSigned( false)
.verificationX509Credentials( c -> c.add( credential))
)
.build();
我想我可以以某种方式做与以前相同的事情,但是对于提供的所有文档,很难理解其中的大部分内容。
谢谢!
最佳答案
也许你应该尝试 .successHandler(
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers( "/saml2/**").permitAll()
.antMatchers( "/login/**").permitAll()
.and()
.saml2Login()
.successHandler(mySamlLoginSuccessHandler)
与
class MySamlLoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
MySamlLoginSuccessHandler() {
super('/path/to/success')
}
}
关于spring-security - Spring SAML2 Saml2WebSsoAuthenticationFilter 自定义 AuthenticationSuccessHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68472040/