sarankk commented on code in PR #179:
URL: https://github.com/apache/cassandra-sidecar/pull/179#discussion_r1948001801


##########
server/src/main/java/org/apache/cassandra/sidecar/acl/authorization/PermissionFactoryImpl.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.acl.authorization;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+import io.vertx.ext.auth.authorization.WildcardPermissionBasedAuthorization;
+import 
io.vertx.ext.auth.authorization.impl.WildcardPermissionBasedAuthorizationImpl;
+
+import static 
org.apache.cassandra.sidecar.acl.authorization.DomainAwarePermission.WILDCARD_PART_DIVIDER_TOKEN;
+import static 
org.apache.cassandra.sidecar.acl.authorization.FeaturePermission.ALL_FEATURE_PERMISSIONS;
+
+/**
+ * Implementation of {@link PermissionFactory}
+ */
+public class PermissionFactoryImpl implements PermissionFactory
+{
+    private static final String FORBIDDEN_FEATURE_PERMISSION_PREFIX = "*:";
+    private final List<CompositePermission> supportedFeaturePermissions;
+
+    public PermissionFactoryImpl()
+    {
+        this(Collections.unmodifiableList(ALL_FEATURE_PERMISSIONS));
+    }
+
+    /**
+     * Creates a {@link PermissionFactoryImpl} given a list of supported 
feature permissions.
+     *
+     * @param supportedFeaturePermissions list of feature permissions sidecar 
recognizes and honors
+     */
+    public PermissionFactoryImpl(List<CompositePermission> 
supportedFeaturePermissions)
+    {
+        this.supportedFeaturePermissions = supportedFeaturePermissions;
+    }
+
+    /**
+     * @return list of supported feature permissions.
+     */
+    public List<CompositePermission> supportedFeaturePermissions()
+    {
+        return supportedFeaturePermissions;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Permission createPermission(String name)
+    {
+        Objects.requireNonNull(name, "name cannot be null");
+        Permission permission = createFeaturePermission(name);
+        if (permission != null)
+        {
+            return permission;
+        }
+        boolean isDomainAware = name.contains(WILDCARD_PART_DIVIDER_TOKEN);
+        return isDomainAware ? new DomainAwarePermission(name) : new 
StandardPermission(name);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CompositePermission createFeaturePermission(String name)
+    {
+        if (name.startsWith(FORBIDDEN_FEATURE_PERMISSION_PREFIX))
+        {
+            return null;

Review Comment:
   @yifan-c I returned null, because we try to create a feature permission if 
not fallback to creating a basic permission. Not throwing an exception, allows 
someone to override `DomainAwarePermission` to allow for `*:` prefix in their 
permission, without overriding `createFeaturePermission` implementation. When 
we have fallback in place, didn't want to throw prematurely.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to