如何不在不安全的控制器之前调用 OncePerRequestFilter
我正在关注 示例< /a> 有 代码<我根据 href="https://stackoverflow.com/questions/36795894/how-to-apply-spring-security-filter-only-on-secured-endpoints">spring-security-filter-only-on-secured-endpoints 。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/secureSide/**")
.cors().and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and().addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.csrf().disable()
.formLogin().disable()
.httpBasic().disable()
.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint())
.and().authorizeRequests()
.anyRequest().authenticated();
}
和两个独立的控制器 但是
@RestController
@RequestMapping("/secureSide")
@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
public class SecureController {
...
}
@RestController
@RequestMapping("/completelyOpen")
public class OpenController {
...
}
当客户端调用 OpenController 中定义的端点时, doFilterInternal 仍然被调用,即使应该为 SecureController 调用过滤器
那么如何调用 doFilterInternal ( ofTokenFilter extends OncePerRequestFilter )被阻止?
I am following an example that has code that I modified per spring-security-filter-only-on-secured-endpoints
.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/secureSide/**")
.cors().and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and().addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.csrf().disable()
.formLogin().disable()
.httpBasic().disable()
.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint())
.and().authorizeRequests()
.anyRequest().authenticated();
}
and two Separate controllers
as
@RestController
@RequestMapping("/secureSide")
@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
public class SecureController {
...
}
@RestController
@RequestMapping("/completelyOpen")
public class OpenController {
...
}
But when end points defined in OpenController are called by the client, the doFilterInternal still gets called, even though the filter are supposed to be called for SecureController
So how can the call to doFilterInternal ( ofTokenFilter extends OncePerRequestFilter ) be prevented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论