Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2967] feat(api,server): Add the more privileges (#2965)

qqqttt1232a1ba00d5c46
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/Privilege.java b/api/src/main/java/com/datastrato/gravitino/authorization/Privilege.java
index d27bde422e..e33bd19eb7 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/Privilege.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/Privilege.java
@@ -4,13 +4,13 @@
*/
package com.datastrato.gravitino.authorization;
-import com.datastrato.gravitino.annotation.Evolving;
+import com.datastrato.gravitino.annotation.Unstable;
/**
* The interface of a privilege. The privilege represents the ability to execute kinds of operations
* for kinds of entities
*/
-@Evolving
+@Unstable
public interface Privilege {
/** @return The generic name of the privilege. */
@@ -21,7 +21,99 @@ public interface Privilege {
/** The name of this privilege. */
enum Name {
- /** The privilege of load a catalog. */
- LOAD_CATALOG
+ /** The privilege to create a catalog. */
+ CREATE_CATALOG(0L, 1L),
+ /** The privilege to drop a catalog. */
+ DROP_CATALOG(0L, 1L << 1),
+ /** The privilege to alter a catalog. */
+ ALTER_CATALOG(0L, 1L << 2),
+ /** The privilege to use a catalog. */
+ USE_CATALOG(0L, 1L << 3),
+ /** The privilege to create a schema. */
+ CREATE_SCHEMA(0L, 1L << 4),
+ /** The privilege to drop a schema. */
+ DROP_SCHEMA(0L, 1L << 5),
+ /** The privilege to alter a schema. */
+ ALTER_SCHEMA(0L, 1L << 6),
+ /** the privilege to use a schema. */
+ USE_SCHEMA(0L, 1L << 7),
+ /** The privilege to create a table. */
+ CREATE_TABLE(0L, 1L << 8),
+ /** The privilege to drop a table. */
+ DROP_TABLE(0L, 1L << 9),
+ /** The privilege to write a table. */
+ WRITE_TABLE(0L, 1L << 10),
+ /** The privilege to read a table. */
+ READ_TABLE(0L, 1L << 11),
+ /** The privilege to create a fileset. */
+ CREATE_FILESET(0L, 1L << 12),
+ /** The privilege to drop a fileset. */
+ DROP_FILESET(0L, 1L << 13),
+ /** The privilege to write a fileset. */
+ WRITE_FILESET(0L, 1L << 14),
+ /** The privilege to read a fileset. */
+ READ_FILESET(0L, 1L << 15),
+ /** The privilege to create a topic. */
+ CREATE_TOPIC(0L, 1L << 16),
+ /** The privilege to drop a topic. */
+ DROP_TOPIC(0L, 1L << 17),
+ /** The privilege to write a topic. */
+ WRITE_TOPIC(0L, 1L << 18),
+ /** The privilege to read a topic. */
+ READ_TOPIC(0L, 1L << 19),
+ /** The privilege to create a metalake. */
+ CREATE_METALAKE(0L, 1L << 20),
+ /** The privilege to manage a metalake, including drop and alter a metalake. */
+ MANAGE_METALAKE(0L, 1L << 21),
+ /** The privilege to use a metalake, the user can load the information of the metalake. */
+ USE_METALAKE(0L, 1L << 22),
+ /** The privilege to add a user */
+ ADD_USER(0L, 1L << 23),
+ /** The privilege to remove a user */
+ REMOVE_USER(0L, 1L << 24),
+ /** The privilege to get a user */
+ GET_USER(0L, 1L << 25),
+ /** The privilege to add a group */
+ ADD_GROUP(0L, 1L << 26),
+ /** The privilege to remove a group */
+ REMOVE_GROUP(0L, 1L << 27),
+ /** The privilege to get a group */
+ GET_GROUP(0L, 1L << 28),
+ /** The privilege to create a role */
+ CREATE_ROLE(0L, 1L << 29),
+ /** The privilege to delete a role */
+ DELETE_ROLE(0L, 1L << 30),
+ /** The privilege to grant a role to the user or the group. */
+ GRANT_ROLE(0L, 1L << 31),
+ /** The privilege to revoke a role from the user or the group. */
+ REVOKE_ROLE(0L, 1L << 32),
+ /** The privilege to get a role */
+ GET_ROLE(0L, 1L << 33);
+
+ private final long highBits;
+ private final long lowBits;
+
+ Name(long highBits, long lowBits) {
+ this.highBits = highBits;
+ this.lowBits = lowBits;
+ }
+
+ /**
+ * Return the low bits of Name
+ *
+ * @return The low bits of Name
+ */
+ public long getLowBits() {
+ return lowBits;
+ }
+
+ /**
+ * Return the high bits of Name
+ *
+ * @return The high bits of Name
+ */
+ public long getHighBits() {
+ return highBits;
+ }
}
}
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java b/api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java
index 9eb4f3f9ef..f91e83e33a 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java
@@ -4,6 +4,41 @@
*/
package com.datastrato.gravitino.authorization;
+import static com.datastrato.gravitino.authorization.Privilege.Name.ADD_GROUP;
+import static com.datastrato.gravitino.authorization.Privilege.Name.ADD_USER;
+import static com.datastrato.gravitino.authorization.Privilege.Name.ALTER_CATALOG;
+import static com.datastrato.gravitino.authorization.Privilege.Name.ALTER_SCHEMA;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_CATALOG;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_FILESET;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_METALAKE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_ROLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_SCHEMA;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_TABLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.CREATE_TOPIC;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DELETE_ROLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DROP_CATALOG;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DROP_FILESET;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DROP_SCHEMA;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DROP_TABLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.DROP_TOPIC;
+import static com.datastrato.gravitino.authorization.Privilege.Name.GET_GROUP;
+import static com.datastrato.gravitino.authorization.Privilege.Name.GET_ROLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.GET_USER;
+import static com.datastrato.gravitino.authorization.Privilege.Name.GRANT_ROLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.MANAGE_METALAKE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.READ_FILESET;
+import static com.datastrato.gravitino.authorization.Privilege.Name.READ_TABLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.READ_TOPIC;
+import static com.datastrato.gravitino.authorization.Privilege.Name.REMOVE_GROUP;
+import static com.datastrato.gravitino.authorization.Privilege.Name.REMOVE_USER;
+import static com.datastrato.gravitino.authorization.Privilege.Name.REVOKE_ROLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.USE_CATALOG;
+import static com.datastrato.gravitino.authorization.Privilege.Name.USE_METALAKE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.USE_SCHEMA;
+import static com.datastrato.gravitino.authorization.Privilege.Name.WRITE_FILESET;
+import static com.datastrato.gravitino.authorization.Privilege.Name.WRITE_TABLE;
+import static com.datastrato.gravitino.authorization.Privilege.Name.WRITE_TOPIC;
+
/** The helper class for {@link Privilege}. */
public class Privileges {
@@ -26,34 +61,935 @@ public class Privileges {
*/
public static Privilege fromName(Privilege.Name name) {
switch (name) {
- case LOAD_CATALOG:
- return LoadCatalog.get();
+ // Catalog
+ case CREATE_CATALOG:
+ return CreateCatalog.get();
+ case DROP_CATALOG:
+ return DropCatalog.get();
+ case ALTER_CATALOG:
+ return AlterCatalog.get();
+ case USE_CATALOG:
+ return UseCatalog.get();
+
+ // Schema
+ case CREATE_SCHEMA:
+ return CreateSchema.get();
+ case DROP_SCHEMA:
+ return DropSchema.get();
+ case ALTER_SCHEMA:
+ return AlterSchema.get();
+ case USE_SCHEMA:
+ return UseSchema.get();
+
+ // Table
+ case CREATE_TABLE:
+ return CreateTable.get();
+ case DROP_TABLE:
+ return DropTable.get();
+ case WRITE_TABLE:
+ return WriteTable.get();
+ case READ_TABLE:
+ return ReadTable.get();
+
+ // Fileset
+ case CREATE_FILESET:
+ return CreateFileset.get();
+ case DROP_FILESET:
+ return DropFileset.get();
+ case WRITE_FILESET:
+ return WriteFileset.get();
+ case READ_FILESET:
+ return ReadFileset.get();
+
+ // Topic
+ case CREATE_TOPIC:
+ return CreateTopic.get();
+ case DROP_TOPIC:
+ return DropTopic.get();
+ case WRITE_TOPIC:
+ return WriteTopic.get();
+ case READ_TOPIC:
+ return ReadTopic.get();
+
+ // Metalake
+ case CREATE_METALAKE:
+ return CreateMetalake.get();
+ case MANAGE_METALAKE:
+ return ManageMetalake.get();
+ case USE_METALAKE:
+ return UseMetalake.get();
+
+ // User
+ case ADD_USER:
+ return AddUser.get();
+ case REMOVE_USER:
+ return RemoveUser.get();
+ case GET_USER:
+ return GetUser.get();
+
+ // Group
+ case ADD_GROUP:
+ return AddGroup.get();
+ case REMOVE_GROUP:
+ return RemoveGroup.get();
+ case GET_GROUP:
+ return GetGroup.get();
+
+ // Role
+ case CREATE_ROLE:
+ return CreateRole.get();
+ case DELETE_ROLE:
+ return DeleteRole.get();
+ case GRANT_ROLE:
+ return GrantRole.get();
+ case REVOKE_ROLE:
+ return RevokeRole.get();
+ case GET_ROLE:
+ return GetRole.get();
+
default:
throw new IllegalArgumentException("Don't support the privilege: " + name);
}
}
- /** The privilege of load a catalog. */
- public static class LoadCatalog implements Privilege {
- private static final LoadCatalog INSTANCE = new LoadCatalog();
+ /** The privilege to create a catalog. */
+ public static class CreateCatalog implements Privilege {
+
+ private static final CreateCatalog INSTANCE = new CreateCatalog();
+
+ private CreateCatalog() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateCatalog get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_CATALOG;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create catalog";
+ }
+ }
+
+ /** The privilege to alter a catalog. */
+ public static class AlterCatalog implements Privilege {
+
+ private static final AlterCatalog INSTANCE = new AlterCatalog();
+
+ private AlterCatalog() {}
+
+ /** @return The instance of the privilege. */
+ public static AlterCatalog get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return ALTER_CATALOG;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "alter catalog";
+ }
+ }
+
+ /** The privilege to drop a catalog. */
+ public static class DropCatalog implements Privilege {
+
+ private static final DropCatalog INSTANCE = new DropCatalog();
+
+ private DropCatalog() {}
+
+ /** @return The instance of the privilege. */
+ public static DropCatalog get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DROP_CATALOG;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "drop catalog";
+ }
+ }
+
+ /** The privilege to use a catalog. */
+ public static class UseCatalog implements Privilege {
+ private static final UseCatalog INSTANCE = new UseCatalog();
+
+ /** @return The instance of the privilege. */
+ public static UseCatalog get() {
+ return INSTANCE;
+ }
+
+ private UseCatalog() {}
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return USE_CATALOG;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "use catalog";
+ }
+ }
+
+ /** The privilege to use a schema. */
+ public static class UseSchema implements Privilege {
+
+ private static final UseSchema INSTANCE = new UseSchema();
+
+ /** @return The instance of the privilege. */
+ public static UseSchema get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return USE_SCHEMA;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "use schema";
+ }
+ }
+
+ /** The privilege to create a schema. */
+ public static class CreateSchema implements Privilege {
+
+ private static final CreateSchema INSTANCE = new CreateSchema();
+
+ /** @return The instance of the privilege. */
+ public static CreateSchema get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_SCHEMA;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create schema";
+ }
+ }
+
+ /** The privilege to alter a schema. */
+ public static class AlterSchema implements Privilege {
+
+ private static final AlterSchema INSTANCE = new AlterSchema();
+
+ /** @return The instance of the privilege. */
+ public static AlterSchema get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return ALTER_SCHEMA;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "alter schema";
+ }
+ }
+
+ /** The privilege to drop a schema. */
+ public static class DropSchema implements Privilege {
+
+ private static final DropSchema INSTANCE = new DropSchema();
+
+ /** @return The instance of the privilege. */
+ public static DropSchema get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DROP_SCHEMA;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "drop schema";
+ }
+ }
+
+ /** The privilege to create a table. */
+ public static class CreateTable implements Privilege {
+
+ private static final CreateTable INSTANCE = new CreateTable();
+
+ private CreateTable() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateTable get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_TABLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create table";
+ }
+ }
+
+ /** The privilege to drop a table. */
+ public static class DropTable implements Privilege {
+
+ private static final DropTable INSTANCE = new DropTable();
+
+ private DropTable() {}
+
+ /** @return The instance of the privilege. */
+ public static DropTable get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DROP_TABLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "drop table";
+ }
+ }
+
+ /** The privilege to read a table. */
+ public static class ReadTable implements Privilege {
+
+ private static final ReadTable INSTANCE = new ReadTable();
+
+ private ReadTable() {}
+
+ /** @return The instance of the privilege. */
+ public static ReadTable get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return READ_TABLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "read table";
+ }
+ }
+
+ /** The privilege to write a table. */
+ public static class WriteTable implements Privilege {
+
+ private static final WriteTable INSTANCE = new WriteTable();
+
+ private WriteTable() {}
+
+ /** @return The instance of the privilege. */
+ public static WriteTable get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return WRITE_TABLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "write table";
+ }
+ }
+
+ /** The privilege to create a fileset. */
+ public static class CreateFileset implements Privilege {
+
+ private static final CreateFileset INSTANCE = new CreateFileset();
+
+ private CreateFileset() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateFileset get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_FILESET;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create fileset";
+ }
+ }
+
+ /** The privilege to drop a fileset. */
+ public static class DropFileset implements Privilege {
+
+ private static final DropFileset INSTANCE = new DropFileset();
+
+ private DropFileset() {}
/** @return The instance of the privilege. */
- public static LoadCatalog get() {
+ public static DropFileset get() {
return INSTANCE;
}
- private LoadCatalog() {}
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DROP_FILESET;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "drop fileset";
+ }
+ }
+
+ /** The privilege to read a fileset. */
+ public static class ReadFileset implements Privilege {
+
+ private static final ReadFileset INSTANCE = new ReadFileset();
+
+ private ReadFileset() {}
+
+ /** @return The instance of the privilege. */
+ public static ReadFileset get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return READ_FILESET;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "read fileset";
+ }
+ }
+
+ /** The privilege to write a fileset. */
+ public static class WriteFileset implements Privilege {
+
+ private static final WriteFileset INSTANCE = new WriteFileset();
+
+ private WriteFileset() {}
+
+ /** @return The instance of the privilege. */
+ public static WriteFileset get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return WRITE_FILESET;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "write fileset";
+ }
+ }
+
+ /** The privilege to create a topic. */
+ public static class CreateTopic implements Privilege {
+
+ private static final CreateTopic INSTANCE = new CreateTopic();
+
+ private CreateTopic() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateTopic get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_TOPIC;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create topic";
+ }
+ }
+
+ /** The privilege to drop a topic. */
+ public static class DropTopic implements Privilege {
+
+ private static final DropTopic INSTANCE = new DropTopic();
+
+ private DropTopic() {}
+
+ /** @return The instance of the privilege. */
+ public static DropTopic get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DROP_TOPIC;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "drop topic";
+ }
+ }
+
+ /** The privilege to read a topic. */
+ public static class ReadTopic implements Privilege {
+
+ private static final ReadTopic INSTANCE = new ReadTopic();
+
+ private ReadTopic() {}
+
+ /** @return The instance of the privilege. */
+ public static ReadTopic get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return READ_TOPIC;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "read topic";
+ }
+ }
+
+ /** The privilege to write a topic. */
+ public static class WriteTopic implements Privilege {
+
+ private static final WriteTopic INSTANCE = new WriteTopic();
+
+ private WriteTopic() {}
+
+ /** @return The instance of the privilege. */
+ public static WriteTopic get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return WRITE_TOPIC;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "write topic";
+ }
+ }
+
+ /** The privilege to manage a metalake. */
+ public static class ManageMetalake implements Privilege {
+
+ private static final ManageMetalake INSTANCE = new ManageMetalake();
+
+ private ManageMetalake() {}
+
+ /** @return The instance of the privilege. */
+ public static ManageMetalake get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return MANAGE_METALAKE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "manage metalake";
+ }
+ }
+
+ /** The privilege to manage a metalake. */
+ public static class CreateMetalake implements Privilege {
+
+ private static final CreateMetalake INSTANCE = new CreateMetalake();
+
+ private CreateMetalake() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateMetalake get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_METALAKE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create metalake";
+ }
+ }
+
+ /** The privilege to use a metalake. */
+ public static class UseMetalake implements Privilege {
+
+ private static final UseMetalake INSTANCE = new UseMetalake();
+
+ private UseMetalake() {}
+
+ /** @return The instance of the privilege. */
+ public static UseMetalake get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return USE_METALAKE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "use metalake";
+ }
+ }
+
+ /** The privilege to get a user. */
+ public static class GetUser implements Privilege {
+
+ private static final GetUser INSTANCE = new GetUser();
+
+ private GetUser() {}
+
+ /** @return The instance of the privilege. */
+ public static GetUser get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return GET_USER;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "get user";
+ }
+ }
+
+ /** The privilege to add a user. */
+ public static class AddUser implements Privilege {
+
+ private static final AddUser INSTANCE = new AddUser();
+
+ private AddUser() {}
+
+ /** @return The instance of the privilege. */
+ public static AddUser get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return ADD_USER;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "add user";
+ }
+ }
+
+ /** The privilege to remove a user. */
+ public static class RemoveUser implements Privilege {
+
+ private static final RemoveUser INSTANCE = new RemoveUser();
+
+ private RemoveUser() {}
+
+ /** @return The instance of the privilege. */
+ public static RemoveUser get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return REMOVE_USER;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "remove user";
+ }
+ }
+
+ /** The privilege to add a group. */
+ public static class AddGroup implements Privilege {
+
+ private static final AddGroup INSTANCE = new AddGroup();
+
+ private AddGroup() {}
+
+ /** @return The instance of the privilege. */
+ public static AddGroup get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return ADD_GROUP;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "add group";
+ }
+ }
+
+ /** The privilege to remove a group. */
+ public static class RemoveGroup implements Privilege {
+
+ private static final RemoveGroup INSTANCE = new RemoveGroup();
+
+ private RemoveGroup() {}
+
+ /** @return The instance of the privilege. */
+ public static RemoveGroup get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return REMOVE_GROUP;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "remove group";
+ }
+ }
+
+ /** The privilege to get a group. */
+ public static class GetGroup implements Privilege {
+
+ private static final GetGroup INSTANCE = new GetGroup();
+
+ private GetGroup() {}
+
+ /** @return The instance of the privilege. */
+ public static GetGroup get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return GET_GROUP;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "get group";
+ }
+ }
+
+ /** The privilege to create a role. */
+ public static class CreateRole implements Privilege {
+
+ private static final CreateRole INSTANCE = new CreateRole();
+
+ private CreateRole() {}
+
+ /** @return The instance of the privilege. */
+ public static CreateRole get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return CREATE_ROLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "create role";
+ }
+ }
+
+ /** The privilege to get a role. */
+ public static class GetRole implements Privilege {
+
+ private static final GetRole INSTANCE = new GetRole();
+
+ private GetRole() {}
+
+ /** @return The instance of the privilege. */
+ public static GetRole get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return GET_ROLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "get role";
+ }
+ }
+
+ /** The privilege to delete a role. */
+ public static class DeleteRole implements Privilege {
+
+ private static final DeleteRole INSTANCE = new DeleteRole();
+
+ private DeleteRole() {}
+
+ /** @return The instance of the privilege. */
+ public static DeleteRole get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return DELETE_ROLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "delete role";
+ }
+ }
+
+ /** The privilege to grant a role to the user or the group. */
+ public static class GrantRole implements Privilege {
+
+ private static final GrantRole INSTANCE = new GrantRole();
+
+ private GrantRole() {}
+
+ /** @return The instance of the privilege. */
+ public static GrantRole get() {
+ return INSTANCE;
+ }
+
+ /** @return The generic name of the privilege. */
+ @Override
+ public Name name() {
+ return GRANT_ROLE;
+ }
+
+ /** @return A readable string representation for the privilege. */
+ @Override
+ public String simpleString() {
+ return "grant role";
+ }
+ }
+
+ /** The privilege to revoke a role from the user or the group. */
+ public static class RevokeRole implements Privilege {
+
+ private static final RevokeRole INSTANCE = new RevokeRole();
+
+ private RevokeRole() {}
+
+ /** @return The instance of the privilege. */
+ public static RevokeRole get() {
+ return INSTANCE;
+ }
/** @return The generic name of the privilege. */
@Override
public Name name() {
- return Name.LOAD_CATALOG;
+ return REVOKE_ROLE;
}
/** @return A readable string representation for the privilege. */
@Override
public String simpleString() {
- return "load catalog";
+ return "revoke role";
}
}
}
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
index b3d8aa5ce2..e045efa381 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObject.java
@@ -4,21 +4,42 @@
*/
package com.datastrato.gravitino.authorization;
-import com.datastrato.gravitino.annotation.Evolving;
+import com.datastrato.gravitino.annotation.Unstable;
import javax.annotation.Nullable;
/**
* The securable object is the entity which access can be granted. Unless allowed by a grant, access
- * is denied. Gravitino organizes the securable objects using tree structure. The securable object
- * may be a catalog, a table or a schema, etc. For example, `catalog1.schema1.table1` represents a
- * table named `table1`. It's in the schema named `schema1`. The schema is in the catalog named
- * `catalog1`. Similarly, `catalog1.schema1.topic1` can represent a topic.
- * `catalog1.schema1.fileset1` can represent a fileset. `*` represents all the catalogs. If you want
- * to use other securable objects which represents all entities," you can use their parent entity,
+ * is denied. Gravitino organizes the securable objects using tree structure. <br>
+ * There are three fields in the securable object: parent, name, and type. <br>
+ * The types include 6 kinds: CATALOG,SCHEMA,TABLE,FILESET,TOPIC and METALAKE. <br>
+ * You can use the helper class `SecurableObjects` to create the securable object which you need.
+ * <br>
+ * You can use full name and type of the securable object in the RESTFUL API. <br>
+ * For example, <br>
+ * If you want to use a catalog named `catalog1`, you can use the code
+ * `SecurableObjects.ofCatalog("catalog1")` to create the securable object, or you can use full name
+ * `catalog1` and type `CATALOG` in the RESTFUL API. <br>
+ * If you want to use a schema named `schema1` in the catalog named `catalog1`, you can use the code
+ * `SecurableObjects.ofSchema(catalog, "schema1")` to create the securable object, or you can use
+ * full name `catalog1.schema1` and type `SCHEMA` in the RESTFUL API. <br>
+ * If you want to use a table named `table1` in the schema named `schema1`, you can use the code
+ * `SecurableObjects.ofTable(schema, "table1")` to create the securable object, or you can use full
+ * name `catalog1.schema1.table1` and type `TABLE` in the RESTFUL API. <br>
+ * If you want to use a topic named `topic1` in the schema named `schema1`, you can use the code
+ * `SecurableObjects.ofTopic(schema, "topic1")` to create the securable object, or you can use full
+ * name `catalog1.schema1.topic1` and type `TOPIC` in the RESTFUL API. <br>
+ * If you want to use a fileset named `fileset1` in the schema named `schema1`, you can use the code
+ * `SecurableObjects.ofFileset(schema, "fileset1)` to create the securable object, or you can use
+ * full name `catalog1.schema1.fileset1` and type `FILESET` in the RESTFUL API. <br>
+ * If you want to use a metalake named `metalake1`, you can use the code
+ * `SecurableObjects.ofMetalake("metalake1")` to create the securable object, or you can use full
+ * name `metalake1` and type `METALAKE` in the RESTFUL API. <br>
+ * If you want to use all the catalogs, you use the metalake to represent them. Likely, you can use
+ * their common parent to represent all securable objects.<br>
* For example if you want to have read table privileges of all tables of `catalog1.schema1`, " you
* can use add `read table` privilege for `catalog1.schema1` directly
*/
-@Evolving
+@Unstable
public interface SecurableObject {
/**
@@ -36,4 +57,49 @@ public interface SecurableObject {
* @return The name of the securable object.
*/
String name();
+
+ /**
+ * The full name of th securable object. If the parent isn't null, the full name will join the
+ * parent full name and the name with `.`, otherwise will return the name.
+ *
+ * @return The name of the securable object.
+ */
+ String fullName();
+
+ /**
+ * The type of securable object
+ *
+ * @return The type of securable object.
+ */
+ Type type();
+
+ /**
+ * The type of securable object in the Gravitino system. Every type will map one kind of the
+ * entity of the underlying system.
+ */
+ enum Type {
+ /**
+ * A catalog is a collection of metadata from a specific metadata source, like Apache Hive
+ * catalog, Apache Iceberg catalog, JDBC catalog, etc.
+ */
+ CATALOG,
+ /**
+ * A schema is a sub collection of the catalog. The schema can contain filesets, tables, topics,
+ * etc.
+ */
+ SCHEMA,
+ /** A fileset is mapped to a directory on a file system like HDFS, S3, ADLS, GCS, etc. */
+ FILESET,
+ /** A table is mapped the table of relational data sources like Apache Hive, MySQL, etc. */
+ TABLE,
+ /**
+ * A topic is mapped the topic of messaging data sources like Apache Kafka, Apache Pulsar, etc.
+ */
+ TOPIC,
+ /**
+ * A metalake is a concept of tenant. It means an organization. A metalake contains many data
+ * sources.
+ */
+ METALAKE
+ }
}
diff --git a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
index 80d68836b8..2c9d99bde7 100644
--- a/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
+++ b/api/src/main/java/com/datastrato/gravitino/authorization/SecurableObjects.java
@@ -6,6 +6,9 @@ package com.datastrato.gravitino.authorization;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
@@ -15,40 +18,15 @@ public class SecurableObjects {
private static final Splitter DOT = Splitter.on('.');
/**
- * Create the {@link SecurableObject} with the given names.
+ * Create the metalake {@link SecurableObject} with the given metalake name.
*
- * @param names The names of the securable object.
- * @return The created {@link SecurableObject}
+ * @param metalake The metalake name
+ * @return The created metalake {@link SecurableObject}
*/
- public static SecurableObject of(String... names) {
- if (names == null) {
- throw new IllegalArgumentException("Cannot create a securable object with null names");
- }
-
- if (names.length == 0) {
- throw new IllegalArgumentException("Cannot create a securable object with no names");
- }
-
- SecurableObject parent = null;
- for (String name : names) {
- if (name == null) {
- throw new IllegalArgumentException("Cannot create a securable object with null name");
- }
+ public static SecurableObject ofMetalake(String metalake) {
+ checkName(metalake);
- if (name.equals("*")) {
- throw new IllegalArgumentException(
- "Cannot create a securable object with `*` name. If you want to use a securable object which represents all catalogs,"
- + " you use the method `ofAllCatalogs`."
- + " If you want to create an another securable object which represents all entities,"
- + " you can use its parent entity, For example,"
- + " if you want to have read table privileges of all tables of `catalog1.schema1`,"
- + " you can use add `read table` privilege for `catalog1.schema1` directly");
- }
-
- parent = new SecurableObjectImpl(parent, name);
- }
-
- return parent;
+ return new SecurableObjectImpl(null, metalake, SecurableObject.Type.METALAKE);
}
/**
@@ -58,7 +36,9 @@ public class SecurableObjects {
* @return The created catalog {@link SecurableObject}
*/
public static SecurableObject ofCatalog(String catalog) {
- return of(catalog);
+ checkName(catalog);
+
+ return new SecurableObjectImpl(null, catalog, SecurableObject.Type.CATALOG);
}
/**
@@ -71,8 +51,9 @@ public class SecurableObjects {
*/
public static SecurableObject ofSchema(SecurableObject catalog, String schema) {
checkCatalog(catalog);
+ checkName(schema);
- return of(catalog.name(), schema);
+ return new SecurableObjectImpl(catalog, schema, SecurableObject.Type.SCHEMA);
}
/**
@@ -84,8 +65,9 @@ public class SecurableObjects {
*/
public static SecurableObject ofTable(SecurableObject schema, String table) {
checkSchema(schema);
+ checkName(table);
- return of(schema.parent().name(), schema.name(), table);
+ return new SecurableObjectImpl(schema, table, SecurableObject.Type.TABLE);
}
/**
@@ -97,8 +79,9 @@ public class SecurableObjects {
*/
public static SecurableObject ofTopic(SecurableObject schema, String topic) {
checkSchema(schema);
+ checkName(topic);
- return of(schema.parent().name(), schema.name(), topic);
+ return new SecurableObjectImpl(schema, topic, SecurableObject.Type.TOPIC);
}
/**
@@ -111,25 +94,32 @@ public class SecurableObjects {
*/
public static SecurableObject ofFileset(SecurableObject schema, String fileset) {
checkSchema(schema);
+ checkName(fileset);
- return of(schema.parent().name(), schema.name(), fileset);
+ return new SecurableObjectImpl(schema, fileset, SecurableObject.Type.FILESET);
}
/**
- * All catalogs is a special securable object .You can give the securable object the privileges
- * `LOAD CATALOG`, `CREATE CATALOG`, etc. It means that you can load any catalog and create any
- * which doesn't exist.
+ * All metalakes is a special securable object .You can give the securable object the privileges
+ * `CREATE METALAKE`, etc. It means that you can create any which doesn't exist. This securable
+ * object is only used for metalake admin. You can't grant any privilege to this securable object.
+ * You can't bind this securable object to any role, too.
*
* @return The created {@link SecurableObject}
*/
- public static SecurableObject ofAllCatalogs() {
- return ALL_CATALOGS;
+ public static SecurableObject ofAllMetalakes() {
+ return ALL_METALAKES;
}
private static void checkSchema(SecurableObject schema) {
if (schema == null) {
throw new IllegalArgumentException("Securable schema object can't be null");
}
+
+ if (schema.type() != SecurableObject.Type.SCHEMA) {
+ throw new IllegalArgumentException("Securable schema object type must be SCHEMA");
+ }
+
checkCatalog(schema.parent());
}
@@ -138,22 +128,29 @@ public class SecurableObjects {
throw new IllegalArgumentException("Securable catalog object can't be null");
}
+ if (catalog.type() != SecurableObject.Type.CATALOG) {
+ throw new IllegalArgumentException("Securable catalog type must be CATALOG");
+ }
+
if (catalog.parent() != null) {
throw new IllegalArgumentException(
String.format("The parent of securable catalog object %s must be null", catalog.name()));
}
}
- private static final SecurableObject ALL_CATALOGS = new SecurableObjectImpl(null, "*");
+ private static final SecurableObject ALL_METALAKES =
+ new SecurableObjectImpl(null, "*", SecurableObject.Type.METALAKE);
private static class SecurableObjectImpl implements SecurableObject {
private final SecurableObject parent;
private final String name;
+ private final Type type;
- SecurableObjectImpl(SecurableObject parent, String name) {
+ SecurableObjectImpl(SecurableObject parent, String name, Type type) {
this.parent = parent;
this.name = name;
+ this.type = type;
}
@Override
@@ -166,9 +163,19 @@ public class SecurableObjects {
return name;
}
+ @Override
+ public String fullName() {
+ return toString();
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
@Override
public int hashCode() {
- return Objects.hash(parent, name);
+ return Objects.hash(parent, name, type);
}
@Override
@@ -188,26 +195,133 @@ public class SecurableObjects {
SecurableObject otherSecurableObject = (SecurableObject) other;
return Objects.equals(parent, otherSecurableObject.parent())
- && Objects.equals(name, otherSecurableObject.name());
+ && Objects.equals(name, otherSecurableObject.name())
+ && Objects.equals(type, otherSecurableObject.type());
}
}
/**
- * Create a {@link SecurableObject} from the given identifier string.
+ * Create a {@link SecurableObject} from the given full name.
*
- * @param securableObjectIdentifier The identifier string
+ * @param fullName The full name of securable object.
+ * @param type The securable object type.
* @return The created {@link SecurableObject}
*/
- public static SecurableObject parse(String securableObjectIdentifier) {
- if ("*".equals(securableObjectIdentifier)) {
- return SecurableObjects.ofAllCatalogs();
+ public static SecurableObject parse(String fullName, SecurableObject.Type type) {
+ if ("*".equals(fullName)) {
+ if (type != SecurableObject.Type.METALAKE) {
+ throw new IllegalArgumentException("If securable object isn't metalake, it can't be `*`");
+ }
+ return SecurableObjects.ofAllMetalakes();
}
- if (StringUtils.isBlank(securableObjectIdentifier)) {
+ if (StringUtils.isBlank(fullName)) {
throw new IllegalArgumentException("securable object identifier can't be blank");
}
- Iterable<String> parts = DOT.split(securableObjectIdentifier);
- return SecurableObjects.of(Iterables.toArray(parts, String.class));
+ Iterable<String> parts = DOT.split(fullName);
+ return SecurableObjects.of(type, Iterables.toArray(parts, String.class));
+ }
+
+ /**
+ * Create the {@link SecurableObject} with the given names.
+ *
+ * @param type The securable object type.
+ * @param names The names of the securable object.
+ * @return The created {@link SecurableObject}
+ */
+ static SecurableObject of(SecurableObject.Type type, String... names) {
+
+ if (names == null) {
+ throw new IllegalArgumentException("Cannot create a securable object with null names");
+ }
+
+ if (names.length == 0) {
+ throw new IllegalArgumentException("Cannot create a securable object with no names");
+ }
+
+ if (type == null) {
+ throw new IllegalArgumentException("Cannot create a securable object with no type");
+ }
+
+ if (names.length > 3) {
+ throw new IllegalArgumentException(
+ "Cannot create a securable object with the name length which is greater than 3");
+ }
+
+ if (names.length == 1
+ && type != SecurableObject.Type.CATALOG
+ && type != SecurableObject.Type.METALAKE) {
+ throw new IllegalArgumentException(
+ "If the length of names is 1, it must be the CATALOG or METALAKE type");
+ }
+
+ if (names.length == 2 && type != SecurableObject.Type.SCHEMA) {
+ throw new IllegalArgumentException("If the length of names is 2, it must be the SCHEMA type");
+ }
+
+ if (names.length == 3
+ && type != SecurableObject.Type.FILESET
+ && type != SecurableObject.Type.TABLE
+ && type != SecurableObject.Type.TOPIC) {
+ throw new IllegalArgumentException(
+ "If the length of names is 3, it must be FILESET, TABLE or TOPIC");
+ }
+
+ List<SecurableObject.Type> types = Lists.newArrayList(type);
+
+ // Find all the types of the parent securable object.
+ SecurableObject.Type curType = type;
+ List<String> reverseNames = Lists.newArrayList(names);
+ Collections.reverse(reverseNames);
+ for (String ignored : reverseNames) {
+ types.add(curType);
+ curType = getParentSecurableObjectType(curType);
+ }
+ Collections.reverse(types);
+
+ SecurableObject parent = null;
+ int level = 0;
+ for (String name : names) {
+ checkName(name);
+
+ parent = new SecurableObjectImpl(parent, name, types.get(level));
+
+ level++;
+ }
+
+ return parent;
+ }
+
+ private static SecurableObject.Type getParentSecurableObjectType(SecurableObject.Type type) {
+ switch (type) {
+ case FILESET:
+ return SecurableObject.Type.SCHEMA;
+
+ case TOPIC:
+ return SecurableObject.Type.SCHEMA;
+
+ case TABLE:
+ return SecurableObject.Type.SCHEMA;
+
+ case SCHEMA:
+ return SecurableObject.Type.CATALOG;
+
+ case CATALOG:
+ return SecurableObject.Type.METALAKE;
+
+ default:
+ return null;
+ }
+ }
+
+ private static void checkName(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Cannot create a securable object with null name");
+ }
+
+ if ("*".equals(name)) {
+ throw new IllegalArgumentException("Cannot create a securable object with `*` name.");
+ }
}
}
diff --git a/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java b/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java
new file mode 100644
index 0000000000..7697c896f3
--- /dev/null
+++ b/api/src/test/java/com/datastrato/gravitino/authorization/TestSecurableObjects.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.authorization;
+
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.CATALOG;
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.FILESET;
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.METALAKE;
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.SCHEMA;
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.TABLE;
+import static com.datastrato.gravitino.authorization.SecurableObject.Type.TOPIC;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestSecurableObjects {
+
+ @Test
+ public void testSecurableObjects() {
+ SecurableObject allMetalakes = SecurableObjects.ofAllMetalakes();
+ Assertions.assertEquals("*", allMetalakes.fullName());
+ Assertions.assertEquals(METALAKE, allMetalakes.type());
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> SecurableObjects.of(METALAKE, "*"));
+
+ SecurableObject metalake = SecurableObjects.ofMetalake("metalake");
+ Assertions.assertEquals("metalake", metalake.fullName());
+ Assertions.assertEquals(METALAKE, metalake.type());
+ SecurableObject anotherMetalake = SecurableObjects.of(METALAKE, "metalake");
+ Assertions.assertEquals(metalake, anotherMetalake);
+
+ SecurableObject catalog = SecurableObjects.ofCatalog("catalog");
+ Assertions.assertEquals("catalog", catalog.fullName());
+ Assertions.assertEquals(CATALOG, catalog.type());
+ SecurableObject anotherCatalog = SecurableObjects.of(CATALOG, "catalog");
+ Assertions.assertEquals(catalog, anotherCatalog);
+
+ SecurableObject schema = SecurableObjects.ofSchema(catalog, "schema");
+ Assertions.assertEquals("catalog.schema", schema.fullName());
+ Assertions.assertEquals(SCHEMA, schema.type());
+ SecurableObject anotherSchema = SecurableObjects.of(SCHEMA, "catalog", "schema");
+ Assertions.assertEquals(schema, anotherSchema);
+
+ SecurableObject table = SecurableObjects.ofTable(schema, "table");
+ Assertions.assertEquals("catalog.schema.table", table.fullName());
+ Assertions.assertEquals(TABLE, table.type());
+ SecurableObject anotherTable = SecurableObjects.of(TABLE, "catalog", "schema", "table");
+ Assertions.assertEquals(table, anotherTable);
+
+ SecurableObject fileset = SecurableObjects.ofFileset(schema, "fileset");
+ Assertions.assertEquals("catalog.schema.fileset", fileset.fullName());
+ Assertions.assertEquals(FILESET, fileset.type());
+ SecurableObject anotherFileset = SecurableObjects.of(FILESET, "catalog", "schema", "fileset");
+ Assertions.assertEquals(fileset, anotherFileset);
+
+ SecurableObject topic = SecurableObjects.ofTopic(schema, "topic");
+ Assertions.assertEquals("catalog.schema.topic", topic.fullName());
+ Assertions.assertEquals(TOPIC, topic.type());
+
+ SecurableObject anotherTopic = SecurableObjects.of(TOPIC, "catalog", "schema", "topic");
+ Assertions.assertEquals(topic, anotherTopic);
+
+ Exception e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> SecurableObjects.of(METALAKE, "metalake", "catalog"));
+ Assertions.assertTrue(e.getMessage().contains("length of names is 2"));
+ e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> SecurableObjects.of(CATALOG, "metalake", "catalog"));
+ Assertions.assertTrue(e.getMessage().contains("length of names is 2"));
+
+ e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> SecurableObjects.of(TABLE, "metalake"));
+ Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
+ e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> SecurableObjects.of(TOPIC, "metalake"));
+ Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
+ e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> SecurableObjects.of(FILESET, "metalake"));
+ Assertions.assertTrue(e.getMessage().contains("the length of names is 1"));
+
+ e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> SecurableObjects.of(SCHEMA, "catalog", "schema", "table"));
+ Assertions.assertTrue(e.getMessage().contains("the length of names is 3"));
+ }
+}
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java
index c109c1a53e..c6dc165103 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java
@@ -9,9 +9,11 @@ import static com.datastrato.gravitino.dto.util.DTOConverters.toFunctionArg;
import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.CatalogChange;
import com.datastrato.gravitino.MetalakeChange;
+import com.datastrato.gravitino.authorization.SecurableObject;
import com.datastrato.gravitino.dto.AuditDTO;
import com.datastrato.gravitino.dto.CatalogDTO;
import com.datastrato.gravitino.dto.MetalakeDTO;
+import com.datastrato.gravitino.dto.authorization.SecurableObjectDTO;
import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;
import com.datastrato.gravitino.dto.requests.FilesetUpdateRequest;
import com.datastrato.gravitino.dto.requests.MetalakeUpdateRequest;
@@ -271,4 +273,11 @@ class DTOConverters {
"Unknown column change type: " + change.getClass().getSimpleName());
}
}
+
+ static SecurableObjectDTO toSecurableObject(SecurableObject securableObject) {
+ return SecurableObjectDTO.builder()
+ .withFullName(securableObject.fullName())
+ .withType(securableObject.type())
+ .build();
+ }
}
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
index 4cea0f062d..aaa15cf41a 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
@@ -451,7 +451,7 @@ public class GravitinoAdminClient extends GravitinoClientBase implements Support
.map(Privilege::name)
.map(Objects::toString)
.collect(Collectors.toList()),
- securableObject.toString());
+ DTOConverters.toSecurableObject(securableObject));
req.validate();
RoleResponse resp =
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java
index 560bb52e49..97bbcd0183 100644
--- a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java
@@ -11,9 +11,11 @@ import static org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR;
import com.datastrato.gravitino.authorization.Privileges;
import com.datastrato.gravitino.authorization.Role;
+import com.datastrato.gravitino.authorization.SecurableObject;
import com.datastrato.gravitino.authorization.SecurableObjects;
import com.datastrato.gravitino.dto.AuditDTO;
import com.datastrato.gravitino.dto.authorization.RoleDTO;
+import com.datastrato.gravitino.dto.authorization.SecurableObjectDTO;
import com.datastrato.gravitino.dto.requests.RoleCreateRequest;
import com.datastrato.gravitino.dto.responses.DeleteResponse;
import com.datastrato.gravitino.dto.responses.ErrorResponse;
@@ -45,7 +47,13 @@ public class TestRole extends TestBase {
String rolePath = withSlash(String.format(API_METALAKES_ROLES_PATH, metalakeName, ""));
RoleCreateRequest request =
new RoleCreateRequest(
- roleName, ImmutableMap.of("k1", "v1"), Lists.newArrayList("LOAD_CATALOG"), "catalog");
+ roleName,
+ ImmutableMap.of("k1", "v1"),
+ Lists.newArrayList("USE_CATALOG"),
+ SecurableObjectDTO.builder()
+ .withFullName("catalog")
+ .withType(SecurableObject.Type.CATALOG)
+ .build());
RoleDTO mockRole = mockRoleDTO(roleName);
RoleResponse roleResponse = new RoleResponse(mockRole);
@@ -57,7 +65,9 @@ public class TestRole extends TestBase {
roleName,
ImmutableMap.of("k1", "v1"),
SecurableObjects.ofCatalog("catalog"),
- Lists.newArrayList(Privileges.LoadCatalog.get()));
+ Lists.newArrayList(Privileges.UseCatalog.get()));
+ Assertions.assertEquals(1L, Privileges.CreateCatalog.get().name().getLowBits());
+ Assertions.assertEquals(0L, Privileges.CreateCatalog.get().name().getHighBits());
Assertions.assertNotNull(createdRole);
assertRole(createdRole, mockRole);
@@ -75,7 +85,7 @@ public class TestRole extends TestBase {
roleName,
ImmutableMap.of("k1", "v1"),
SecurableObjects.ofCatalog("catalog"),
- Lists.newArrayList(Privileges.LoadCatalog.get())));
+ Lists.newArrayList(Privileges.UseCatalog.get())));
Assertions.assertEquals("role already exists", ex.getMessage());
// test NoSuchMetalakeException
@@ -91,7 +101,7 @@ public class TestRole extends TestBase {
roleName,
ImmutableMap.of("k1", "v1"),
SecurableObjects.ofCatalog("catalog"),
- Lists.newArrayList(Privileges.LoadCatalog.get())));
+ Lists.newArrayList(Privileges.UseCatalog.get())));
Assertions.assertEquals("metalake not found", ex.getMessage());
// test RuntimeException
@@ -105,7 +115,7 @@ public class TestRole extends TestBase {
roleName,
ImmutableMap.of("k1", "v1"),
SecurableObjects.ofCatalog("catalog"),
- Lists.newArrayList(Privileges.LoadCatalog.get())),
+ Lists.newArrayList(Privileges.UseCatalog.get())),
"internal error");
}
@@ -145,6 +155,15 @@ public class TestRole extends TestBase {
buildMockResource(Method.GET, rolePath, null, errResp3, SC_SERVER_ERROR);
Assertions.assertThrows(
RuntimeException.class, () -> client.getRole(metalakeName, roleName), "internal error");
+
+ // test SecurableDTO use parent method
+ Role testParentRole = mockHasParentRoleDTO("test");
+ Assertions.assertEquals("schema", testParentRole.securableObject().name());
+ Assertions.assertEquals(SecurableObject.Type.SCHEMA, testParentRole.securableObject().type());
+ Assertions.assertEquals("catalog", testParentRole.securableObject().parent().fullName());
+ Assertions.assertEquals("catalog", testParentRole.securableObject().parent().name());
+ Assertions.assertEquals(
+ SecurableObject.Type.CATALOG, testParentRole.securableObject().parent().type());
}
@Test
@@ -172,8 +191,20 @@ public class TestRole extends TestBase {
return RoleDTO.builder()
.withName(name)
.withProperties(ImmutableMap.of("k1", "v1"))
- .withSecurableObject(SecurableObjects.of("catalog"))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(DTOConverters.toSecurableObject(SecurableObjects.ofCatalog("catalog")))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
+ .build();
+ }
+
+ private RoleDTO mockHasParentRoleDTO(String name) {
+ SecurableObject catalog = SecurableObjects.ofCatalog("catalog");
+ return RoleDTO.builder()
+ .withName(name)
+ .withProperties(ImmutableMap.of("k1", "v1"))
+ .withSecurableObject(
+ DTOConverters.toSecurableObject(SecurableObjects.ofSchema(catalog, "schema")))
+ .withPrivileges(Lists.newArrayList(Privileges.UseSchema.get()))
.withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
.build();
}
@@ -182,6 +213,6 @@ public class TestRole extends TestBase {
Assertions.assertEquals(expected.name(), actual.name());
Assertions.assertEquals(expected.privileges(), actual.privileges());
Assertions.assertEquals(
- expected.securableObject().toString(), actual.securableObject().toString());
+ expected.securableObject().fullName(), actual.securableObject().fullName());
}
}
diff --git a/common/src/main/java/com/datastrato/gravitino/dto/authorization/RoleDTO.java b/common/src/main/java/com/datastrato/gravitino/dto/authorization/RoleDTO.java
index 2f50da3a35..6a9c24fa3a 100644
--- a/common/src/main/java/com/datastrato/gravitino/dto/authorization/RoleDTO.java
+++ b/common/src/main/java/com/datastrato/gravitino/dto/authorization/RoleDTO.java
@@ -9,7 +9,6 @@ import com.datastrato.gravitino.authorization.Privilege;
import com.datastrato.gravitino.authorization.Privileges;
import com.datastrato.gravitino.authorization.Role;
import com.datastrato.gravitino.authorization.SecurableObject;
-import com.datastrato.gravitino.authorization.SecurableObjects;
import com.datastrato.gravitino.dto.AuditDTO;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
@@ -39,7 +38,7 @@ public class RoleDTO implements Role {
private List<String> privileges;
@JsonProperty("securableObject")
- private String securableObject;
+ private SecurableObjectDTO securableObject;
/** Default constructor for Jackson deserialization. */
protected RoleDTO() {}
@@ -57,7 +56,7 @@ public class RoleDTO implements Role {
String name,
Map<String, String> properties,
List<String> privileges,
- String securableObject,
+ SecurableObjectDTO securableObject,
AuditDTO audit) {
this.name = name;
this.audit = audit;
@@ -103,7 +102,7 @@ public class RoleDTO implements Role {
*/
@Override
public SecurableObject securableObject() {
- return SecurableObjects.parse(securableObject);
+ return securableObject;
}
/** @return The audit information of the Role DTO. */
@@ -141,7 +140,7 @@ public class RoleDTO implements Role {
protected Map<String, String> properties;
/** The securable object of the role. */
- protected SecurableObject securableObject;
+ protected SecurableObjectDTO securableObject;
/**
* Sets the name of the role.
@@ -188,7 +187,7 @@ public class RoleDTO implements Role {
* @param securableObject The securableObject of the role.
* @return The builder instance.
*/
- public S withSecurableObject(SecurableObject securableObject) {
+ public S withSecurableObject(SecurableObjectDTO securableObject) {
this.securableObject = securableObject;
return (S) this;
}
@@ -224,7 +223,7 @@ public class RoleDTO implements Role {
.map(Privilege::name)
.map(Objects::toString)
.collect(Collectors.toList()),
- securableObject.toString(),
+ securableObject,
audit);
}
}
diff --git a/common/src/main/java/com/datastrato/gravitino/dto/authorization/SecurableObjectDTO.java b/common/src/main/java/com/datastrato/gravitino/dto/authorization/SecurableObjectDTO.java
new file mode 100644
index 0000000000..abde242dd7
--- /dev/null
+++ b/common/src/main/java/com/datastrato/gravitino/dto/authorization/SecurableObjectDTO.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.dto.authorization;
+
+import com.datastrato.gravitino.authorization.SecurableObject;
+import com.datastrato.gravitino.authorization.SecurableObjects;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+
+/** Data transfer object representing a securable object. */
+public class SecurableObjectDTO implements SecurableObject {
+
+ @JsonProperty("fullName")
+ private String fullName;
+
+ @JsonProperty("type")
+ private Type type;
+
+ private SecurableObject parent;
+ private String name;
+
+ /** Default constructor for Jackson deserialization. */
+ protected SecurableObjectDTO() {}
+
+ /**
+ * Creates a new instance of RoleDTO.
+ *
+ * @param fullName The name of the Role DTO.
+ * @param type The type of the securable object.
+ */
+ protected SecurableObjectDTO(String fullName, Type type) {
+ SecurableObject securableObject = SecurableObjects.parse(fullName, type);
+ this.type = type;
+ this.fullName = fullName;
+ this.parent = securableObject.parent();
+ this.name = securableObject.name();
+ }
+
+ @Nullable
+ @Override
+ public SecurableObject parent() {
+ return parent;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String fullName() {
+ return fullName;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ /** @return the builder for creating a new instance of SecurableObjectDTO. */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /** Builder for {@link SecurableObjectDTO}. */
+ public static class Builder {
+ private String fullName;
+ private Type type;
+
+ /**
+ * Sets the full name of the securable object.
+ *
+ * @param fullName The full name of the securable object.
+ * @return The builder instance.
+ */
+ public Builder withFullName(String fullName) {
+ this.fullName = fullName;
+ return this;
+ }
+
+ /**
+ * Sets the type of the securable object.
+ *
+ * @param type The type of the securable object.
+ * @return The builder instance.
+ */
+ public Builder withType(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Builds an instance of SecurableObjectDTO using the builder's properties.
+ *
+ * @return An instance of SecurableObjectDTO.
+ * @throws IllegalArgumentException If the full name or type are not set.
+ */
+ public SecurableObjectDTO build() {
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(fullName), "full name cannot be null or empty");
+
+ Preconditions.checkArgument(type != null, "type cannot be null");
+
+ return new SecurableObjectDTO(fullName, type);
+ }
+ }
+}
diff --git a/common/src/main/java/com/datastrato/gravitino/dto/requests/RoleCreateRequest.java b/common/src/main/java/com/datastrato/gravitino/dto/requests/RoleCreateRequest.java
index f2deaf72f9..89b11de658 100644
--- a/common/src/main/java/com/datastrato/gravitino/dto/requests/RoleCreateRequest.java
+++ b/common/src/main/java/com/datastrato/gravitino/dto/requests/RoleCreateRequest.java
@@ -4,6 +4,7 @@
*/
package com.datastrato.gravitino.dto.requests;
+import com.datastrato.gravitino.dto.authorization.SecurableObjectDTO;
import com.datastrato.gravitino.rest.RESTRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
@@ -37,7 +38,7 @@ public class RoleCreateRequest implements RESTRequest {
private List<String> privileges;
@JsonProperty("securableObject")
- private String securableObject;
+ private SecurableObjectDTO securableObject;
/** Default constructor for RoleCreateRequest. (Used for Jackson deserialization.) */
public RoleCreateRequest() {
@@ -56,7 +57,7 @@ public class RoleCreateRequest implements RESTRequest {
String name,
Map<String, String> properties,
List<String> privileges,
- String securableObject) {
+ SecurableObjectDTO securableObject) {
super();
this.name = name;
this.properties = properties;
diff --git a/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java b/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java
index ad93bfbf56..be7a6691cc 100644
--- a/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java
+++ b/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java
@@ -11,12 +11,14 @@ import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.Metalake;
import com.datastrato.gravitino.authorization.Group;
import com.datastrato.gravitino.authorization.Role;
+import com.datastrato.gravitino.authorization.SecurableObject;
import com.datastrato.gravitino.authorization.User;
import com.datastrato.gravitino.dto.AuditDTO;
import com.datastrato.gravitino.dto.CatalogDTO;
import com.datastrato.gravitino.dto.MetalakeDTO;
import com.datastrato.gravitino.dto.authorization.GroupDTO;
import com.datastrato.gravitino.dto.authorization.RoleDTO;
+import com.datastrato.gravitino.dto.authorization.SecurableObjectDTO;
import com.datastrato.gravitino.dto.authorization.UserDTO;
import com.datastrato.gravitino.dto.file.FilesetDTO;
import com.datastrato.gravitino.dto.messaging.TopicDTO;
@@ -384,13 +386,30 @@ public class DTOConverters {
return RoleDTO.builder()
.withName(role.name())
- .withSecurableObject(role.securableObject())
+ .withSecurableObject(toDTO(role.securableObject()))
.withPrivileges(role.privileges())
.withProperties(role.properties())
.withAudit(toDTO(role.auditInfo()))
.build();
}
+ /**
+ * Converts a securable object implementation to a SecurableObjectDTO.
+ *
+ * @param securableObject The securable object implementation.
+ * @return The securable object DTO.
+ */
+ public static SecurableObjectDTO toDTO(SecurableObject securableObject) {
+ if (securableObject instanceof SecurableObjectDTO) {
+ return (SecurableObjectDTO) securableObject;
+ }
+
+ return SecurableObjectDTO.builder()
+ .withFullName(securableObject.fullName())
+ .withType(securableObject.type())
+ .build();
+ }
+
/**
* Converts a Expression to an FunctionArg DTO.
*
diff --git a/common/src/test/java/com/datastrato/gravitino/dto/responses/TestResponses.java b/common/src/test/java/com/datastrato/gravitino/dto/responses/TestResponses.java
index 96b27b0e85..f4515c726b 100644
--- a/common/src/test/java/com/datastrato/gravitino/dto/responses/TestResponses.java
+++ b/common/src/test/java/com/datastrato/gravitino/dto/responses/TestResponses.java
@@ -23,6 +23,7 @@ import com.datastrato.gravitino.dto.rel.ColumnDTO;
import com.datastrato.gravitino.dto.rel.SchemaDTO;
import com.datastrato.gravitino.dto.rel.TableDTO;
import com.datastrato.gravitino.dto.rel.partitioning.Partitioning;
+import com.datastrato.gravitino.dto.util.DTOConverters;
import com.datastrato.gravitino.rel.types.Types;
import com.google.common.collect.Lists;
import java.time.Instant;
@@ -267,8 +268,8 @@ public class TestResponses {
RoleDTO role =
RoleDTO.builder()
.withName("role1")
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
- .withSecurableObject(SecurableObjects.ofCatalog("catalog"))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
+ .withSecurableObject(DTOConverters.toDTO(SecurableObjects.ofCatalog("catalog")))
.withAudit(audit)
.build();
RoleResponse response = new RoleResponse(role);
diff --git a/core/src/main/java/com/datastrato/gravitino/proto/RoleEntitySerDe.java b/core/src/main/java/com/datastrato/gravitino/proto/RoleEntitySerDe.java
index 841a8f9c15..92d7623b13 100644
--- a/core/src/main/java/com/datastrato/gravitino/proto/RoleEntitySerDe.java
+++ b/core/src/main/java/com/datastrato/gravitino/proto/RoleEntitySerDe.java
@@ -6,6 +6,7 @@ package com.datastrato.gravitino.proto;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.authorization.Privileges;
+import com.datastrato.gravitino.authorization.SecurableObject;
import com.datastrato.gravitino.authorization.SecurableObjects;
import com.datastrato.gravitino.meta.RoleEntity;
import java.util.stream.Collectors;
@@ -29,7 +30,8 @@ public class RoleEntitySerDe implements ProtoSerDe<RoleEntity, Role> {
roleEntity.privileges().stream()
.map(privilege -> privilege.name().toString())
.collect(Collectors.toList()))
- .setSecurableObject(roleEntity.securableObject().toString());
+ .setSecurableObjectFullName(roleEntity.securableObject().fullName())
+ .setSecurableObjectType(roleEntity.securableObject().type().name());
if (roleEntity.properties() != null && !roleEntity.properties().isEmpty()) {
builder.putAllProperties(roleEntity.properties());
@@ -55,7 +57,10 @@ public class RoleEntitySerDe implements ProtoSerDe<RoleEntity, Role> {
role.getPrivilegesList().stream()
.map(Privileges::fromString)
.collect(Collectors.toList()))
- .withSecurableObject(SecurableObjects.parse(role.getSecurableObject()))
+ .withSecurableObject(
+ SecurableObjects.parse(
+ role.getSecurableObjectFullName(),
+ SecurableObject.Type.valueOf(role.getSecurableObjectType())))
.withAuditInfo(new AuditInfoSerDe().deserialize(role.getAuditInfo(), namespace));
if (!role.getPropertiesMap().isEmpty()) {
diff --git a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
index 6b69395be5..8e4d88e452 100644
--- a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
+++ b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
@@ -222,7 +222,11 @@ public class TestAccessControlManager {
Role role =
accessControlManager.createRole(
- "metalake", "create", props, SecurableObjects.ofAllCatalogs(), Lists.newArrayList());
+ "metalake",
+ "create",
+ props,
+ SecurableObjects.ofCatalog("catalog"),
+ Lists.newArrayList());
Assertions.assertEquals("create", role.name());
testProperties(props, role.properties());
@@ -234,7 +238,7 @@ public class TestAccessControlManager {
"metalake",
"create",
props,
- SecurableObjects.ofAllCatalogs(),
+ SecurableObjects.ofCatalog("catalog"),
Lists.newArrayList()));
}
@@ -243,7 +247,7 @@ public class TestAccessControlManager {
Map<String, String> props = ImmutableMap.of("k1", "v1");
accessControlManager.createRole(
- "metalake", "loadRole", props, SecurableObjects.ofAllCatalogs(), Lists.newArrayList());
+ "metalake", "loadRole", props, SecurableObjects.ofCatalog("catalog"), Lists.newArrayList());
Role cachedRole = accessControlManager.getRole("metalake", "loadRole");
accessControlManager.getRoleManager().getCache().invalidateAll();
@@ -267,7 +271,7 @@ public class TestAccessControlManager {
Map<String, String> props = ImmutableMap.of("k1", "v1");
accessControlManager.createRole(
- "metalake", "testDrop", props, SecurableObjects.ofAllCatalogs(), Lists.newArrayList());
+ "metalake", "testDrop", props, SecurableObjects.ofCatalog("catalog"), Lists.newArrayList());
// Test drop role
boolean dropped = accessControlManager.deleteRole("metalake", "testDrop");
diff --git a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
index 4d1080649a..8fab7127f0 100644
--- a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
+++ b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
@@ -84,8 +84,8 @@ public class TestAccessControlManagerForPermissions {
.withId(1L)
.withName("role")
.withProperties(Maps.newHashMap())
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
- .withSecurableObject(SecurableObjects.of(CATALOG))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog(CATALOG))
.withAuditInfo(auditInfo)
.build();
@@ -268,7 +268,7 @@ public class TestAccessControlManagerForPermissions {
.withId(1L)
.withName(anotherRole)
.withProperties(Maps.newHashMap())
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.withSecurableObject(SecurableObjects.ofCatalog(CATALOG))
.withAuditInfo(auditInfo)
.build();
diff --git a/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java b/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java
index 7108f33ef8..109254af7f 100644
--- a/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java
+++ b/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java
@@ -266,8 +266,8 @@ public class TestEntity {
.withId(1L)
.withName(roleName)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.of(catalogName))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog(catalogName))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.withProperties(map)
.build();
@@ -277,17 +277,17 @@ public class TestEntity {
Assertions.assertEquals(auditInfo, fields.get(RoleEntity.AUDIT_INFO));
Assertions.assertEquals(map, fields.get(RoleEntity.PROPERTIES));
Assertions.assertEquals(
- Lists.newArrayList(Privileges.LoadCatalog.get()), fields.get(RoleEntity.PRIVILEGES));
+ Lists.newArrayList(Privileges.UseCatalog.get()), fields.get(RoleEntity.PRIVILEGES));
Assertions.assertEquals(
- SecurableObjects.of(catalogName), fields.get(RoleEntity.SECURABLE_OBJECT));
+ SecurableObjects.ofCatalog(catalogName), fields.get(RoleEntity.SECURABLE_OBJECT));
RoleEntity roleWithoutFields =
RoleEntity.builder()
.withId(1L)
.withName(roleName)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.of(catalogName))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog(catalogName))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.build();
Assertions.assertNull(roleWithoutFields.properties());
}
diff --git a/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java b/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java
index a314a3f1c7..3f88105e21 100644
--- a/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java
+++ b/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java
@@ -386,8 +386,8 @@ public class TestEntityProtoSerDe {
.withName(roleName)
.withNamespace(roleNamespace)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.of(catalogName))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog(catalogName))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.withProperties(props)
.build();
byte[] roleBytes = protoEntitySerDe.serialize(roleEntity);
@@ -401,8 +401,8 @@ public class TestEntityProtoSerDe {
.withName(roleName)
.withNamespace(roleNamespace)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.of(catalogName))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog(catalogName))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.build();
roleBytes = protoEntitySerDe.serialize(roleWithoutFields);
roleFromBytes = protoEntitySerDe.deserialize(roleBytes, RoleEntity.class, roleNamespace);
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java b/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java
index 42fad98d86..bd49c196b0 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java
@@ -1239,8 +1239,8 @@ public class TestEntityStorage {
.withNamespace(AuthorizationUtils.ofRoleNamespace(metalake))
.withName(name)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.of("catalog"))
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withSecurableObject(SecurableObjects.ofCatalog("catalog"))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.withProperties(Collections.emptyMap())
.build();
}
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java
index 5c6c4aa2e5..64517c3354 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java
@@ -770,8 +770,8 @@ public class TestJDBCBackend {
.withNamespace(namespace)
.withProperties(null)
.withAuditInfo(auditInfo)
- .withSecurableObject(SecurableObjects.ofAllCatalogs())
- .withPrivileges(Lists.newArrayList(Privileges.fromName(Privilege.Name.LOAD_CATALOG)))
+ .withSecurableObject(SecurableObjects.ofCatalog("catalog"))
+ .withPrivileges(Lists.newArrayList(Privileges.fromName(Privilege.Name.USE_CATALOG)))
.build();
}
diff --git a/meta/src/main/proto/gravitino_meta.proto b/meta/src/main/proto/gravitino_meta.proto
index e160c8eaf0..98162c3ba9 100644
--- a/meta/src/main/proto/gravitino_meta.proto
+++ b/meta/src/main/proto/gravitino_meta.proto
@@ -122,7 +122,8 @@ message Role {
uint64 id = 1;
string name = 2;
repeated string privileges = 3;
- string securable_object = 4;
- map<string, string> properties = 5;
- AuditInfo audit_info = 6;
+ string securable_object_full_name = 4;
+ string securable_object_type = 5;
+ map<string, string> properties = 6;
+ AuditInfo audit_info = 7;
}
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
index 14b8d33117..a5fc49e905 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
@@ -65,6 +65,7 @@ public class RoleOperations {
@ResponseMetered(name = "create-role", absolute = true)
public Response createRole(@PathParam("metalake") String metalake, RoleCreateRequest request) {
try {
+
return Utils.doAs(
httpRequest,
() ->
@@ -75,7 +76,9 @@ public class RoleOperations {
metalake,
request.getName(),
request.getProperties(),
- SecurableObjects.parse(request.getSecurableObject()),
+ SecurableObjects.parse(
+ request.getSecurableObject().fullName(),
+ request.getSecurableObject().type()),
request.getPrivileges().stream()
.map(Privileges::fromString)
.collect(Collectors.toList()))))));
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
index 59397bce66..2c6d88468c 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
@@ -24,6 +24,7 @@ import com.datastrato.gravitino.dto.responses.DeleteResponse;
import com.datastrato.gravitino.dto.responses.ErrorConstants;
import com.datastrato.gravitino.dto.responses.ErrorResponse;
import com.datastrato.gravitino.dto.responses.RoleResponse;
+import com.datastrato.gravitino.dto.util.DTOConverters;
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import com.datastrato.gravitino.exceptions.NoSuchRoleException;
import com.datastrato.gravitino.exceptions.RoleAlreadyExistsException;
@@ -100,8 +101,8 @@ public class TestRoleOperations extends JerseyTest {
new RoleCreateRequest(
"role",
Collections.emptyMap(),
- Lists.newArrayList(Privileges.LoadCatalog.get().name().toString()),
- SecurableObjects.of("catalog").toString());
+ Lists.newArrayList(Privileges.UseCatalog.get().name().toString()),
+ DTOConverters.toDTO(SecurableObjects.ofCatalog("catalog")));
Role role = buildRole("role1");
when(manager.createRole(any(), any(), any(), any(), any())).thenReturn(role);
@@ -120,8 +121,9 @@ public class TestRoleOperations extends JerseyTest {
RoleDTO roleDTO = roleResponse.getRole();
Assertions.assertEquals("role1", roleDTO.name());
- Assertions.assertEquals(SecurableObjects.of("catalog"), roleDTO.securableObject());
- Assertions.assertEquals(Lists.newArrayList(Privileges.LoadCatalog.get()), roleDTO.privileges());
+ Assertions.assertEquals(
+ SecurableObjects.ofCatalog("catalog").fullName(), roleDTO.securableObject().fullName());
+ Assertions.assertEquals(Lists.newArrayList(Privileges.UseCatalog.get()), roleDTO.privileges());
// Test to throw NoSuchMetalakeException
doThrow(new NoSuchMetalakeException("mock error"))
@@ -194,8 +196,9 @@ public class TestRoleOperations extends JerseyTest {
RoleDTO roleDTO = roleResponse.getRole();
Assertions.assertEquals("role1", roleDTO.name());
Assertions.assertTrue(role.properties().isEmpty());
- Assertions.assertEquals(SecurableObjects.of("catalog"), roleDTO.securableObject());
- Assertions.assertEquals(Lists.newArrayList(Privileges.LoadCatalog.get()), roleDTO.privileges());
+ Assertions.assertEquals(
+ SecurableObjects.ofCatalog("catalog").fullName(), roleDTO.securableObject().fullName());
+ Assertions.assertEquals(Lists.newArrayList(Privileges.UseCatalog.get()), roleDTO.privileges());
// Test to throw NoSuchMetalakeException
doThrow(new NoSuchMetalakeException("mock error")).when(manager).getRole(any(), any());
@@ -245,9 +248,9 @@ public class TestRoleOperations extends JerseyTest {
return RoleEntity.builder()
.withId(1L)
.withName(role)
- .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withPrivileges(Lists.newArrayList(Privileges.UseCatalog.get()))
.withProperties(Collections.emptyMap())
- .withSecurableObject(SecurableObjects.of("catalog"))
+ .withSecurableObject(SecurableObjects.ofCatalog("catalog"))
.withAuditInfo(
AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build())
.build();