Skip to content

Add getAllowedObjectConditions() API#492

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/add-get-allowed-object-conditions-api
Closed

Add getAllowedObjectConditions() API#492
Copilot wants to merge 3 commits intomasterfrom
copilot/add-get-allowed-object-conditions-api

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Ports the GetAllowedObjectConditions() API from Go Casbin (commit 6b2c686) to jCasbin. This API retrieves object conditions that a user can access based on their permissions and inherited roles, enabling data adapters to generate filtered ORM queries.

Implementation

  • New API method getAllowedObjectConditions(String user, String action, String prefix) in Enforcer.java

    • Retrieves implicit permissions for user (including inherited roles)
    • Filters by action and validates prefix requirement
    • Returns list of object conditions with prefix stripped
  • Exception types for error handling

    • CasbinObjectConditionException - thrown when object condition lacks required prefix
    • CasbinEmptyConditionException - thrown when no conditions match (prevents ORMs from returning full table)
  • Test resources object_conditions_model.conf and object_conditions_policy.csv

Example Usage

Enforcer e = new Enforcer("examples/object_conditions_model.conf", 
                          "examples/object_conditions_policy.csv");

// Alice has role "admin" which grants access to category_id = 2
// Alice also has direct permission for price < 25
List<String> conditions = e.getAllowedObjectConditions("alice", "read", "r.obj.");
// Returns: ["price < 25", "category_id = 2"]

// Can be used to generate ORM query: WHERE price < 25 OR category_id = 2
Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] add GetAllowedObjectConditions() API</issue_title>
<issue_description>Need to port this API from Go Casbin to Java

refer to commit: casbin/casbin@6b2c686 (issue: casbin/gorm-adapter#195, PR: casbin/casbin#1230)</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review December 31, 2025 15:14
@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 73.68421% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.89%. Comparing base (c9155af) to head (8e8302c).

Files with missing lines Patch % Lines
...asbin/exception/CasbinEmptyConditionException.java 50.00% 2 Missing ⚠️
...sbin/exception/CasbinObjectConditionException.java 50.00% 2 Missing ⚠️
...rc/main/java/org/casbin/jcasbin/main/Enforcer.java 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
+ Coverage   67.82%   67.89%   +0.06%     
==========================================
  Files          61       63       +2     
  Lines        3058     3077      +19     
  Branches      568      572       +4     
==========================================
+ Hits         2074     2089      +15     
- Misses        802      805       +3     
- Partials      182      183       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI and others added 2 commits December 31, 2025 15:21
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GetAllowedObjectConditions() API port from Go to Java Add getAllowedObjectConditions() API Dec 31, 2025
Copilot AI requested a review from hsluoyz December 31, 2025 15:26
@hsluoyz hsluoyz closed this Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] add GetAllowedObjectConditions() API

4 participants