Skip to content

Commit eafa4ab

Browse files
committed
Refactor AuthAdmin RBAC interfaces
to eliminate confusion
1 parent 38fdc5a commit eafa4ab

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

core/src/main/java/com/scalar/db/api/AuthAdmin.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@ default void dropRole(String roleName) throws ExecutionException {
198198
}
199199

200200
/**
201-
* Retrieves a list of {@link RoleDetail}s.
201+
* Retrieves a list of {@link Role}s.
202202
*
203-
* @return a list of {@link RoleDetail}s
203+
* @return a list of {@link Role}s
204204
* @throws ExecutionException if the operation fails
205205
*/
206-
default List<RoleDetail> getRoles() throws ExecutionException {
206+
default List<Role> getRoles() throws ExecutionException {
207207
throw new UnsupportedOperationException(CoreError.AUTH_NOT_ENABLED.buildMessage());
208208
}
209209

210210
/**
211-
* Retrieves a list of {@link UserRoleDetail}s for the given user.
211+
* Retrieves a list of {@link RoleForUser}s for the given user.
212212
*
213213
* @param username the username
214-
* @return a list of {@link UserRoleDetail}s for the given user
214+
* @return a list of {@link RoleForUser}s for the given user
215215
* @throws ExecutionException if the operation fails
216216
*/
217-
default List<UserRoleDetail> getRolesForUser(String username) throws ExecutionException {
217+
default List<RoleForUser> getRolesForUser(String username) throws ExecutionException {
218218
throw new UnsupportedOperationException(CoreError.AUTH_NOT_ENABLED.buildMessage());
219219
}
220220

@@ -258,13 +258,13 @@ default void revokeAdminOptionFromUser(String username, String roleName)
258258
}
259259

260260
/**
261-
* Retrieves a list of {@link UserRole}s for the given role.
261+
* Retrieves a list of {@link GranteeUser}s for the given role.
262262
*
263263
* @param roleName the role name
264-
* @return a list of {@link UserRole}s for the given role
264+
* @return a list of {@link GranteeUser}s for the given role
265265
* @throws ExecutionException if the operation fails
266266
*/
267-
default List<UserRole> getUsersForRole(String roleName) throws ExecutionException {
267+
default List<GranteeUser> getGranteeUsersForRole(String roleName) throws ExecutionException {
268268
throw new UnsupportedOperationException(CoreError.AUTH_NOT_ENABLED.buildMessage());
269269
}
270270

@@ -406,21 +406,18 @@ interface User {
406406

407407
/** Represents a role. */
408408
interface Role {
409+
/** Returns the role name. */
409410
String getName();
410-
}
411411

412-
/** Represents a role with its hierarchy information. */
413-
interface RoleDetail {
414-
Role getRole();
415-
416-
List<RoleHierarchy> getRoleHierarchies();
412+
/** Returns the member roles granted to the role. */
413+
List<MemberRole> getMemberRoles();
417414
}
418415

419416
/**
420417
* Represents a role detail for a specific user, including whether the user has admin option for
421418
* this role.
422419
*/
423-
interface UserRoleDetail extends RoleDetail {
420+
interface RoleForUser extends Role {
424421
/**
425422
* Returns whether the user has admin option for this role. This is distinct from the admin
426423
* option in role hierarchies, which applies to role-to-role grants.
@@ -429,21 +426,18 @@ interface UserRoleDetail extends RoleDetail {
429426
}
430427

431428
/** Represents a user-role assignment. */
432-
interface UserRole {
433-
String getUsername();
434-
435-
String getRoleName();
429+
interface GranteeUser {
430+
/** Returns the username. */
431+
String getName();
436432

433+
/** Returns whether admin option is granted for this assignment. */
437434
boolean hasAdminOption();
438435
}
439436

440437
/** Represents a role hierarchy (role-to-role assignment). */
441-
interface RoleHierarchy {
442-
/** Returns the role name. */
443-
String getRoleName();
444-
438+
interface MemberRole {
445439
/** Returns the member role name granted to the role. */
446-
String getMemberRoleName();
440+
String getName();
447441

448442
/** Returns whether admin option is granted for this hierarchy. */
449443
boolean hasAdminOption();

core/src/main/java/com/scalar/db/common/DecoratedDistributedTransactionAdmin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ public void dropRole(String roleName) throws ExecutionException {
394394
}
395395

396396
@Override
397-
public List<RoleDetail> getRoles() throws ExecutionException {
397+
public List<Role> getRoles() throws ExecutionException {
398398
return distributedTransactionAdmin.getRoles();
399399
}
400400

401401
@Override
402-
public List<UserRoleDetail> getRolesForUser(String username) throws ExecutionException {
402+
public List<RoleForUser> getRolesForUser(String username) throws ExecutionException {
403403
return distributedTransactionAdmin.getRolesForUser(username);
404404
}
405405

@@ -421,8 +421,8 @@ public void revokeAdminOptionFromUser(String username, String roleName)
421421
}
422422

423423
@Override
424-
public List<UserRole> getUsersForRole(String roleName) throws ExecutionException {
425-
return distributedTransactionAdmin.getUsersForRole(roleName);
424+
public List<GranteeUser> getGranteeUsersForRole(String roleName) throws ExecutionException {
425+
return distributedTransactionAdmin.getGranteeUsersForRole(roleName);
426426
}
427427

428428
@Override

0 commit comments

Comments
 (0)