-
Notifications
You must be signed in to change notification settings - Fork 60
Fixes null Check where a template is created with an admin (null) user #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -366,6 +366,16 @@ public static void resolveUserAndExecute( | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // helper method to check if varargs User... is null | ||||||||||||||||||||||||||||||||||||||
| private static boolean hasUsersAndRoles(User requestedUser, User resourceUser) { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return requestedUser != null | ||||||||||||||||||||||||||||||||||||||
| && resourceUser != null | ||||||||||||||||||||||||||||||||||||||
| && resourceUser.getBackendRoles() != null | ||||||||||||||||||||||||||||||||||||||
| && requestedUser.getBackendRoles() != null; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+370
to
+377
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or you can possibly use a stream. |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Check if requested user has backend role required to access the resource | ||||||||||||||||||||||||||||||||||||||
| * @param requestedUser the user to execute the request | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -374,10 +384,11 @@ public static void resolveUserAndExecute( | |||||||||||||||||||||||||||||||||||||
| * @return boolean if the requested user has backend role required to access the resource | ||||||||||||||||||||||||||||||||||||||
| * @throws Exception exception | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static boolean checkUserPermissions(User requestedUser, User resourceUser, String workflowId) throws Exception { | ||||||||||||||||||||||||||||||||||||||
| if (resourceUser.getBackendRoles() == null || requestedUser.getBackendRoles() == null) { | ||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (!hasUsersAndRoles(requestedUser, resourceUser)) return false; | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but given the negation we may want to make the helper method |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Check if requested user has backend role required to access the resource | ||||||||||||||||||||||||||||||||||||||
| for (String backendRole : requestedUser.getBackendRoles()) { | ||||||||||||||||||||||||||||||||||||||
| if (resourceUser.getBackendRoles().contains(backendRole)) { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -395,6 +406,13 @@ private static boolean checkUserPermissions(User requestedUser, User resourceUse | |||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // method to expose checkUserPermissions for testing | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to just make the existing method package private with this comment than have a wrapper method to do the same thing. It actually wouldn't hurt to just make the method public. |
||||||||||||||||||||||||||||||||||||||
| static boolean exposeCheckUserPermissions(User requestedUser, User resourceUser, String workflowId) throws Exception { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return checkUserPermissions(requestedUser, resourceUser, workflowId); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Check if filter by backend roles is enabled and validate the requested user | ||||||||||||||||||||||||||||||||||||||
| * @param requestedUser the user to execute the request | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -533,8 +551,8 @@ public static void onGetWorkflowResponse( | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (shouldUseResourceAuthz(CommonValue.WORKFLOW_RESOURCE_TYPE) | ||||||||||||||||||||||||||||||||||||||
| || !filterByEnabled | ||||||||||||||||||||||||||||||||||||||
| || checkUserPermissions(requestUser, resourceUser, workflowId) | ||||||||||||||||||||||||||||||||||||||
| || isAdmin(requestUser)) { | ||||||||||||||||||||||||||||||||||||||
| || isAdmin(requestUser) | ||||||||||||||||||||||||||||||||||||||
| || checkUserPermissions(requestUser, resourceUser, workflowId)) { | ||||||||||||||||||||||||||||||||||||||
| function.run(); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| logger.debug("User: " + requestUser.getName() + " does not have permissions to access workflow: " + workflowId); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -444,4 +444,17 @@ public void testIsAdminBackendRoleIsAllAccess() { | |
| public void testIsAdminNull() { | ||
| assertFalse(isAdmin(null)); | ||
| } | ||
|
|
||
| public void testCheckUserPermissionsWithNullUsers() throws Exception { | ||
|
|
||
| User mockrequestedUser = null; | ||
| User mockresourceUser = new User(); | ||
| String mockWorkFlowId = "mockWorkFlowId"; | ||
|
|
||
| boolean res = ParseUtils.exposeCheckUserPermissions(mockrequestedUser, mockresourceUser, mockWorkFlowId); | ||
|
|
||
| assertFalse(res); | ||
|
|
||
| } | ||
|
Comment on lines
+448
to
+458
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good test case but you need to test all the conditional cases (null/non-null on both requested and resource user). |
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the format of our change log entries (see the release notes for where they eventually go) and add a blank line after this so the markdown properly renders.