Skip to content
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

The error message is not user-friendly when adding duplicate permissi… #12805

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,18 @@ public Object deletePermission(@RequestParam String role, @RequestParam String r
nacosRoleService.deletePermission(role, resource, action);
return RestResultUtils.success("delete permission ok!");
}

/**
* Judge whether a permission is duplicate.
*
* @param role the role
* @param resource the related resource
* @param action the related action
* @return true if duplicate, false otherwise
*/
@GetMapping
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX + "permissions", action = ActionTypes.READ)
public Boolean isDuplicatePermission(@RequestParam String role, @RequestParam String resource, @RequestParam String action) {
zhouchunhai marked this conversation as resolved.
Show resolved Hide resolved
return nacosRoleService.isDuplicatePermission(role, resource, action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,28 @@ public boolean hasGlobalAdminRole() {
authConfigs.setHasGlobalAdminRole(hasGlobalAdminRole);
return hasGlobalAdminRole;
}

/**
* judge whether the permission is duplicate.
*
* @param role role name
* @param resource resource
* @param action action
* @return true if duplicate, false otherwise
*/
public Boolean isDuplicatePermission(String role, String resource, String action) {
List<PermissionInfo> permissionInfos = getPermissions(role);
if (CollectionUtils.isEmpty(permissionInfos)) {
return Boolean.FALSE;
}
for (PermissionInfo permissionInfo : permissionInfos) {
boolean resourceMatch = StringUtils.equals(resource, permissionInfo.getResource());
boolean actionMatch = StringUtils.equals(action, permissionInfo.getAction()) || "rw".equals(permissionInfo.getAction());
if (resourceMatch && actionMatch) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}

}
Loading