question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addGroupingPolicy API interface bug

See original GitHub issue

When using this interface enforcer. addGroupingPolicy (“member”, “group”) to add user to an group, occured java.lang.NullPointerException:

dependencies pom

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>jcasbin</artifactId>
    <version>1.31.1</version>
</dependency>

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>jdbc-adapter</artifactId>
    <version>2.3.3</version>
</dependency>

model.conf

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act

Application

JDBCAdapter adapter = new JDBCAdapter(driver, url, username, password);
String modelPath = "src/main/resources/cabin/model.conf";

Enforcer enforcer = new Enforcer(modelPath, adapter);

enforcer.addPolicy("admin", "/books", "READ");
boolean policy = enforcer.addGroupingPolicy("tony", "admin");  // Exception in thread "main" java.lang.NullPointerException

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
imp2002commented, Nov 8, 2022

I took a look and found that this is not a bug, acutrally addGroupingPolicy() is a role inheritance, so in model.conf should include a [role_definition] just look like follows.

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
1reaction
imp2002commented, Nov 7, 2022

Verified, I will fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not add role for a user in case g = _, _, _ #25 - GitHub
it accepts user and role, but all it does is just passing them by to addGroupingPolicy which also has hard-coded user and role....
Read more >
Simplified identity with 'Sign-in with Google' and Casbin
Combining “Sign in with Google” with Casbin you can add authentication and authorization to a Cloud Run service without using any identity provider...
Read more >
casbin package - github.com/seacoastboy/casbin - Go Packages
Enforcer is the main interface for authorization enforcement and policy management. ... func (e *Enforcer) AddGroupingPolicy(params ...interface{}) bool.
Read more >
Management API | Casbin
The primitive API that provides full support for Casbin policy management. ... AddGroupingPolicy adds a role inheritance rule to the current policy.
Read more >
changelog - Debian Package Tracker
Bug fixes: * Install new Essential or Required packages with the commands "full-upgrade" (command line) and MarkUpgradable ('U' in the curses interface) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found