我尝试配置Spring Security。我有以下配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/auth**").permitAll()
.and()
.authorizeRequests()
.antMatchers("/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.userDetailsService(userDetailsService());
}我可以向以"/auth“开头的链接发送get-request,但没有身份验证就不能发送post-request。如果我删除了下面的代码,一切都是正常的:
.authorizeRequests()
.antMatchers("/**").authenticated()
.anyRequest().permitAll()但我需要对任何页面进行身份验证,除了"/auth**“
发布于 2017-04-12 00:34:22
一个非常晚的答案,但像大多数人一样,我讨厌没有答案的问题。我想您是在问如何防止对/auth**进行身份验证。
您应该覆盖其他配置方法:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(HttpMethod.POST, "/auth/**");
}这将不会对该URL执行任何身份验证。换句话说,它是一个公共URL,例如,人们可以通过它发布一个提醒密码请求。
https://stackoverflow.com/questions/31832148
复制相似问题