我有一個Spring Boot應用程序,我使用的是Spring Security(4.0.4)。Spring Security 4:如何忽略尾部斜槓
端點的當前安全配置(以Java爲單位)允許調用/some/endpoint
,但不允許調用/some/endpoint/
。
我已經在這裏搜索過,但我沒有看到任何東西像開關忽略尾隨空格。例如,Spring MVC的,我可以做到以下幾點:
@Configuration
public class ServletConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(final PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(false);
}
}
當然,上面的代碼改變了我想要的行爲相反的,但它只是作爲的想什麼我做示範Spring Security。
我的(減少)的安全配置:
@Bean
public ResourceServerConfigurer resourceServerConfigurer(final ScopesProperties oauthProperties) {
return new ResourceServerConfigurerAdapter() {
@Override
public void configure(final HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(NEVER).and()
.authorizeRequests()
.antMatchers(GET, "/foo")
.access(oauthProperties.getFooRead())
.antMatchers(GET, "/bar/*")
.access(oauthProperties.getBarRead())
.antMatchers(PUT, "/bar/*")
.access(oauthProperties.getBarWrite())
// everything else
.anyRequest().denyAll();
}
我知道我可以使用正則表達式匹配器,我想避免的,主要是出於同樣的原因它,因爲我想避免一個額外的規則爲每個端點只是批准具有結尾斜槓的同一端點。我必須爲每個端點執行此操作,這很容易出錯。我也知道我可以使用ant匹配器並將路徑設置爲/foo/**
。與此問題是當我想控制不同範圍的子資源。
所以問題是:如何告訴Spring Security全局忽略尾隨斜線?
在此先感謝