EL1004E:方法调用:在MethodSecurityExpressionRoot类型上找不到方法isPermitt(java.lang.String)

EL1004E:方法调用:在MethodSecurityExpressionRoot类型上找不到方法isPermitt(java.lang.String),java,spring-boot,kotlin,Java,Spring Boot,Kotlin,大家好,当我在Intellij上运行我的项目时,我遇到了以下问题,一切正常,但是当我使用maven进行构建时,安装并运行我的项目会出现这个问题 [计算表达式'isAuthenticated()失败] &&isPermitted('域:已读:'')][1] [1] : 我的代码 @PreAuthorize("isAuthenticated() && isPermitted('domain:read:*')") @GetMapping(produces

大家好,当我在Intellij上运行我的项目时,我遇到了以下问题,一切正常,但是当我使用maven进行构建时,安装并运行我的项目会出现这个问题

[计算表达式'isAuthenticated()失败]

&&isPermitted('域:已读:'')][1] [1] :

我的代码

 @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)
        }
    }


}
@PreAuthorize(“isAuthenticated()&&isPermitted('domain:read::'))
@GetMapping(products=[(MediaType.APPLICATION\u JSON\u VALUE)])
趣味搜索(查询:域名查询):响应性{
val retval=service.search(查询)
返回响应性(
retval.map{domain->converter.convert(domain,DomainOutput::class.java)},
HttpStatus.OK
)
}
@配置
@EnableGlobalMethodSecurity(Prespenabled=true)
类ShiromethosecurityConfiguration:GlobalMethodSecurityConfiguration(){
重写createExpressionHandler():MethodSecurityExpressionHandler{
return ShiroMethodSecurityExpressionHandler()
}
}
类ShiroMethodSecurityExpressionHandler:DefaultMethodSecurityExpressionHandler(){
private val trustResolver=AuthenticationTrustResolverImpl()
重写createSecurityExpressionRoot(身份验证:身份验证,调用:MethodInvocation):MethodSecurityExpressionOperations{
返回ShiroMethodSecurityExpressionRoot(身份验证)。应用{
setPermissionEvaluator(permissionEvaluator)
setTrustResolver(信任解析程序)
setRoleHierarchy(roleHierarchy)
}
}
}
开放类ShiroMethodSecurityExpressionRoot(身份验证:身份验证):SecurityExpressionRoot(身份验证),MethodSecurityExpressionOperations{
私有变量筛选器对象:有吗?=null
private var returnObject:有吗?=null
私有变量目标:有吗?=null
private val LOG=LoggerFactory.getLogger(ShiroMethodSecurityExpressionRoot::class.java)
覆盖fun setFilterObject(filterObject:Any){
this.filterObject=filterObject
}
覆盖有趣的getFilterObject():有吗{
返回过滤器对象
}
重写fun setReturnObject(returnObject:Any){
this.returnObject=returnObject
}
覆盖有趣的getReturnObject():有吗{
返回对象
}
/**
*设置表达式中使用的“this”属性。通常为“this”
*表示正在执行的方法调用的'JoinPoint'的属性
*受保护。
*
*@param target调用中方法的目标对象。
*/
乐趣集此(目标:任何){
this.target=target
}
有吗{
返回目标
}
@豆子
OpenFunisPermitted(权限:字符串?):布尔值{
返回真值
}
@豆子
fun isPermitted(vararg权限:字符串):布尔值{
回击{
val permissionObjects=permissions.map{permission->wildcardpmission(permission)}
val user=this.principal作为AuthAccount
//真的
许可对象。全部{
user.permissions.any{permission->
允许。暗示(它)
}
}
}捕获(e:例外){
e、 printStackTrace()
LOG.debug(“,e)
投掷(e)
}
}
}

尝试使用text'和'代替逻辑运算符'&&'。我相信@PreAuthorize注释,您需要提供文本来组合多个检查

显而易见的原因是它使用了一个或多个Spring库的不同版本。你是如何运作这个项目的?依赖项是否已编译到jar/war中?如果没有,从何处获取它们?感谢您的回复,这些依赖项已编译到jar中并使用java-jar运行我的项目,我使用的是spring boot 2.3.3。此外,如果我运行命令mvn spring boot:run一切正常,但我运行的是mvn package或mvn install,然后是java-jar mybundle.jar,则应用程序抛出错误。不幸的是,它不起作用,如果我在intellij中运行我的应用程序,那么在创建捆绑包时就会出现问题,但当我使用以下命令mvn clean install创建捆绑包并使用java-jar my_bundle.jar运行我的应用程序时,错误立即出现