From 889e3e0b946a03a900ba5ad6e348458f835b7618 Mon Sep 17 00:00:00 2001 From: Hiroyuki Yamada Date: Thu, 14 Dec 2023 18:08:20 +0900 Subject: [PATCH] Backport to branch(3) : Add getUser() to AuthAdmin (#1386) Co-authored-by: Toshihiro Suzuki --- .../java/com/scalar/db/api/AuthAdmin.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/scalar/db/api/AuthAdmin.java b/core/src/main/java/com/scalar/db/api/AuthAdmin.java index 309723e013..65ddc950fb 100644 --- a/core/src/main/java/com/scalar/db/api/AuthAdmin.java +++ b/core/src/main/java/com/scalar/db/api/AuthAdmin.java @@ -2,6 +2,7 @@ import com.scalar.db.exception.storage.ExecutionException; import java.util.List; +import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; @@ -18,6 +19,7 @@ public interface AuthAdmin { * @param username the username * @param password the password. If null, the user is created without a password * @param userOptions the user options + * @throws IllegalArgumentException if the user already exists * @throws ExecutionException if the operation fails */ default void createUser(String username, @Nullable String password, UserOption... userOptions) @@ -27,11 +29,13 @@ default void createUser(String username, @Nullable String password, UserOption.. /** * Alters a user with the given username, password and user options. If the password is null, the - * password is not changed. + * password is not changed. If empty, the password is deleted. * * @param username the username - * @param password the password. If null, the password is not changed + * @param password the password. If null, the password is not changed. If empty, the password is + * deleted * @param userOptions the user options + * @throws IllegalArgumentException if the user does not exist * @throws ExecutionException if the operation fails */ default void alterUser(String username, @Nullable String password, UserOption... userOptions) @@ -43,6 +47,7 @@ default void alterUser(String username, @Nullable String password, UserOption... * Drops a user with the given username. * * @param username the username + * @throws IllegalArgumentException if the user does not exist * @throws ExecutionException if the operation fails */ default void dropUser(String username) throws ExecutionException { @@ -56,7 +61,8 @@ default void dropUser(String username) throws ExecutionException { * @param namespaceName the namespace name of the table * @param tableName the table name * @param privileges the privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the table does not exist + * @throws ExecutionException if the operation fails */ default void grant( String username, String namespaceName, String tableName, Privilege... privileges) @@ -70,7 +76,8 @@ default void grant( * @param username the username * @param namespaceName the namespace name * @param privileges the privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the namespace does not exist + * @throws ExecutionException if the operation fails */ default void grant(String username, String namespaceName, Privilege... privileges) throws ExecutionException { @@ -84,7 +91,8 @@ default void grant(String username, String namespaceName, Privilege... privilege * @param namespaceName the namespace name of the table * @param tableName the table name * @param privileges the privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the table does not exist + * @throws ExecutionException if the operation fails */ default void revoke( String username, String namespaceName, String tableName, Privilege... privileges) @@ -98,7 +106,8 @@ default void revoke( * @param username the username * @param namespaceName the namespace name * @param privileges the privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the namespace does not exist + * @throws ExecutionException if the operation fails */ default void revoke(String username, String namespaceName, Privilege... privileges) throws ExecutionException { @@ -106,7 +115,18 @@ default void revoke(String username, String namespaceName, Privilege... privileg } /** - * Retrieve a list of {@link User}s. + * Retrieves a {@link User} for the given username. + * + * @param username the username + * @return a {@link User} for the given username + * @throws ExecutionException if the operation fails + */ + default Optional getUser(String username) throws ExecutionException { + throw new UnsupportedOperationException("Not supported in the community edition"); + } + + /** + * Retrieves a list of {@link User}s. * * @return a list of {@link User}s * @throws ExecutionException if the operation fails @@ -116,13 +136,14 @@ default List getUsers() throws ExecutionException { } /** - * Retrieve privileges for the given table for the given user. + * Retrieves privileges for the given table for the given user. * * @param username the username * @param namespaceName the namespace name of the table * @param tableName the table name * @return a set of privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the table does not exist + * @throws ExecutionException if the operation fails */ default Set getPrivileges(String username, String namespaceName, String tableName) throws ExecutionException { @@ -130,12 +151,13 @@ default Set getPrivileges(String username, String namespaceName, Stri } /** - * Retrieve privileges for all tables in the given namespace for the given user. + * Retrieves privileges for all tables in the given namespace for the given user. * * @param username the username * @param namespaceName the namespace name * @return a set of privileges - * @throws ExecutionException if the user does not exist or the operation fails + * @throws IllegalArgumentException if the user does not exist or the namespace does not exist + * @throws ExecutionException if the operation fails */ default Set getPrivileges(String username, String namespaceName) throws ExecutionException {