【发布时间】:2021-06-01 15:56:03
【问题描述】:
我有一个场景,我必须实施 Spring Security 来保护已经存在的其他端点中的新端点。
我目前的配置如下:
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.csrf().requireCsrfProtectionMatcher(new CsrfRequestMatcher())
.and()
.sessionManagement().invalidSessionUrl("/invalidSession")
.and()
.sessionManagement().maximumSessions(1).expiredUrl("/expiredSession").and()
.and()
.authorizeRequests()
.antMatchers("/user/manage/*").authenticated()
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/user/login").permitAll()
.defaultSuccessUrl("/user/manage")
.and()
.logout().permitAll();
}
我的要求是仅对 /user/manage/* 路径强制执行上述 spring 安全配置。但是,我注意到我的应用程序中的其他 mvc 端点会导致重定向到 /invalidSessions URL。
我希望其他端点按原样工作,并完全禁用这些端点的 Spring Security(以及会话管理指令)。我知道这样做的唯一地方是在提供的其他配置覆盖中,但它并不完全符合我的需要:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/cof/manage/*"); //need something like NOT "/cof/manage/*"
}
上面的忽略可以在每个 url 的基础上完成,但不可能禁用除给定 URL 之外的所有 URL。除了“/cof/manage/*”路径之外,我唯一的选择是列出我的应用程序中当前存在的所有 MVC 端点吗?
谢谢
【问题讨论】:
标签: spring spring-mvc spring-security