【发布时间】:2020-11-26 11:14:31
【问题描述】:
我正在使用 Spring 安全策略,需要全局角色 SUPER 的帮助,当令牌拥有它时,该角色必须绕过端点上的所有 @PreAuthorize。这是一个端点示例:
@GetMapping
@PreAuthorize("(hasAuthority('DOMAIN_FIND_ALL'))")
public ResponseEntity<ResponseDTO<List<DomainDTO>>> findAll() {
return ResponseEntity.ok().body(domainService.findAll());
}
我为我的全球角色找到的工作方式是这样的
@GetMapping
@PreAuthorize("(hasAuthority('DOMAIN_FIND_ALL') or (hasAuthority('SUPER'))")
public ResponseEntity<ResponseDTO<List<DomainDTO>>> findAll() {
return ResponseEntity.ok().body(domainService.findAll());
}
但是对于实现(hasAuthority('SUPER') 应用程序的每个端点来说太长了,所以我正在寻找一种以全局方式配置它的方法,这样,如果令牌具有该角色,则允许所有端点。
我尝试过的:
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.otherStuffs..
.antMatchers("/**").authenticated()
.antMatchers("/**").hasRole("SUPER");
}
但它不起作用。有人对此有任何想法吗?
【问题讨论】:
标签: java spring spring-security authorization