Jay*_*ngs 4 java spring spring-security saml
太棒了;注册自定义 AuthenticationSuccessHandler 或配置 SAMLRelayStateSuccessHandler 以在成功身份验证后设置重定向 URL Spring Security 的 SAML 扩展的适当方法是什么?
\n\n我是 Spring 和 Spring Security 的新手,但我在让 SAML 扩展适用于单点登录应用程序方面取得了一些成功。但是,我遇到了一个问题,Okta(IDP)和我的应用程序将在成功身份验证后连续循环,而不是转到原始 URL。我怀疑这是由于我同时使用 Vaadin 和 Spring 而导致的,一旦 Vaadin servlet 加载,它就会使用 Spring 过滤器做一些奇怪的事情或完全忽略 Spring 过滤器。在关于将基于过滤器的 Spring Security 与 Vaadin 相结合的博客文章中建议了一个可能的问题和解决方案,其中建议的解决方案是注册 AuthenticationSuccessHandler。
\n\n然而,对于 Spring Security SAML 扩展来说,这并不像简单的表单登录或 OpenID 那样简单。例如,使用表单登录注册成功处理程序就像
\n\nhttp.formLogin().successHandler(handler);\nRun Code Online (Sandbox Code Playgroud)\n\nSAML 扩展不提供此类选项。然而,在另一篇文章中,Vladim\xc3\xadr Sch\xc3\xa4fer(请参阅“Spring saml - how Remember requestparameterwheninitialloginonSP,andprocessingthereafterIdPresponse)建议将 AuthenticationSuccessHandler 更改为 SAMLRelayStateSuccessHandler。文档建议这将是一个完美的方法。但是,我不希望将 SAMLEntryPoint 子类化。
\n\n我当前的 SecurityConfiguration 完全基于 Java,并遵循 Matt Raible 关于一起使用 Spring 和 Okta 的文章。安全配置如下:
\n\n@Override\nprotected void configure(final HttpSecurity http) throws Exception {\n\n http\n .csrf().disable() // Disable Spring\'s CSRF protection and use Vaadin\'s.\n .authorizeRequests() // Everything else: Do SAML SSO\n // Allow everyone to attempt to login\n .antMatchers("/root/saml*").permitAll()\n // But make sure all other requests are authenticated\n .anyRequest().authenticated()\n .and()\n // Create a completely new session\n .sessionManagement().sessionFixation().newSession()\n .and()\n // Configure the saml properties\n .apply(saml())\n .serviceProvider()\n .keyStore()\n .storeFilePath("saml/keystore.jks")\n .password(this.password)\n .keyname(this.keyAlias)\n .keyPassword(this.password)\n .and()\n .protocol("https")\n // Do I need to adjust this localhost piece?\n .hostname(String.format("%s:%s", "localhost", this.port))\n .basePath("/")\n .and() \n // Load the metadata from the stored properties\n .identityProvider().metadataFilePath(this.metadataUrl);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n````
\n\n注册 AuthenticationSuccessHandler 或配置 SAMLRelayStateSuccessHandler 的最佳方法是什么?任何其他想法也将不胜感激!
\n我在用着:
@Bean
public SavedRequestAwareAuthenticationSuccessHandler successRedirectHandler() {
SavedRequestAwareAuthenticationSuccessHandler successRedirectHandler =
new SavedRequestAwareAuthenticationSuccessHandler() {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
super.onAuthenticationSuccess(request, response, authentication);
}
};
successRedirectHandler.setDefaultTargetUrl("/");
return successRedirectHandler;
}
Run Code Online (Sandbox Code Playgroud)
它似乎避免需要单独的 securityContext.xml 文件。
| 归档时间: |
|
| 查看次数: |
4618 次 |
| 最近记录: |