禁用特定路径的弹簧安全性

时间:2017-08-10 16:47:44

标签: spring-boot spring-security

我知道之前已经回答了这个问题,但我似乎无法让它发挥作用:

我有一个自定义JWT过滤器,并尝试允许未经身份验证的调用特定的休息路径:

以下是WebConfig中的代码:

protected void configure(HttpSecurity http) throws Exception
{
    http.csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and().
            sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http.authorizeRequests().antMatchers("/api/documents/fax").permitAll()
            .and().authorizeRequests().anyRequest().authenticated().and()
    .addFilterBefore(authenticationFilterBean(), AnonymousAuthenticationFilter.class);

}

如果我呼叫传真路径,我最终进入JWT过滤器

我也试过这个:

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

在日志中给出了这个:

2017-08-10 12:32:06.245  INFO 12258 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: Ant [pattern='/api/documents/fax**'], []

但结果相同。最后我尝试了两个代码块,结果相同。

我也有这个注释:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter

我试过没有EnableGlobalMethodSecurity注释,没有工作 谢谢你的帮助...

0 个答案:

没有答案