feat(core): integrate Detector into DefaultRoleManager with post-load cycle detection#484
feat(core): integrate Detector into DefaultRoleManager with post-load cycle detection#484
Conversation
|
|
…support - Add optional Detector field to DefaultRoleManager with setter method - Modify addLink to call detector.check() after adding inheritance link - Implement automatic rollback on cycle detection - Throw IllegalArgumentException with error description on cycle detection - Create comprehensive DetectorTest.java with 12 test cases - All tests pass including existing RoleManagerUnitTest Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Replace hardcoded value 9 with CHAIN_LENGTH constant for better code clarity Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #484 +/- ##
==========================================
+ Coverage 67.80% 68.05% +0.24%
==========================================
Files 61 63 +2
Lines 3069 3096 +27
Branches 569 578 +9
==========================================
+ Hits 2081 2107 +26
+ Misses 806 805 -1
- Partials 182 184 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
When This breaks the idempotency of the operation and causes data loss. Since if (user.roles.containsKey(name2)) {
return;
} |
|
@copilot When This breaks the idempotency of the operation and causes data loss. Since if (user.roles.containsKey(name2)) {
return;
} |
Add idempotency check in addLink to prevent deleting pre-existing valid links when detector fails. This ensures addLink is truly idempotent even with cycle detection enabled. - Check if link already exists before adding (user.roles.containsKey(name2)) - Return early if link exists, avoiding unnecessary processing and rollback issues - Add comprehensive tests for idempotency scenarios Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Fixed in commit 53da062. Added the idempotency check as suggested: if (user.roles.containsKey(name2)) {
return;
}This prevents data loss when |
|
@copilot DescriptionThe Task:
|
1 similar comment
DescriptionThe Task:
|
Add synchronized keyword to addLink method to ensure thread safety. The method now performs compound operations (check -> add -> check -> rollback) which could lead to race conditions without proper synchronization. This aligns with the existing synchronized hasLink method. Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
... Fixed in commit 4ecff15. Added the This aligns with the existing |
|
Please fix the performance regression in Description: Task:
|
|
@copilot Please fix the performance regression in Description: Task:
|
Temporarily disable detector during rebuild loop to prevent repeated cycle checks on each addLink call. Perform a single check at the end. This reduces rebuild() complexity from O(N^2) to O(N) when detector is enabled. - Save original detector before rebuild - Set detector to null during addLink loop - Restore detector and perform single check after loop - Properly restore detector in exception handler Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Fixed in commit b168081. Optimized
This reduces rebuild complexity from O(N²) to O(N) when detector is enabled. |
|
Description: Modifications Required: 1.
|
|
Description: Modifications Required: 1.
|
Change cycle detection strategy to improve bulk loading performance: - Remove automatic cycle check from addLink() method - Add public checkCycles() method for manual cycle detection - Simplify rebuild() to just call checkCycles() at the end - Override loadPolicy() in ManagementEnforcer to call checkCycles() after loading - Update all DetectorTest cases to call checkCycles() explicitly This changes the detection from O(N^2) real-time checks to O(N) post-load check, significantly improving performance during bulk policy loading while maintaining the same cycle detection capability. Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Fixed in commit 25d842a. Moved cycle detection from real-time to post-load: DefaultRoleManager:
ManagementEnforcer:
DetectorTest:
This changes detection from O(N²) real-time to O(N) post-load, significantly improving bulk policy loading performance. |
d4aa61e to
53d9a5f
Compare
0c8d4c7 to
6504a9e
Compare
Plan for integrating Detector into DefaultRoleManager
Detectorfield toDefaultRoleManagerdetectorfieldsetDetector(Detector detector)setter methodaddLinkmethod simply adds links without automatic cycle checkingcheckCycles()method for manual cycle detectionaddLinkto prevent duplicate linksaddLinkto prevent race conditionsloadPolicy()inManagementEnforcerto callcheckCycles()on allDefaultRoleManagerinstances after loadingrebuild()to callcheckCycles()at the endDetectorTest.javatest filecheckCycles()(no exceptions)addLink(links added without exception)checkCycles()throws exception when cycles existDefaultRoleManagerandDefaultDetector, notEnforcerSummary
✅ All requirements met:
loadPolicy()inManagementEnforcerautomatically callscheckCycles()after loadingcheckCycles()method available for explicit cycle checkingImplementation Details
Cycle Detection Strategy:
addLink()adds links without performing cycle checks (O(1) per call)checkCycles()performs a single graph traversal to detect cycles (O(N) total)ManagementEnforcer.loadPolicy()automatically callscheckCycles()after policy is loadedcheckCycles()manually when neededThis approach provides significant performance improvement during bulk policy loading (O(N) instead of O(N²)) while maintaining the same cycle detection capabilities.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.