Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring安全XML配置和Java配置中的Spring SAML_Java_Spring_Security_Spring Security_Spring Saml - Fatal编程技术网

Spring安全XML配置和Java配置中的Spring SAML

Spring安全XML配置和Java配置中的Spring SAML,java,spring,security,spring-security,spring-saml,Java,Spring,Security,Spring Security,Spring Saml,我正在我的一个项目中使用SpringSecurity,现在想介绍SpringSAML。到目前为止,我已经使用了Spring的XML配置。我可以使用基于Java的配置集成SAML吗 我不熟悉SAML集成。您可以使用xml配置进行SAML集成。很难从头开始创建它,所以我建议您下载SpringSAML示例应用程序,并基于它创建您的配置。与现有应用程序的集成只是一个spring安全集成。是的,您可以使用Java配置spring SAML,就像使用spring安全的其余部分一样 您需要一个WebSecur

我正在我的一个项目中使用SpringSecurity,现在想介绍SpringSAML。到目前为止,我已经使用了Spring的XML配置。我可以使用基于Java的配置集成SAML吗


我不熟悉SAML集成。

您可以使用xml配置进行SAML集成。很难从头开始创建它,所以我建议您下载SpringSAML示例应用程序,并基于它创建您的配置。与现有应用程序的集成只是一个spring安全集成。

是的,您可以使用Java配置spring SAML,就像使用spring安全的其余部分一样

您需要一个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("/");
}
    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);
}
您只需要使用Java将所有不同的bean编写在一起,例如,像这样设置SecurityFilterChain

   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("/");
}
    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);
}
public FilterChainProxy samlFilter()引发异常{
列表链=新的ArrayList();
add(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/login/**”),
samlEntryPoint());
添加(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/logout/**”),
samlLogoutFilter());
add(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/metadata/**”),
metadataDisplayFilter());
添加(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/SSO/**”),
samlWebSSOProcessingFilter());
add(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/sshok/**”),
SamlWebSShokProcessingFilter());
add(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/SingleLogout/**”),
samlLogoutProcessingFilter());
add(新的DefaultSecurityFilterChain(新的AntPathRequestMatcher(“/saml/discovery/**”),
samlIDPDiscovery());
返回新的过滤器链氧(链条);
}

以这个项目为例说明它是如何完成的。com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java显示了秘方的成分。

实际上,我希望saml配置基于java,因为这样我就能够根据一些数据库值启用/禁用它。如果您是saml新手,我建议您基于现有的示例,创建配置并存储它,然后将配置更改为java定义。事实上,现有的官方示例是基于xml配置的。因为config基于Spring安全性,而Security具有java config。谢谢你的回答,还有一个问题,如果我有Spring安全性(xml配置)和Spring SAML(Java配置),什么优先?有什么想法吗?我不知道,但你应该能够在应用程序启动时看到它。Spring将告诉您正在配置哪些bean。最好是自己控制初始化的顺序。以下是如何结合XML和JavaConfig的相关文档,并解释了如何从XML引导JavaConfig,反之亦然: