You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/07/30 07:36:58 UTC

[GitHub] [nifi-registry] bbende commented on a change in pull request #232: NIFIREG-292 Add DB impls of UserGroupProvider and AccessPolicyProvider

bbende commented on a change in pull request #232:
URL: https://github.com/apache/nifi-registry/pull/232#discussion_r462560423



##########
File path: nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/authorization/util/AccessPolicyProviderUtils.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.nifi.registry.security.authorization.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext;
+import org.apache.nifi.registry.security.authorization.Group;
+import org.apache.nifi.registry.security.authorization.UserGroupProvider;
+import org.apache.nifi.registry.security.exception.SecurityProviderCreationException;
+import org.apache.nifi.registry.security.identity.IdentityMapper;
+import org.apache.nifi.registry.util.PropertyValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Utility methods related to access policies for use by various {@link org.apache.nifi.registry.security.authorization.AccessPolicyProvider} implementations.
+ */
+public final class AccessPolicyProviderUtils {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(AccessPolicyProviderUtils.class);
+
+    /**
+     * The prefix of a property from an AuthorizerConfigurationContext that specifies a NiFi Identity.
+     */
+    public static final String PROP_NIFI_IDENTITY_PREFIX = "NiFi Identity ";
+
+    /**
+     * The name of the property from an AuthorizerConfigurationContext that specifies the initial admin identity.
+     */
+    public static final String PROP_INITIAL_ADMIN_IDENTITY = "Initial Admin Identity";
+
+    /**
+     * A Pattern for identifying properties that represent NiFi Identities.
+     */
+    public static final Pattern NIFI_IDENTITY_PATTERN = Pattern.compile(PROP_NIFI_IDENTITY_PREFIX + "\\S+");
+
+    /**
+     * The name of the property from AuthorizerConfigurationContext that specifies a name of a group for NiFi Identities.
+     */
+    public static final String PROP_NIFI_GROUP_NAME = "NiFi Group Name";
+
+    /**
+     * Returns the value of the 'Initial Admin Identity' property with any identity mappings applied.
+     *
+     * @param configurationContext the configuration context
+     * @param identityMapper the identity mapper
+     * @return the value for the initial admin identity
+     */
+    public static String getInitialAdminIdentity(final AuthorizerConfigurationContext configurationContext, final IdentityMapper identityMapper) {
+        final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY);
+        return initialAdminIdentityProp.isSet() ? identityMapper.mapUser(initialAdminIdentityProp.getValue()) : null;

Review comment:
       The existing file-based implementations in Nifi and Nifi registry both apply the identity mappings inside the user-group-provider and access-policy-provider, so this was mostly preserving existing behavior and making it reusable across the file and DB impls.
   
   It basically means you could enter either form... entering pre-mapped would map it for you, or if you know the mapping result you could enter that and it won't match the patterns anymore. 
   
   It is somewhat questionable that each implementation has to do this separately though. Maybe there is a way we could move it to a layer above as part of a follow on effort, but I haven't thought enough about it, or we could not apply it in any of them and you always have to enter post-mapped values.




----------------------------------------------------------------
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.

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