spring saml2 saml2 WebSoAuthenticationFilter自定义authenticationsuccesshandler

gblwokeq  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(413)

我正在使用SpringSecurityV5.5.1SAML2代码来支持saml。我有一个使用旧的spring安全扩展的工作解决方案,但我正在“升级”。
我有sp启动和idp启动的流,但我不知道如何配置成功处理程序重定向url。默认为“/”。我不明白如何才能访问 Saml2WebSsoAuthenticationFilter 和/或 SavedRequestAwareAuthenticationSuccessHandler 以覆盖url。
我设置了默认值 RelayState 在idp上,它确实与Assert一起发送,但spring似乎没有使用它。
此外,使用较旧的扩展,我可以将saml请求存储在数据库中,并在收到响应时检索它,因为我的应用程序不使用会话。我在这里还没有找到一种方法来做同样的事情。
以下是我的身份验证提供商和中继方注册,如我找到的文档和样本所示:

  1. OpenSaml4AuthenticationProvider authenticationProvider = new OpenSaml4AuthenticationProvider();
  2. authenticationProvider.setAssertionValidator( OpenSaml4AuthenticationProvider.createDefaultAssertionValidator( assertionToken -> {
  3. Map<String, Object> params = new HashMap<>();
  4. params.put( CLOCK_SKEW, Duration.ofMinutes(10).toMillis());
  5. String recipient = assertionToken.getToken().getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
  6. params.put( SAML2AssertionValidationParameters.SC_VALID_RECIPIENTS, Collections.singleton(recipient));
  7. String audience = assertionToken.getToken().getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
  8. params.put( SAML2AssertionValidationParameters.COND_VALID_AUDIENCES, Collections.singleton( "blah"));
  9. return new ValidationContext( params);
  10. })
  11. );
  12. Converter<HttpServletRequest, RelyingPartyRegistration> relyingPartyRegistrationResolver =
  13. new DefaultRelyingPartyRegistrationResolver( relyingPartyRegistrationRepository);
  14. Saml2MetadataFilter filter = new Saml2MetadataFilter(
  15. relyingPartyRegistrationResolver,
  16. new OpenSamlMetadataResolver());
  17. http
  18. .sessionManagement()
  19. .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  20. .and()
  21. .authorizeRequests()
  22. .antMatchers( "/saml2/**").permitAll()
  23. .antMatchers( "/login/**").permitAll()
  24. .and()
  25. .saml2Login( saml2 -> saml2.authenticationManager( new ProviderManager( authenticationProvider)))
  26. .addFilterBefore( filter, Saml2WebSsoAuthenticationFilter.class);
  1. RelyingPartyRegistration registration = RelyingPartyRegistration
  2. .withRegistrationId("blah")
  3. .assertionConsumerServiceLocation( getAssertionRecipient( environment, "blah"))
  4. .signingX509Credentials( c -> c.add( credentialSp))
  5. .decryptionX509Credentials( c -> c.add( decryptSp))
  6. .assertingPartyDetails(party -> party
  7. .entityId("blah")
  8. .singleSignOnServiceLocation("https://sso.stuff/samlstuff")
  9. .wantAuthnRequestsSigned( false)
  10. .verificationX509Credentials( c -> c.add( credential))
  11. )
  12. .build();

我想我可以以某种方式像以前那样做,但是对于提供的所有文档,很难理解其中的大部分内容。
非常感谢。

aurhwmvo

aurhwmvo1#

试试这样的,对我很管用。saml2login(saml2->{saml2.authenticationmanager(新providermanager(authenticationprovider));saml2.defaultsuccessurl(“url”)})

相关问题