Spring boot @与自定义JWT属性的预授权比较

Spring boot @与自定义JWT属性的预授权比较,spring-boot,spring-security,Spring Boot,Spring Security,我正在尝试使用KeyClope 8.0.1保护Spring Boot 2.2.2应用程序 JWT令牌如下所示(请注意额外的customer_id字段): 我想保护这个入口点: // eg.: http://localhost:9000/customers/first @GetMapping(@Path path = "/customers/{customerId}") @PreAuthorize("hasPermission(????.customer_id == #customerId) pu

我正在尝试使用KeyClope 8.0.1保护Spring Boot 2.2.2应用程序

JWT令牌如下所示(请注意额外的customer_id字段):

我想保护这个入口点:

// eg.: http://localhost:9000/customers/first
@GetMapping(@Path path = "/customers/{customerId}")
@PreAuthorize("hasPermission(????.customer_id == #customerId)
public Object customerEntryPoint(@PathVariable String customerId) {
    ...
}

什么是合适的@PreAuthorization表达式,因此我将令牌中的“customer\u id”字段与提供的customerId参数进行比较

两小时后,我设法找到了一个不太优雅的解决方案:

@PreAuthorize("principal.keycloakSecurityContext.token.getOtherClaims().get('customer_id')==#customerId")
如果有人能提供更优雅的解决方案,我将不胜感激

@PreAuthorize("principal.keycloakSecurityContext.token.getOtherClaims().get('customer_id')==#customerId")