使用 Spring EL 的复杂表达式(条件和括号)

mru*_*lan 6 spring spring-security spring-el

我正在使用具有弹簧安全性的 spring-EL

是否可以使用括号制作“复杂”的条件表达式?

@PreAuthorize("( hasRole('ROLE_USER') and ( isOwnerDocumentUUID( #docUuids ) ) or hasRole('ROLE_ADMIN')  ")
Run Code Online (Sandbox Code Playgroud)

抛出一个 java.lang.IllegalArgumentException:

解析表达式失败

@PreAuthorize("hasRole('ROLE_USER') and ( isOwnerDocumentUUID( #docUuids ) ")
Run Code Online (Sandbox Code Playgroud)

被接受。

axt*_*avt 6

你有一个额外的(,以下应该工作:

@PreAuthorize("( hasRole('ROLE_USER') and isOwnerDocumentUUID( #docUuids ) ) or hasRole('ROLE_ADMIN')  ") 
Run Code Online (Sandbox Code Playgroud)