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

Backport to branch(3) : Add getUser() to AuthAdmin #1386

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
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
44 changes: 33 additions & 11 deletions core/src/main/java/com/scalar/db/api/AuthAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -98,15 +106,27 @@ 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 {
throw new UnsupportedOperationException("Not supported in the community edition");
}

/**
* 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<User> 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
Expand All @@ -116,26 +136,28 @@ default List<User> 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<Privilege> getPrivileges(String username, String namespaceName, String tableName)
throws ExecutionException {
throw new UnsupportedOperationException("Not supported in the community edition");
}

/**
* 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<Privilege> getPrivileges(String username, String namespaceName)
throws ExecutionException {
Expand Down