简体   繁体   English

春季安全@PreAuthorize

[英]Spring Security @PreAuthorize

I'm trying to access the current active profile via the Spring Security @PreAuthorize annotation like 我正在尝试通过Spring Security @PreAuthorize注释访问当前的活动配置文件

@PreAuthorize("hasRole('SOME_' + #{ environment.activeProfiles[0] } + '_ROLE')")

I'm receiving the following exception: 我收到以下异常:

EL1043E: Unexpected token. EL1043E:意外的令牌。 Expected 'identifier' but was 'lcurly({)' 预期为“标识符”,但为“ lcurly({)”

Is there a way to do this without writing a custom expression handler? 没有编写自定义表达式处理程序的方法吗?

Got it working in a convoluted way. 使它以令人费解的方式工作。 Seems like it should be more straightforward. 似乎应该更直接。 This feels like a hack: 感觉就像是骇客:

@PreAuthorize("hasRole('SOME_' + #profile + '_ROLE')")
public void method(@Value("#{ environment.getActiveProfiles()[0]?.toUpperCase() }") String profile)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM