Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.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安全Java配置,无需强制验证_Java_Spring_Spring Mvc_Authentication_Spring Security - Fatal编程技术网

Spring安全Java配置,无需强制验证

Spring安全Java配置,无需强制验证,java,spring,spring-mvc,authentication,spring-security,Java,Spring,Spring Mvc,Authentication,Spring Security,我很难弄清楚如何在不强制认证的情况下连接spring安全性。我的特定应用程序不要求用户进行身份验证,但用户可以根据需要进行身份验证 我目前有一个WebSecurityConfigureAdapter设置,您可以在本文末尾看到。通过这个设置,我得到了所有/api/*请求和/j_spring_安全检查的403 有人能帮我修复我现有的配置,或者给我一个可以实现这一点的工作示例吗 我看到的每个示例似乎都要求用户进行身份验证,如果他们不进行身份验证,则抛出403。在我的应用程序中,我只是用它来建立一个会话

我很难弄清楚如何在不强制认证的情况下连接spring安全性。我的特定应用程序不要求用户进行身份验证,但用户可以根据需要进行身份验证

我目前有一个WebSecurityConfigureAdapter设置,您可以在本文末尾看到。通过这个设置,我得到了所有/api/*请求和/j_spring_安全检查的403

有人能帮我修复我现有的配置,或者给我一个可以实现这一点的工作示例吗

我看到的每个示例似乎都要求用户进行身份验证,如果他们不进行身份验证,则抛出403。在我的应用程序中,我只是用它来建立一个会话,在这一点上,所有用户都应该能够访问所有端点,无论他们是否经过身份验证

网站安全配置

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private ItAuthenticationProvider customAuthenticationProvider;


    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) {
        auth.authenticationProvider(customAuthenticationProvider);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().authorizeRequests().antMatchers("/**").permitAll()
                .antMatchers("/j_spring_security_check").permitAll()
                .and().formLogin()
                .loginProcessingUrl("/j_spring_security_check")
                .defaultSuccessUrl("/successful.html")
                .loginPage("/#login")
                .permitAll()
                .and()
                .logout()
                .logoutSuccessUrl("/successful.html");
    }
}

如果我了解您的要求,您可以使用匿名身份验证。
文档可以在中找到

您可以查看我们在支持下构建的Spring Security应用程序。在此示例中,主屏幕不需要身份验证。此外,此处显示的信息是根据用户是否经过身份验证而动态计算的。

不是您想要的,但以下链接可能会有所帮助。。