【问题标题】:Spring Security Java Config without Forcing Auth没有强制身份验证的 Spring Security Java Config
【发布时间】:2015-07-09 15:22:29
【问题描述】:

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

我目前有一个 WebSecurityConfigurerAdapter 设置,您可以在本文末尾看到。通过这个设置,我在所有 /api/* 请求和 /j_spring_security_check 上都得到了 403。

有人可以帮我修复我现有的配置,或者指出一个可以完成此任务的工作示例吗?

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

WebSecurityConfig

@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");
    }
}

【问题讨论】:

标签: java spring spring-mvc authentication spring-security


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 2015-02-14
      • 2017-04-28
      • 2022-01-15
      • 2014-02-26
      • 1970-01-01
      相关资源
      最近更新 更多