qqqttt123 commented on code in PR #4010:
URL: https://github.com/apache/gravitino/pull/4010#discussion_r1664013928
##########
api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java:
##########
@@ -262,114 +229,148 @@ public static Privilege deny(Privilege.Name name) {
}
}
- /** The privilege to create a catalog. */
- public abstract static class CreateCatalog implements Privilege {
-
- private static final CreateCatalog ALLOW_INSTANCE =
- new CreateCatalog() {
- @Override
- public Condition condition() {
- return Condition.ALLOW;
- }
- };
-
- private static final CreateCatalog DENY_INSTANCE =
- new CreateCatalog() {
- @Override
- public Condition condition() {
- return Condition.DENY;
- }
- };
-
- private CreateCatalog() {}
+ /**
+ * Abstract class representing a generic privilege.
+ *
+ * @param <T> the type of the privilege
+ */
+ public abstract static class GenericPrivilege<T extends GenericPrivilege<T>>
+ implements Privilege {
- /** @return The instance with allow condition of the privilege. */
- public static CreateCatalog allow() {
- return ALLOW_INSTANCE;
+ /**
+ * Functional interface for creating instances of GenericPrivilege.
+ *
+ * @param <T> the type of the privilege
+ */
+ @FunctionalInterface
+ public interface GenericPrivilegeFactory<T extends GenericPrivilege<T>> {
+ /**
+ * Creates a new instance of the privilege.
+ *
+ * @param condition the condition of the privilege
+ * @param name the name of the privilege
+ * @return the created privilege instance
+ */
+ T create(Condition condition, Name name);
}
- /** @return The instance with deny condition of the privilege. */
- public static CreateCatalog deny() {
- return DENY_INSTANCE;
+ private final Condition condition;
+ private final Name name;
+
+ /**
+ * Constructor for GenericPrivilege.
+ *
+ * @param condition the condition of the privilege
+ * @param name the name of the privilege
+ */
+ protected GenericPrivilege(Condition condition, Name name) {
+ this.condition = condition;
+ this.name = name;
+ }
+
+ /**
+ * Creates an allowed privilege.
+ *
+ * @param <T> the type of the privilege
+ * @param name the name of the privilege
+ * @param factory the factory to create the privilege
+ * @return the created privilege instance
+ */
+ public static <T extends GenericPrivilege<T>> T allow(
Review Comment:
Is this method used for other methods?
##########
api/src/main/java/com/datastrato/gravitino/authorization/Privileges.java:
##########
@@ -262,114 +229,148 @@ public static Privilege deny(Privilege.Name name) {
}
}
- /** The privilege to create a catalog. */
- public abstract static class CreateCatalog implements Privilege {
-
- private static final CreateCatalog ALLOW_INSTANCE =
- new CreateCatalog() {
- @Override
- public Condition condition() {
- return Condition.ALLOW;
- }
- };
-
- private static final CreateCatalog DENY_INSTANCE =
- new CreateCatalog() {
- @Override
- public Condition condition() {
- return Condition.DENY;
- }
- };
-
- private CreateCatalog() {}
+ /**
+ * Abstract class representing a generic privilege.
+ *
+ * @param <T> the type of the privilege
+ */
+ public abstract static class GenericPrivilege<T extends GenericPrivilege<T>>
+ implements Privilege {
- /** @return The instance with allow condition of the privilege. */
- public static CreateCatalog allow() {
- return ALLOW_INSTANCE;
+ /**
+ * Functional interface for creating instances of GenericPrivilege.
+ *
+ * @param <T> the type of the privilege
+ */
+ @FunctionalInterface
+ public interface GenericPrivilegeFactory<T extends GenericPrivilege<T>> {
+ /**
+ * Creates a new instance of the privilege.
+ *
+ * @param condition the condition of the privilege
+ * @param name the name of the privilege
+ * @return the created privilege instance
+ */
+ T create(Condition condition, Name name);
}
- /** @return The instance with deny condition of the privilege. */
- public static CreateCatalog deny() {
- return DENY_INSTANCE;
+ private final Condition condition;
+ private final Name name;
+
+ /**
+ * Constructor for GenericPrivilege.
+ *
+ * @param condition the condition of the privilege
+ * @param name the name of the privilege
+ */
+ protected GenericPrivilege(Condition condition, Name name) {
+ this.condition = condition;
+ this.name = name;
+ }
+
+ /**
+ * Creates an allowed privilege.
+ *
+ * @param <T> the type of the privilege
+ * @param name the name of the privilege
+ * @param factory the factory to create the privilege
+ * @return the created privilege instance
+ */
+ public static <T extends GenericPrivilege<T>> T allow(
+ Name name, GenericPrivilegeFactory<T> factory) {
+ return factory.create(Condition.ALLOW, name);
+ }
+
+ /**
+ * Creates a denied privilege.
+ *
+ * @param <T> the type of the privilege
+ * @param name the name of the privilege
+ * @param factory the factory to create the privilege
+ * @return the created privilege instance
+ */
+ public static <T extends GenericPrivilege<T>> T deny(
Review Comment:
ditto.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]