casbin / jcasbin

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

Not able to use loadFilteredPolicy with JdbcAdatper in Jcasbin #128

Closed shreyasGit closed 3 years ago

shreyasGit commented 3 years ago

i think theres an issue in Jcasbin java version 1.6.3 and older , it does not support filtering on jdbc adapter, when i try to use https://github.com/jcasbin/casbin-spring-boot-starter with jcasbin, i see that in CoreEnforcer , it expects FilterAdapter only from file_adapter package, else throws this eroor.in short cannot use any jdbc adapter with Jcasbin

* loadFilteredPolicy reloads a filtered policy from file/database.
 *
 * @param filter the filter used to specify which type of policy should be loaded.
 */
public void loadFilteredPolicy(Object filter) {
    model.clearPolicy();
    FilteredAdapter filteredAdapter;
    if (adapter instanceof FilteredAdapter) {
        filteredAdapter = (FilteredAdapter) adapter;
    } else {
        throw new CasbinAdapterException("Filtered policies are not supported by this adapter.");
    }

in above code FilteredAdapter should be referenced from org.casbin.jcasbin.persist package which is a parent interface. Due to this when i try to use any jdbcadapter to filter policies i get an error "Filtered policies are not supported by this adapter."

hsluoyz commented 3 years ago

@shy1st plz take a look.

hsluoyz commented 3 years ago

@shreyasGit fixed and released: https://github.com/casbin/jcasbin/releases/tag/v1.6.4

shreyasGit commented 3 years ago

this is not fixednow i get following error Exception in thread "main" java.lang.ClassCastException: org.casbin.adapter.JdbcAdapter cannot be cast to org.casbin.jcasbin.persist.file_adapter.FilteredAdapter at org.casbin.jcasbin.main.CoreEnforcer.loadFilteredPolicy(CoreEnforcer.java:241) at com.sas.mkt.example.controller.DumpDataUtil.main(DumpDataUtil.java:58)

  if (adapter instanceof org.casbin.jcasbin.persist.FilteredAdapter) {
        filteredAdapter = (FilteredAdapter) adapter;

the cast is not needed

shy1st commented 3 years ago

@shreyasGit Would you mind show me your code of how you create the JdbcAdapter?

hsluoyz commented 3 years ago

ping @shreyasGit

hsluoyz commented 3 years ago

@shreyasGit @shy1st I think I found the cause.

The latest version of casbin-spring-boot-starter was released 15 days ago: https://github.com/jcasbin/casbin-spring-boot-starter/releases/tag/0.0.11

However, latest jCasbin was released 10 days ago: https://github.com/casbin/jcasbin/releases/tag/v1.6.4

So we need to update casbin-spring-boot-starter's POM dependency to use jCasbin v1.6.4. @shy1st can you make a PR for it?

shy1st commented 3 years ago

@hsluoyz yes,I can.

shy1st commented 3 years ago

@shreyasGit @shy1st I think I found the cause.

The latest version of casbin-spring-boot-starter was released 15 days ago: https://github.com/jcasbin/casbin-spring-boot-starter/releases/tag/0.0.11

However, latest jCasbin was released 10 days ago: https://github.com/casbin/jcasbin/releases/tag/v1.6.4

So we need to update casbin-spring-boot-starter's POM dependency to use jCasbin v1.6.4. @shy1st can you make a PR for it?

@hsluoyz Please see: https://github.com/jcasbin/casbin-spring-boot-starter/pull/26

hsluoyz commented 3 years ago

@shy1st merged, plz make a new release of https://github.com/jcasbin/casbin-spring-boot-starter

hsluoyz commented 3 years ago

@shreyasGit can you see if v0.0.12 fixed this issue? https://github.com/jcasbin/casbin-spring-boot-starter/releases/tag/0.0.12

shy1st commented 3 years ago

The v0.0.12 of the casbin-spring-boot-starter had released in the maven repository.

hsluoyz commented 3 years ago

@shreyasGit fixed in: https://github.com/casbin/jcasbin/pull/153