This is an automated email from the ASF dual-hosted git repository.

pradeepagrawal8184 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new b5c496abe RANGER-5714 : Ranger server returns an incorrect error 
message when an admin tries to revoke a non-existing role from a user (#1124)
b5c496abe is described below

commit b5c496abed6da05af0105fbbcc0b9cc5f52c811b
Author: akash gupta <[email protected]>
AuthorDate: Wed Aug 5 04:30:03 2026 +0530

    RANGER-5714 : Ranger server returns an incorrect error message when an 
admin tries to revoke a non-existing role from a user (#1124)
    
    Co-authored-by: akgupta <[email protected]>
---
 .../main/java/org/apache/ranger/biz/RoleDBStore.java |  2 +-
 .../main/java/org/apache/ranger/rest/RoleREST.java   |  2 ++
 .../java/org/apache/ranger/rest/TestRoleREST.java    | 20 ++++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/security-admin/src/main/java/org/apache/ranger/biz/RoleDBStore.java 
b/security-admin/src/main/java/org/apache/ranger/biz/RoleDBStore.java
index a34cb5344..4d06bfe67 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/RoleDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/RoleDBStore.java
@@ -214,7 +214,7 @@ public RangerRole getRole(String name) {
         XXRole xxRole = daoMgr.getXXRole().findByRoleName(name);
 
         if (xxRole == null) {
-            throw restErrorUtil.createRESTException("Role with name: " + name 
+ " does not exist");
+            throw restErrorUtil.createRESTException("Role with name: " + name 
+ " does not exist.");
         }
 
         return roleService.read(xxRole.getId());
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java 
b/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
index 1790cc1ca..b92b221fe 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
@@ -1283,6 +1283,8 @@ private RangerRole getRoleIfAccessible(String roleName, 
String serviceName, Stri
             } else {
                 existingRole = roleStore.getRole(roleName);
             }
+        } catch (WebApplicationException ex) {
+            throw ex;
         } catch (Exception ex) {
             LOG.error(ex.getMessage());
 
diff --git 
a/security-admin/src/test/java/org/apache/ranger/rest/TestRoleREST.java 
b/security-admin/src/test/java/org/apache/ranger/rest/TestRoleREST.java
index 64a90dc43..b7de41724 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestRoleREST.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestRoleREST.java
@@ -1728,4 +1728,24 @@ public void 
test34GetSecureRangerRolesIfUpdatedWithInvalidService() {
             roleRest.getSecureRangerRolesIfUpdated(serviceName, -1L, 0L, 
pluginId, clusterName, pluginCapabilities, 
Mockito.mock(HttpServletRequest.class));
         });
     }
+
+    @Test
+    public void test35GrantRoleNonExistentRole() throws Exception {
+        String                 serviceName            = "serviceName";
+        GrantRevokeRoleRequest grantRevokeRoleRequest = 
createGrantRevokeRoleRequest();
+        String                 roleName               = "role_100";
+        WebApplicationException roleNotFoundException   = new 
WebApplicationException("Role with name: " + roleName + " does not exist");
+
+        grantRevokeRoleRequest.setTargetRoles(new 
HashSet<>(Collections.singletonList(roleName)));
+
+        
Mockito.when(bizUtil.isUserRangerAdmin(Mockito.anyString())).thenReturn(true);
+        
Mockito.when(roleStore.getRole(roleName)).thenThrow(roleNotFoundException);
+
+        WebApplicationException exception = 
Assertions.assertThrows(WebApplicationException.class, () -> {
+            roleRest.grantRole(serviceName, grantRevokeRoleRequest, 
Mockito.mock(HttpServletRequest.class));
+        });
+
+        Assertions.assertNotNull(exception);
+        Mockito.verify(roleStore, Mockito.times(1)).getRole(roleName);
+    }
 }

Reply via email to