大家好,当我在Intellij上运行我的项目时,我遇到以下问题,但是当我使用maven install进行构建并运行我的项目时,就会出现此问题。
[无法计算表达式'isAuthenticated()
&& isPermitted('domain:read:*')'] [1] [1]:https://i.stack.imgur.com/LkaY6.png
我的代码
@PreAuthorize("isAuthenticated() && isPermitted('domain:read:*')")
@GetMapping(produces = [(MediaType.APPLICATION_JSON_VALUE)])
fun search(query: DomainQuery): ResponseEntity<ArpiaPage<DomainOutput>> {
val retval = service.search(query)
return ResponseEntity(
retval.map { domain -> converter.convert(domain, DomainOutput::class.java) },
HttpStatus.OK
)
}
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled=true)
class ShiroMethoSecurityConfig : GlobalMethodSecurityConfiguration() {
override fun createExpressionHandler(): MethodSecurityExpressionHandler {
return ShiroMethodSecurityExpressionHandler()
}
}
class ShiroMethodSecurityExpressionHandler : DefaultMethodSecurityExpressionHandler() {
private val trustResolver = AuthenticationTrustResolverImpl()
override fun createSecurityExpressionRoot(authentication: Authentication, invocation: MethodInvocation): MethodSecurityExpressionOperations {
return ShiroMethodSecurityExpressionRoot(authentication).apply {
setPermissionEvaluator(permissionEvaluator)
setTrustResolver(trustResolver)
setRoleHierarchy(roleHierarchy)
}
}
}
open class ShiroMethodSecurityExpressionRoot(authentication: Authentication) : SecurityExpressionRoot(authentication), MethodSecurityExpressionOperations {
private var filterObject: Any? = null
private var returnObject: Any? = null
private var target: Any? = null
private val LOG = LoggerFactory.getLogger(ShiroMethodSecurityExpressionRoot::class.java)
override fun setFilterObject(filterObject: Any) {
this.filterObject = filterObject
}
override fun getFilterObject(): Any? {
return filterObject
}
override fun setReturnObject(returnObject: Any) {
this.returnObject = returnObject
}
override fun getReturnObject(): Any? {
return returnObject
}
/**
* Sets the "this" property for use in expressions. Typically this will be the "this"
* property of the `JoinPoint` representing the method invocation which is being
* protected.
*
* @param target the target object on which the method in is being invoked.
*/
fun setThis(target: Any) {
this.target = target
}
override fun getThis(): Any? {
return target
}
@Bean
open fun isPermitted(permission: String?): Boolean {
return true
}
@Bean
fun isPermitted(vararg permissions: String): Boolean {
return try {
val permissionObjects = permissions.map { permission -> WildcardPermission(permission) }
val user = this.principal as AuthAccount
//true
permissionObjects.all {
user.permissions.any { permission ->
permission.implies(it)
}
}
} catch (e: Exception) {
e.printStackTrace()
LOG.debug("", e)
throw (e)
}
}
}
答案 0 :(得分:0)
请尝试在逻辑运算符“ &&”的位置使用文本“ and”。我相信@PreAuthorize批注中,您需要提供文本以结合多项检查