[NAE-2387] Fix permission evaluation order between ActorRef and proce…#420
[NAE-2387] Fix permission evaluation order between ActorRef and proce…#420machacjozef merged 4 commits intorelease/7.0.0-rev10from
Conversation
…ssRole - Introduced `checkPermissions` method in `AbstractAuthorizationService` to streamline permission verification logic across services. - Updated `TaskAuthorizationService` and `WorkflowAuthorizationService` to utilize the new `checkPermissions` method. - Added roles and actor references to XML test configuration for improved test scenarios. - Expanded `TaskAuthorizationServiceTest` with new unit tests to cover additional role and actor reference assignment scenarios.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughIntroduces a centralized protected method Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowAuthorizationService.java (1)
53-53:⚠️ Potential issue | 🟠 MajorPotential NPE:
userHasAtLeastOneRolePermissioncan returnnull.The method
canCallCreatereturns a primitiveboolean, butuserHasAtLeastOneRolePermissionreturnsBooleanwhich can benull(when the user has no matching roles in the permissions map). This will cause aNullPointerExceptionduring unboxing.🐛 Proposed fix to handle null return
`@Override` public boolean canCallCreate(LoggedUser user, String netId) { // TODO: impersonation if (user.isAdmin()) { return true; } PetriNet net = petriNetService.getPetriNet(netId); // TODO: impersonation - return userHasAtLeastOneRolePermission(user, net, ProcessRolePermission.CREATE); + Boolean rolePerm = userHasAtLeastOneRolePermission(user, net, ProcessRolePermission.CREATE); + return rolePerm != null && rolePerm; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowAuthorizationService.java` at line 53, canCallCreate currently returns the primitive boolean but delegates to userHasAtLeastOneRolePermission which returns a Boolean that may be null; change canCallCreate to guard against null by returning Boolean.TRUE.equals(userHasAtLeastOneRolePermission(user, net, ProcessRolePermission.CREATE)) (or use Optional.ofNullable(...).orElse(false)) so a null result is treated as false and no NPE occurs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@application-engine/src/test/groovy/com/netgrif/application/engine/auth/TaskAuthorizationServiceTest.groovy`:
- Around line 593-633: Both new tests
(testCanAssignWithRoleAssignTrueAndWithActorRefAssignUndefined and
testCanAssignWithRoleAssignUndefinedAndWithActorRefAssignTrue) are missing the
explicit cleanup used elsewhere; after asserting canCallAssign, call
userService.removeRole(testUser, positiveRole.get_id()) and
workflowService.deleteCase(case_.get_id()) (or the equivalent deleteCase
invocation used in this test class) to remove the added role and case to match
the pattern in testCanAssign/testCanFinish and keep tests consistent.
---
Outside diff comments:
In
`@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowAuthorizationService.java`:
- Line 53: canCallCreate currently returns the primitive boolean but delegates
to userHasAtLeastOneRolePermission which returns a Boolean that may be null;
change canCallCreate to guard against null by returning
Boolean.TRUE.equals(userHasAtLeastOneRolePermission(user, net,
ProcessRolePermission.CREATE)) (or use Optional.ofNullable(...).orElse(false))
so a null result is treated as false and no NPE occurs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c830f451-05d6-4b3b-a962-2d80a0330b9b
📒 Files selected for processing (5)
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/AbstractAuthorizationService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskAuthorizationService.javaapplication-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowAuthorizationService.javaapplication-engine/src/test/groovy/com/netgrif/application/engine/auth/TaskAuthorizationServiceTest.groovyapplication-engine/src/test/resources/task_authorization_service_test_with_userRefs.xml
...gine/src/test/groovy/com/netgrif/application/engine/auth/TaskAuthorizationServiceTest.groovy
Show resolved
Hide resolved
…ssRole Expanded XML test config with additional roles and actor references to support new scenarios. Introduced two new unit tests in `WorkflowAuthorizationServiceTest` to validate delete permissions based on role and actor reference combinations.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@application-engine/src/test/groovy/com/netgrif/application/engine/auth/WorkflowAuthorizationServiceTest.groovy`:
- Around line 334-352: The variable positiveDeleteRole in
testCanCallDeleteWithRoleDeleteUndefinedAndActorRefDeleteTrue is misleading
because it actually loads the "view_pos_role"; rename it to a clearer identifier
(e.g., viewPosRole or roleWithViewPermission) and update its declaration and
subsequent use in userService.addRole(...) so the variable name reflects the
role semantics returned by netWithUserRefs.getRoles().values().find(...
"view_pos_role").
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: f3b3f441-4ff0-4ce5-9687-aa486d7ebc05
📒 Files selected for processing (2)
application-engine/src/test/groovy/com/netgrif/application/engine/auth/WorkflowAuthorizationServiceTest.groovyapplication-engine/src/test/resources/workflow_authorization_service_test_with_userRefs.xml
.../src/test/groovy/com/netgrif/application/engine/auth/WorkflowAuthorizationServiceTest.groovy
Show resolved
Hide resolved
application-engine/src/test/resources/task_authorization_service_test_with_userRefs.xml
Show resolved
Hide resolved
Updated the actorRef logic to set the "view" permission to true in the test XML. This change ensures the test reflects the updated authorization configuration.
Description
Fix permission evaluation order between ActorRef and processRole with implementing check for undefined permissions on both role refs and actor refs.
Fixes NAE-2387
Dependencies
No new dependencies were introduced
Third party dependencies
No new dependencies were introduced
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
This was tested manually and with unit tests.
Test Configuration
Checklist:
Summary by CodeRabbit
Tests
Refactor