jan*_*lan 2 java rest spring-security spring-boot
当使用 Postman 或从 Angular 前端发出请求时,200 OK即使在错误的路线上,我总是从后端得到空白/空响应。
安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
Run Code Online (Sandbox Code Playgroud)
例如,检查用户名是否被占用:
@GetMapping("/available")
public Boolean isUsernameTaken(@RequestParam String username) {
return userService.isUsernameTaken(username);
}
Run Code Online (Sandbox Code Playgroud)
甚至没有进入这个方法,但返回的代码是200.
在错误的端点上发出请求http://localhost:8080/fakeEndpoint/xxxxx也会返回空白页和代码 200。
问题出在扩展的自定义过滤器类中OncePerRequestFilter。执行了覆盖doFilterInternal()方法,但没有链接过滤 - 我没有filterChain.doFilter(httpServletRequest, httpServletResponse)在此方法结束时调用。
| 归档时间: |
|
| 查看次数: |
1072 次 |
| 最近记录: |