Code Monkey home page Code Monkey logo

Comments (6)

casbin-bot avatar casbin-bot commented on May 21, 2024

@tangyang9464 @imp2002

from casbin-spring-boot-starter.

hsluoyz avatar hsluoyz commented on May 21, 2024

@tunctolgahan hi, can you run this example: https://github.com/jcasbin/casbin-spring-boot-example (which uses this casbin-spring-boot-starter)? Does it work?

Did you use another Jedis version in your own project?

from casbin-spring-boot-starter.

tunctolgahan avatar tunctolgahan commented on May 21, 2024

Hi, thanks for your reply. I am a bit busy this week, check it ASAP and let you know.

For your Jedis version question, yes I use more up-to-date version of it in my own project.

from casbin-spring-boot-starter.

tunctolgahan avatar tunctolgahan commented on May 21, 2024

Hi again,

First, I checked the jedis version I use in my own project, it is 4.3.1. And my own project use maven, not gradle.

Second, the example project ran well. I checked all the endpoints defined in it, all returned HTTP 200.

After everything seems OK, I enabled both enableWatcher and use-synced-enforcer. Also I configured spring redis dependency manually (as described in readme file of this repo).

casbin:
  storeType: file
  enableWatcher: true
  use-synced-enforcer: true

spring:
  redis:
    database: 0
    host: localhost
    port: 6379

Then, I created my own endpoints (in DataController) that adds a new policy to casbin db, and returning all policies:

  @Secured("ROLE_ADMIN")
  @PostMapping("/admins/add-policy")
  public ResponseEntity<Data> addPolicy(Authentication authentication) {
    logger.info("addPolicy called");

    List<String> policy = new ArrayList<>();
    policy.add("p");
    policy.add("ROLE_ADMIN");
    policy.add("/data/admins/add-policy");
    policy.add("*");

    enforcer.addPolicy(policy);

    return ResponseEntity.ok().build();
  }

  @Secured("ROLE_ADMIN")
  @GetMapping("/admins/get-all-policies")
  public ResponseEntity<List<List<String>>> getAllPolicies(Authentication authentication) {
    logger.info("getAllPolicies called");
    
    List<List<String>> policies = enforcer.getPolicy();

    return ResponseEntity.ok().body(policies);
  }

When I called /add-policy and /get-all-policies endpoints from postman, I got this log output.
Please see the highlighted line "Method not implemented". Why I got this message? I think this is not something about watcher or synced-enforcer configure, because when I disabled both of them I got the same message after calling /add-policy.

org.casbin.jcasbin                       : Request: [admin, /data/admins/add-policy, POST] ---> true
org.casbin.jcasbin                       : Hit Policy: [ROLE_ADMIN, /data/admins/*, *]
org.casbin.config.CasbinFilter           : session is authorized: B11F208EC2077C80DABBC800DBAAA4F4 admin POST /data/admins/add-policy
org.casbin.controller.DataController     : addPolicy called
org.casbin.jcasbin                       : ****Method not implemented****

org.casbin.jcasbin                       : Request: [admin, /data/admins/get-all-policies, GET] ---> true
org.casbin.jcasbin                       : Hit Policy: [ROLE_ADMIN, /data/admins/*, *]
org.casbin.config.CasbinFilter           : session is authorized: B11F208EC2077C80DABBC800DBAAA4F4 admin GET /data/admins/get-all-policies
org.casbin.controller.DataController     : getAllPolicies called

Also, /admins/get-all-policies returned the all policies as expected (the last policy is the policy I added via endpoint):

[
    [
        "ROLE_USER",
        "/data/users/*",
        "*"
    ],
    [
        "ROLE_ADMIN",
        "/data/users/*",
        "*"
    ],
    [
        "ROLE_ADMIN",
        "/data/admins/*",
        "*"
    ],
    **[
        "p",
        "ROLE_ADMIN",
        "/data/admins/add-policy",
        "*"
    ]**
]

I think there is something wrong with redis/watcher structure on this example project too. Because on redis server, when I checked the "connected client list", I don't see any.

from casbin-spring-boot-starter.

imp2002 avatar imp2002 commented on May 21, 2024

Yes, it's seems jedis-client version is incompatible with the Spring Data Redis, Compatible versions are available here, you can switch to you version to see
image

try downgraded or upgraded version, or try use the default client in spring-boot-data-redis.

Does example invalid? Did you manually introduce the dependency?

image

from casbin-spring-boot-starter.

hsluoyz avatar hsluoyz commented on May 21, 2024

Closed as resolved

from casbin-spring-boot-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.