casbin / jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
https://casbin.org
Apache License 2.0
2.38k stars 461 forks source link

ClassCastException for Strings within grouping fucntions #254

Closed pza94 closed 2 years ago

pza94 commented 2 years ago

Hi there,

I created a matcher that extracts a string from a given request object, and checks if that is in a given group:

g4(keyGet2(r.obj, "/customer/:cid/*", "cid"), p.dom )

When I try to call enforce it throws a ClassCastException.

java.lang.ClassCastException: <String, > is not a javaType

    at com.googlecode.aviator.runtime.function.FunctionUtils.getJavaObject(FunctionUtils.java:107)
    at org.casbin.jcasbin.util.BuiltInFunctions$1.variadicCall(BuiltInFunctions.java:354)
    at com.googlecode.aviator.runtime.function.AbstractVariadicFunction.call(AbstractVariadicFunction.java:71)
    at Script_1644402524748_59/70807318.execute0(Script_1644402524748_59:1)
    at com.googlecode.aviator.ClassExpression.executeDirectly(ClassExpression.java:44)
    at com.googlecode.aviator.BaseExpression.execute(BaseExpression.java:237)
    at org.casbin.jcasbin.main.CoreEnforcer.enforce(CoreEnforcer.java:478)
    at org.casbin.jcasbin.main.CoreEnforcer.enforce(CoreEnforcer.java:590)
    at com.w.platform.rbac.MCEnforcer.enforce(MCEnforcer.java:95)

I made some investigation myself, I found that the g(rouping)-function expects that the arguments are AviatorJavaObjects (fx. p.dom) and just fails when it receives a raw string. But keyGet2 returns string so it feels that it is impossible to use keyGet2 within a group match function.

PS. the exact same configuration: same policies, groups, model, request works as intended in the online editor, https://casbin.org/en/editor/

casbin-bot commented 2 years ago

@tangyang9464 @seriouszyx @elfisworking @fangzhengjin

hsluoyz commented 2 years ago

@seriouszyx @Abingcbc @fabian4

tangyang9464 commented 2 years ago

@hsluoyz @pza94 soloved by #265