【发布时间】:2018-11-20 01:40:06
【问题描述】:
我想允许在特定控制器中定义的所有 url,除了一个。
假设我的控制器公开了 3 个带有基本 url /users 的 url
- “/”列出所有用户
- "/{id}" 按 id 列出用户
- “/admin”获取用户的管理员级别详细信息。
我想允许除最后一个用户之外的任何用户访问 1 和 2 个 url。
我一直在做这样的事情
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.pathMatchers("/users/**")
.permitAll()
.pathMatchers("/users/admin")
.hasRole("ADMIN")
.anyExchange()
.authenticated()
.and()
.httpBasic()
.and()
.formLogin();
return http.build();
}
但它不起作用。我也尝试过相反的方法,即
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.pathMatchers("/users/admin")
.hasRole("ADMIN")
.anyExchange()
.authenticated()
.pathMatchers("/users/**")
.permitAll()
.and()
.httpBasic()
.and()
.formLogin();
return http.build();
}
这也不起作用,因为anyExchange() 已经注册,所以无法访问下一个pathMatcher。
【问题讨论】:
标签: java spring spring-security spring-webflux