[英]Spring Security XML configuration and Spring SAML in Java configuration
我在我的一个项目中使用 Spring Security,现在想引入 Spring SAML。 到目前为止,我已经使用了 Spring 的 XML 配置。 我可以使用基于 Java 的配置来集成 SAML 吗?
我是 SAML 集成的新手。
是的,您可以像使用 Spring Security 的其余部分一样使用 Java 配置 Spring SAML。
您需要一个带有这样的配置类的 WebSecurityConfig 类
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.authenticationEntryPoint(samlEntryPoint());
http
.csrf()
.disable();
http
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/error").permitAll()
.antMatchers("/saml/**").permitAll()
.anyRequest().authenticated();
http
.logout()
.logoutSuccessUrl("/");
}
您只需要使用 Java 将所有不同的 bean 编写在一起,例如像这样设置 SecurityFilterChain
public FilterChainProxy samlFilter() throws Exception {
List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>();
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
samlEntryPoint()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
samlLogoutFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/metadata/**"),
metadataDisplayFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
samlWebSSOProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSOHoK/**"),
samlWebSSOHoKProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"),
samlLogoutProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
samlIDPDiscovery()));
return new FilterChainProxy(chains);
}
看看这个项目https://github.com/vdenotaris/spring-boot-security-saml-sample作为它是如何完成的示例。 com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java 显示了秘方的成分。
您可以使用 xml 配置进行 SAML 集成。 作为初学者很难从头开始创建它,因此我建议您下载 spring saml 示例应用程序并基于它创建您的配置。 集成到您现有的应用程序只是一个 spring 安全集成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.