Skip to content

Commit b08f6c7

Browse files
Backport to branch(3) : [RBAC] Refactor AuthAdmin RBAC interfaces to eliminate confusion (#3165)
Co-authored-by: Mitsunori Komatsu <komamitsu@gmail.com>
1 parent 27a2ece commit b08f6c7

File tree

2 files changed

+65
-35
lines changed

2 files changed

+65
-35
lines changed

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

Lines changed: 61 additions & 31 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 GranteeUserRef}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 GranteeUserRef}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<GranteeUserRef> getGranteeUsersForRole(String roleName) throws ExecutionException {
268268
throw new UnsupportedOperationException(CoreError.AUTH_NOT_ENABLED.buildMessage());
269269
}
270270

@@ -399,53 +399,83 @@ default void revokePrivilegeFromRole(
399399

400400
/** Represents a user. */
401401
interface User {
402+
/**
403+
* Returns the username.
404+
*
405+
* @return the username
406+
*/
402407
String getName();
403408

409+
/**
410+
* Returns whether the user is a superuser.
411+
*
412+
* @return whether the user is a superuser
413+
*/
404414
boolean isSuperuser();
405415
}
406416

407-
/** Represents a role. */
417+
/** Represents a role, including its granted roles. */
408418
interface Role {
419+
/**
420+
* Returns the role name.
421+
*
422+
* @return the role name
423+
*/
409424
String getName();
410-
}
411-
412-
/** Represents a role with its hierarchy information. */
413-
interface RoleDetail {
414-
Role getRole();
415425

416-
List<RoleHierarchy> getRoleHierarchies();
426+
/**
427+
* Returns the roles granted to the role.
428+
*
429+
* @return the roles granted to the role
430+
*/
431+
List<GrantedRoleRef> getGrantedRoles();
417432
}
418433

419434
/**
420-
* Represents a role detail for a specific user, including whether the user has admin option for
435+
* Represents a role granted to a specific user, including whether the user has admin option for
421436
* this role.
422437
*/
423-
interface UserRoleDetail extends RoleDetail {
438+
interface RoleForUser extends Role {
424439
/**
425440
* Returns whether the user has admin option for this role. This is distinct from the admin
426441
* option in role hierarchies, which applies to role-to-role grants.
442+
*
443+
* @return whether the user has admin option for this role
427444
*/
428445
boolean hasAdminOptionOnUser();
429446
}
430447

431-
/** Represents a user-role assignment. */
432-
interface UserRole {
433-
String getUsername();
434-
435-
String getRoleName();
448+
/** A reference to a grantee user of a role. */
449+
interface GranteeUserRef {
450+
/**
451+
* Returns the username.
452+
*
453+
* @return the username
454+
*/
455+
String getName();
436456

457+
/**
458+
* Returns whether admin option is granted for this assignment.
459+
*
460+
* @return whether admin option is granted for this assignment
461+
*/
437462
boolean hasAdminOption();
438463
}
439464

440-
/** Represents a role hierarchy (role-to-role assignment). */
441-
interface RoleHierarchy {
442-
/** Returns the role name. */
443-
String getRoleName();
444-
445-
/** Returns the member role name granted to the role. */
446-
String getMemberRoleName();
465+
/** A reference to a granted role. */
466+
interface GrantedRoleRef {
467+
/**
468+
* Returns the granted role name.
469+
*
470+
* @return the granted role name
471+
*/
472+
String getName();
447473

448-
/** Returns whether admin option is granted for this hierarchy. */
474+
/**
475+
* Returns whether admin option is granted for this role grant.
476+
*
477+
* @return whether admin option is granted for this role grant
478+
*/
449479
boolean hasAdminOption();
450480
}
451481

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

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

385385
@Override
386-
public List<RoleDetail> getRoles() throws ExecutionException {
386+
public List<Role> getRoles() throws ExecutionException {
387387
return distributedTransactionAdmin.getRoles();
388388
}
389389

390390
@Override
391-
public List<UserRoleDetail> getRolesForUser(String username) throws ExecutionException {
391+
public List<RoleForUser> getRolesForUser(String username) throws ExecutionException {
392392
return distributedTransactionAdmin.getRolesForUser(username);
393393
}
394394

@@ -410,8 +410,8 @@ public void revokeAdminOptionFromUser(String username, String roleName)
410410
}
411411

412412
@Override
413-
public List<UserRole> getUsersForRole(String roleName) throws ExecutionException {
414-
return distributedTransactionAdmin.getUsersForRole(roleName);
413+
public List<GranteeUserRef> getGranteeUsersForRole(String roleName) throws ExecutionException {
414+
return distributedTransactionAdmin.getGranteeUsersForRole(roleName);
415415
}
416416

417417
@Override

0 commit comments

Comments
 (0)