【发布时间】:2018-01-15 10:35:54
【问题描述】:
我正在尝试使用 Spring Security 来保护使用 JWT 令牌的休息/无状态 api。从我看到的研究来看,它涉及关闭 spring 安全会话管理,然后添加一些自定义过滤器来处理用户登录以及检查 jwt 令牌。
我遇到的问题是,一旦我添加了一个过滤器,它就会在每一个而不是我想要它的端点上运行。我需要打开登录端点以及其他一些有助于注册和参考不需要保护的数据的端点。
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/api/user").permitAll()
.anyRequest().authenticated().and()
.addFilterBefore(new StatelessAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
;
}
}
StatelessAuthenticationFilter 所做的只是打印“in here”。我只希望在您转到 localhost:8080/api/order 时看到该消息打印,但是当您转到 localhost:8080/api/user 时我看到它显示出来。
有没有办法获得这种行为?
【问题讨论】:
标签: java spring spring-mvc spring-security