【发布时间】: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");
}
}
【问题讨论】:
-
不是您想要的,但以下链接可能会有所帮助.. stackoverflow.com/questions/29454078/…
标签: java spring spring-mvc authentication spring-security