Skip to content

feat: adds the missing AddGroupingPoliciesEx and AddNamedGroupingPoliciesEx APIs to sync jCasbin with Go Casbin#463

Merged
hsluoyz merged 2 commits intomasterfrom
copilot/sync-new-apis-jcasbin
Oct 11, 2025
Merged

feat: adds the missing AddGroupingPoliciesEx and AddNamedGroupingPoliciesEx APIs to sync jCasbin with Go Casbin#463
hsluoyz merged 2 commits intomasterfrom
copilot/sync-new-apis-jcasbin

Conversation

Copy link
Contributor

Copilot AI commented Oct 11, 2025

This PR adds the missing AddGroupingPoliciesEx and AddNamedGroupingPoliciesEx APIs to sync jCasbin with Go Casbin implementation (commit ea5ed6b).

Changes

New APIs in ManagementEnforcer

  • addGroupingPoliciesEx(List<List<String>> rules) - Adds grouping policies with default "g" ptype
  • addGroupingPoliciesEx(String[][] rules) - Overload accepting String array
  • addNamedGroupingPoliciesEx(String ptype, List<List<String>> rules) - Named version with custom ptype
  • addNamedGroupingPoliciesEx(String ptype, String[][] rules) - Named overload accepting String array

Thread-safe implementations in SyncedEnforcer

All four methods are properly overridden with synchronization support using runSynchronized().

Motivation

The "Ex" variants provide more flexible policy management compared to the regular APIs:

Regular APIs (addGroupingPolicies):

  • Fail completely if ANY rule in the batch already exists
  • All-or-nothing approach

Ex APIs (addGroupingPoliciesEx):

  • Continue adding non-existent rules even if some already exist
  • Partial success approach - useful for bulk operations where some rules may already be in place

Example Usage

Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");

String[][] groupingRules = {
    {"alice", "data2_admin"}, // Already exists
    {"bob", "data1_admin"},   // New
    {"eve", "data3_admin"}    // New
};

// This succeeds and adds bob and eve, skipping alice's existing rule
boolean result = e.addGroupingPoliciesEx(groupingRules);
// result = true (at least one rule was added)

Testing

  • Added comprehensive test coverage in ManagementAPIUnitTest
  • Added thread-safety tests in SyncedManagementAPIUnitTest
  • All 193 tests pass, including 2 new tests
  • No breaking changes to existing functionality

Fixes #459 (required by apache/casbin-jcasbin-postgres-watcher#3)

Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] sync new APIs like AddNamedGroupingPoliciesEx() from Go Casbin to jCasbin</issue_title>
<issue_description>Required by: apache/casbin-jcasbin-postgres-watcher#3

About what APIs to add, refer to Golang Casbin: apache/casbin@ea5ed6b

Need to add the missing APIs, need to sync missing APIs from Golang Casbin</issue_description>

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

Fixes #461


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@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.

…nforcer with tests

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing APIs from Go Casbin to jCasbin Sync AddNamedGroupingPoliciesEx APIs from Go Casbin to jCasbin Oct 11, 2025
Copilot AI requested a review from hsluoyz October 11, 2025 18:10
@hsluoyz hsluoyz marked this pull request as ready for review October 11, 2025 18:16
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.30%. Comparing base (747eb33) to head (065284f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #463      +/-   ##
==========================================
+ Coverage   66.77%   67.30%   +0.52%     
==========================================
  Files          60       60              
  Lines        2992     3000       +8     
  Branches      557      557              
==========================================
+ Hits         1998     2019      +21     
+ Misses        811      802       -9     
+ Partials      183      179       -4     

☔ 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.

@hsluoyz hsluoyz changed the title Sync AddNamedGroupingPoliciesEx APIs from Go Casbin to jCasbin feat: adds the missing AddGroupingPoliciesEx and AddNamedGroupingPoliciesEx APIs to sync jCasbin with Go Casbin Oct 11, 2025
@hsluoyz hsluoyz merged commit 58903b0 into master Oct 11, 2025
3 of 5 checks passed
@github-actions
Copy link

🎉 This PR is included in version 1.85.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] sync new APIs like AddNamedGroupingPoliciesEx() from Go Casbin to jCasbin google aviator critical vulnerability

4 participants