angular - Springboot WebSecurityConfig 忽略过滤器
问题描述
我的问题是,当我登录时,spring boot security 已经要求提供一个不记名令牌,而它还不存在。因此,过滤器不应使用特定请求执行,在我的情况下是 /authenticate
WebSecurityConfig.java
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
// We don't need CSRF for this example
httpSecurity.csrf().disable()
// dont authenticate this particular request
.authorizeRequests().antMatchers(HttpMethod.POST, "/authenticate", "/register").permitAll().
// all other requests need to be authenticated
anyRequest().authenticated().and().
// make sure we use stateless session; session won't be used to
// store user's state.
exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// Add a filter to validate the tokens with every request
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
但是使用这种方法,过滤器总是在任何请求上执行,也不是意图的 /authenticate。
解决方案
推荐阅读
- python-3.x - 将流式 JSON 转换为 DataFrame
- html - angular和nativescript的结合
- node.js - 在 Mongoose 中调用 modal.countDocuments() 和 modal.count() 时出现投射错误
- javascript - 当用户手动向上或向下滚动时重置当前部分计数器
- algorithm - 如何证明均匀分区是快速排序算法的最佳情况?
- android - 使用 java.io.IOException 不生成测试覆盖率报告
- c# - 抛出异常:UWP 后台任务中未知模块中的“System.TypeLoadException”
- c# - 使用 C# 在 MVVM 中使用组合框和按钮单击事件的不同方法?
- node.js - node-postgres 监听/通知超时
- android - 将数据从一个活动的 EditText 传输到另一个活动的 EditText