You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by kd...@apache.org on 2018/09/22 02:11:31 UTC

[32/51] [partial] nifi-registry git commit: NIFIREG-201 Refactoring project structure to better isolate extensions

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/SearchScope.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/SearchScope.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/SearchScope.java
new file mode 100644
index 0000000..2e5e8a2
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/SearchScope.java
@@ -0,0 +1,28 @@
+/*
+ * 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.ldap.tenants;
+
+/**
+ * Scope for searching a directory server.
+ */
+public enum SearchScope {
+
+    OBJECT,
+    ONE_LEVEL,
+    SUBTREE;
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/TenantHolder.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/TenantHolder.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/TenantHolder.java
new file mode 100644
index 0000000..7ef3a8c
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/ldap/tenants/TenantHolder.java
@@ -0,0 +1,165 @@
+/*
+ * 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.ldap.tenants;
+
+
+import org.apache.nifi.registry.security.authorization.Group;
+import org.apache.nifi.registry.security.authorization.User;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A holder to provide atomic access to user group data structures.
+ */
+public class TenantHolder {
+
+    private final Set<User> allUsers;
+    private final Map<String,User> usersById;
+    private final Map<String,User> usersByIdentity;
+
+    private final Set<Group> allGroups;
+    private final Map<String,Group> groupsById;
+    private final Map<String, Set<Group>> groupsByUserIdentity;
+
+    /**
+     * Creates a new holder and populates all convenience data structures.
+     */
+    public TenantHolder(final Set<User> allUsers, final Set<Group> allGroups) {
+        // create a convenience map to retrieve a user by id
+        final Map<String, User> userByIdMap = Collections.unmodifiableMap(createUserByIdMap(allUsers));
+
+        // create a convenience map to retrieve a user by identity
+        final Map<String, User> userByIdentityMap = Collections.unmodifiableMap(createUserByIdentityMap(allUsers));
+
+        // create a convenience map to retrieve a group by id
+        final Map<String, Group> groupByIdMap = Collections.unmodifiableMap(createGroupByIdMap(allGroups));
+
+        // create a convenience map to retrieve the groups for a user identity
+        final Map<String, Set<Group>> groupsByUserIdentityMap = Collections.unmodifiableMap(createGroupsByUserIdentityMap(allGroups, allUsers));
+
+        // set all the holders
+        this.allUsers = allUsers;
+        this.allGroups = allGroups;
+        this.usersById = userByIdMap;
+        this.usersByIdentity = userByIdentityMap;
+        this.groupsById = groupByIdMap;
+        this.groupsByUserIdentity = groupsByUserIdentityMap;
+    }
+
+    /**
+     * Creates a Map from user identifier to User.
+     *
+     * @param users the set of all users
+     * @return the Map from user identifier to User
+     */
+    private Map<String,User> createUserByIdMap(final Set<User> users) {
+        Map<String,User> usersMap = new HashMap<>();
+        for (User user : users) {
+            usersMap.put(user.getIdentifier(), user);
+        }
+        return usersMap;
+    }
+
+    /**
+     * Creates a Map from user identity to User.
+     *
+     * @param users the set of all users
+     * @return the Map from user identity to User
+     */
+    private Map<String,User> createUserByIdentityMap(final Set<User> users) {
+        Map<String,User> usersMap = new HashMap<>();
+        for (User user : users) {
+            usersMap.put(user.getIdentity(), user);
+        }
+        return usersMap;
+    }
+
+    /**
+     * Creates a Map from group identifier to Group.
+     *
+     * @param groups the set of all groups
+     * @return the Map from group identifier to Group
+     */
+    private Map<String,Group> createGroupByIdMap(final Set<Group> groups) {
+        Map<String,Group> groupsMap = new HashMap<>();
+        for (Group group : groups) {
+            groupsMap.put(group.getIdentifier(), group);
+        }
+        return groupsMap;
+    }
+
+    /**
+     * Creates a Map from user identity to the set of Groups for that identity.
+     *
+     * @param groups all groups
+     * @param users all users
+     * @return a Map from User identity to the set of Groups for that identity
+     */
+    private Map<String, Set<Group>> createGroupsByUserIdentityMap(final Set<Group> groups, final Set<User> users) {
+        Map<String, Set<Group>> groupsByUserIdentity = new HashMap<>();
+
+        for (User user : users) {
+            Set<Group> userGroups = new HashSet<>();
+            for (Group group : groups) {
+                for (String groupUser : group.getUsers()) {
+                    if (groupUser.equals(user.getIdentifier())) {
+                        userGroups.add(group);
+                    }
+                }
+            }
+
+            groupsByUserIdentity.put(user.getIdentity(), userGroups);
+        }
+
+        return groupsByUserIdentity;
+    }
+
+    Set<User> getAllUsers() {
+        return allUsers;
+    }
+
+    Map<String, User> getUsersById() {
+        return usersById;
+    }
+
+    Set<Group> getAllGroups() {
+        return allGroups;
+    }
+
+    Map<String, Group> getGroupsById() {
+        return groupsById;
+    }
+
+    public User getUser(String identity) {
+        if (identity == null) {
+            throw new IllegalArgumentException("Identity cannot be null");
+        }
+        return usersByIdentity.get(identity);
+    }
+
+    public Set<Group> getGroups(String userIdentity) {
+        if (userIdentity == null) {
+            throw new IllegalArgumentException("User Identity cannot be null");
+        }
+        return groupsByUserIdentity.get(userIdentity);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/util/XmlUtils.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/util/XmlUtils.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/util/XmlUtils.java
new file mode 100644
index 0000000..2caa8fa
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/security/util/XmlUtils.java
@@ -0,0 +1,44 @@
+/*
+ * 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.util;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
+import java.io.InputStream;
+
+public class XmlUtils {
+
+    public static XMLStreamReader createSafeReader(InputStream inputStream) throws XMLStreamException {
+        if (inputStream == null) {
+            throw new IllegalArgumentException("The provided input stream cannot be null");
+        }
+        return createSafeReader(new StreamSource(inputStream));
+    }
+
+    public static XMLStreamReader createSafeReader(StreamSource source) throws XMLStreamException {
+        if (source == null) {
+            throw new IllegalArgumentException("The provided source cannot be null");
+        }
+
+        XMLInputFactory xif = XMLInputFactory.newFactory();
+        xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
+        xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
+        return xif.createXMLStreamReader(source);
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/SerializationException.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/SerializationException.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/SerializationException.java
new file mode 100644
index 0000000..dd05e77
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/SerializationException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.serialization;
+
+/**
+ * An error that can occur during serialization or deserialization.
+ */
+public class SerializationException extends RuntimeException {
+
+    public SerializationException(String message) {
+        super(message);
+    }
+
+    public SerializationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public SerializationException(Throwable cause) {
+        super(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/Serializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/Serializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/Serializer.java
new file mode 100644
index 0000000..ca424ad
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/Serializer.java
@@ -0,0 +1,43 @@
+/*
+ * 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.serialization;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Serializes and de-serializes objects.
+ */
+public interface Serializer<T> {
+
+    /**
+     * Serializes a snapshot to the given output stream.
+     *
+     * @param t the object to serialize
+     * @param out the output stream to serialize to
+     */
+    void serialize(T t, OutputStream out) throws SerializationException;
+
+    /**
+     * Deserializes the given InputStream back to an object of the given type.
+     *
+     * @param input the InputStream to deserialize
+     * @return the deserialized object
+     */
+    T deserialize(InputStream input) throws SerializationException;
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedProcessGroupSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedProcessGroupSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedProcessGroupSerializer.java
new file mode 100644
index 0000000..7322ce7
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedProcessGroupSerializer.java
@@ -0,0 +1,137 @@
+/*
+ * 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.serialization;
+
+import org.apache.nifi.registry.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.serialization.jackson.JacksonVersionedProcessGroupSerializer;
+import org.apache.nifi.registry.serialization.jaxb.JAXBVersionedProcessGroupSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * A serializer for VersionedProcessGroup that maps a "version" of the data model to a serializer.
+ * </p>
+ *
+ * <p>
+ * When serializing, the serializer associated with the {@link #CURRENT_DATA_MODEL_VERSION} is used.
+ * The version will be written as a header at the beginning of the OutputStream then followed by the content.
+ * </p>
+ *
+ * <p>
+ * When deserializing, each registered serializer will be asked to read a data model version number from the input stream
+ * in descending version order until a version number is read successfully.
+ * Then the associated serializer to the read data model version is used to deserialize content back to the target object.
+ * If no serializer can read the version, or no serializer is registered for the read version, then SerializationException is thrown.
+ * </p>
+ *
+ * <p>
+ * Current data model version is 2.
+ * Data Model Version Histories:
+ * <ul>
+ *     <li>version 2: Serialized by {@link JacksonVersionedProcessGroupSerializer}</li>
+ *     <li>version 1: Serialized by {@link JAXBVersionedProcessGroupSerializer}</li>
+ * </ul>
+ * </p>
+ */
+@Service
+public class VersionedProcessGroupSerializer implements Serializer<VersionedProcessGroup> {
+
+    private static final Logger logger = LoggerFactory.getLogger(VersionedProcessGroupSerializer.class);
+
+    static final Integer CURRENT_DATA_MODEL_VERSION = 2;
+
+    private final Map<Integer, VersionedSerializer<VersionedProcessGroup>> serializersByVersion;
+    private final VersionedSerializer<VersionedProcessGroup> defaultSerializer;
+    private final List<Integer> descendingVersions;
+    public static final int MAX_HEADER_BYTES = 1024;
+
+    public VersionedProcessGroupSerializer() {
+
+        final Map<Integer, VersionedSerializer<VersionedProcessGroup>> tempSerializers = new HashMap<>();
+        tempSerializers.put(2, new JacksonVersionedProcessGroupSerializer());
+        tempSerializers.put(1, new JAXBVersionedProcessGroupSerializer());
+
+        this.serializersByVersion = Collections.unmodifiableMap(tempSerializers);
+        this.defaultSerializer = tempSerializers.get(CURRENT_DATA_MODEL_VERSION);
+
+        final List<Integer> sortedVersions = new ArrayList<>(serializersByVersion.keySet());
+        sortedVersions.sort(Collections.reverseOrder(Integer::compareTo));
+        this.descendingVersions = sortedVersions;
+    }
+
+    @Override
+    public void serialize(final VersionedProcessGroup versionedProcessGroup, final OutputStream out) throws SerializationException {
+
+        defaultSerializer.serialize(CURRENT_DATA_MODEL_VERSION, versionedProcessGroup, out);
+    }
+
+    @Override
+    public VersionedProcessGroup deserialize(final InputStream input) throws SerializationException {
+
+        final InputStream markSupportedInput = input.markSupported() ? input : new BufferedInputStream(input);
+
+        // Mark the beginning of the stream.
+        markSupportedInput.mark(MAX_HEADER_BYTES);
+
+        // Applying each serializer
+        for (int serializerVersion : descendingVersions) {
+            final VersionedSerializer<VersionedProcessGroup> serializer = serializersByVersion.get(serializerVersion);
+
+            // Serializer version will not be the data model version always.
+            // E.g. higher version of serializer can read the old data model version number if it has the same header structure,
+            // but it does not mean the serializer is compatible with the old format.
+            final int version;
+            try {
+                version = serializer.readDataModelVersion(markSupportedInput);
+                if (!serializersByVersion.containsKey(version)) {
+                    throw new SerializationException(String.format(
+                            "Version %d was returned by %s, but no serializer is registered for that version.", version, serializer));
+                }
+            } catch (SerializationException e) {
+                logger.debug("Deserialization failed with {}", serializer, e);
+                continue;
+            } finally {
+                // Either when continue with the next serializer, or proceed deserialization with the corresponding serializer,
+                // reset the stream position.
+                try {
+                    markSupportedInput.reset();
+                } catch (IOException resetException) {
+                    // Should not happen.
+                    logger.error("Unable to reset the input stream.", resetException);
+                }
+            }
+
+            return serializersByVersion.get(version).deserialize(markSupportedInput);
+        }
+
+        throw new SerializationException("Unable to find a process group serializer compatible with the input.");
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedSerializer.java
new file mode 100644
index 0000000..b3c626f
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/VersionedSerializer.java
@@ -0,0 +1,65 @@
+/*
+ * 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.serialization;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Serializes and de-serializes objects.
+ * This interface is designed to provide backward compatibility to different versioned serialization formats.
+ * So that serialized data model and format can evolve overtime.
+ */
+public interface VersionedSerializer<T> {
+
+    /**
+     * Serialize the given object into the target output stream with the specified version format.
+     * Implementation classes are responsible to serialize the version to the head of the serialized content,
+     * so that it can be retrieved by {@link #readDataModelVersion(InputStream)} method efficiently
+     * without reading the entire byte array.
+     *
+     * @param dataModelVersion the data model version
+     * @param t the object to serialize
+     * @param out the target output stream
+     * @throws SerializationException thrown when serialization failed
+     */
+    void serialize(int dataModelVersion, T t, OutputStream out) throws SerializationException;
+
+    /**
+     * Read data model version from the given InputStream.
+     * <p>
+     * Even if an implementation serializer was able to read a version, it does not necessary mean
+     * the same serializers {@link #deserialize(InputStream)} method will be called.
+     * For example, when the header structure has not been changed, the newer version of serializer may be able to
+     * read older data model version. But deserialization should be done with the older serializer.
+     * </p>
+     * @param input the input stream to read version from
+     * @return the read data model version
+     * @throws SerializationException thrown when reading version failed
+     */
+    int readDataModelVersion(InputStream input) throws SerializationException;
+
+    /**
+     * Deserializes the given InputStream back to an object of the given type.
+     *
+     * @param input the InputStream to deserialize,
+     *              the position of input is reset to the the beginning of the stream when this method is called
+     * @return the deserialized object
+     * @throws SerializationException thrown when deserialization failed
+     */
+    T deserialize(InputStream input) throws SerializationException;
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonSerializer.java
new file mode 100644
index 0000000..4098c77
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonSerializer.java
@@ -0,0 +1,127 @@
+/*
+ * 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.serialization.jackson;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.registry.serialization.SerializationException;
+import org.apache.nifi.registry.serialization.VersionedSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.HashMap;
+
+import static org.apache.nifi.registry.serialization.VersionedProcessGroupSerializer.MAX_HEADER_BYTES;
+
+/**
+ * A Serializer that uses Jackson for serializing/deserializing.
+ */
+public abstract class JacksonSerializer<T> implements VersionedSerializer<T> {
+
+    private static final Logger logger = LoggerFactory.getLogger(JacksonSerializer.class);
+
+    private static final String JSON_HEADER = "\"header\"";
+    private static final String DATA_MODEL_VERSION = "dataModelVersion";
+
+    private final ObjectMapper objectMapper = ObjectMapperProvider.getMapper();
+
+    @Override
+    public void serialize(int dataModelVersion, T t, OutputStream out) throws SerializationException {
+        if (t == null) {
+            throw new IllegalArgumentException("The object to serialize cannot be null");
+        }
+
+        if (out == null) {
+            throw new IllegalArgumentException("OutputStream cannot be null");
+        }
+
+        final SerializationContainer<T> container = new SerializationContainer<>();
+        container.setHeader(Collections.singletonMap(DATA_MODEL_VERSION, String.valueOf(dataModelVersion)));
+        container.setContent(t);
+
+        try {
+            objectMapper.writerWithDefaultPrettyPrinter().writeValue(out, container);
+        } catch (IOException e) {
+            throw new SerializationException("Unable to serialize object", e);
+        }
+    }
+
+    @Override
+    public T deserialize(InputStream input) throws SerializationException {
+        final TypeReference<SerializationContainer<T>> typeRef = getDeserializeTypeRef();
+        try {
+            final SerializationContainer<T> container = objectMapper.readValue(input, typeRef);
+            return container.getContent();
+        } catch (IOException e) {
+            throw new SerializationException("Unable to deserialize object", e);
+        }
+    }
+
+    abstract TypeReference<SerializationContainer<T>> getDeserializeTypeRef() throws SerializationException;
+
+    @Override
+    public int readDataModelVersion(InputStream input) throws SerializationException {
+        final byte[] headerBytes = new byte[MAX_HEADER_BYTES];
+        final int readHeaderBytes;
+        try {
+            readHeaderBytes = input.read(headerBytes);
+        } catch (IOException e) {
+            throw new SerializationException("Could not read additional bytes to parse as serialization version 2 or later. "
+                    + e.getMessage(), e);
+        }
+
+        // Seek '"header"'.
+        final String headerStr = new String(headerBytes, 0, readHeaderBytes, StandardCharsets.UTF_8);
+        final int headerIndex = headerStr.indexOf(JSON_HEADER);
+        if (headerIndex < 0) {
+            throw new SerializationException(String.format("Could not find %s in the first %d bytes",
+                    JSON_HEADER, readHeaderBytes));
+        }
+
+        final int headerStart = headerStr.indexOf("{", headerIndex);
+        if (headerStart < 0) {
+            throw new SerializationException(String.format("Could not find '{' starting header object in the first %d bytes.", readHeaderBytes));
+        }
+
+        final int headerEnd = headerStr.indexOf("}", headerStart);
+        if (headerEnd < 0) {
+            throw new SerializationException(String.format("Could not find '}' ending header object in the first %d bytes.", readHeaderBytes));
+        }
+
+        final String headerObjectStr = headerStr.substring(headerStart, headerEnd + 1);
+        logger.debug("headerObjectStr={}", headerObjectStr);
+
+        try {
+            final TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {};
+            final HashMap<String, String> header = objectMapper.readValue(headerObjectStr, typeRef);
+            if (!header.containsKey(DATA_MODEL_VERSION)) {
+                throw new SerializationException("Missing " + DATA_MODEL_VERSION);
+            }
+
+            return Integer.parseInt(header.get(DATA_MODEL_VERSION));
+        } catch (IOException e) {
+            throw new SerializationException(String.format("Failed to parse header string '%s' due to %s", headerObjectStr, e), e);
+        } catch (NumberFormatException e) {
+            throw new SerializationException(String.format("Failed to parse version string due to %s", e.getMessage()), e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonVersionedProcessGroupSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonVersionedProcessGroupSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonVersionedProcessGroupSerializer.java
new file mode 100644
index 0000000..21bdecc
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/JacksonVersionedProcessGroupSerializer.java
@@ -0,0 +1,33 @@
+/*
+ * 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.serialization.jackson;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.apache.nifi.registry.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.serialization.SerializationException;
+
+/**
+ * A Jackson serializer for VersionedFlowSnapshots.
+ */
+public class JacksonVersionedProcessGroupSerializer extends JacksonSerializer<VersionedProcessGroup> {
+
+
+    @Override
+    TypeReference<SerializationContainer<VersionedProcessGroup>> getDeserializeTypeRef() throws SerializationException {
+        return new TypeReference<SerializationContainer<VersionedProcessGroup>>() {};
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/ObjectMapperProvider.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/ObjectMapperProvider.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/ObjectMapperProvider.java
new file mode 100644
index 0000000..080d258
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/ObjectMapperProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.serialization.jackson;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
+
+/**
+ * Provides a singleton ObjectMapper.
+ */
+public abstract class ObjectMapperProvider {
+
+    private static final ObjectMapper mapper = new ObjectMapper();
+
+    static {
+        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+        mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL));
+        mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory()));
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
+    }
+
+    public static ObjectMapper getMapper() {
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/SerializationContainer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/SerializationContainer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/SerializationContainer.java
new file mode 100644
index 0000000..8c4d474
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jackson/SerializationContainer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.serialization.jackson;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import java.util.Map;
+
+@XmlRootElement
+@XmlType(propOrder = {"header", "content"})
+public class SerializationContainer<T> {
+
+    private Map<String, String> header;
+    private T content;
+
+    @ApiModelProperty("The serialization headers")
+    public Map<String, String> getHeader() {
+        return header;
+    }
+
+    public void setHeader(Map<String, String> header) {
+        this.header = header;
+    }
+
+    @ApiModelProperty("The serialized content")
+    public T getContent() {
+        return content;
+    }
+
+    public void setContent(T content) {
+        this.content = content;
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
new file mode 100644
index 0000000..5290fb5
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
@@ -0,0 +1,127 @@
+/*
+ * 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.serialization.jaxb;
+
+import org.apache.nifi.registry.serialization.SerializationException;
+import org.apache.nifi.registry.serialization.VersionedSerializer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * A Serializer that uses JAXB for serializing/deserializing.
+ */
+public class JAXBSerializer<T> implements VersionedSerializer<T> {
+
+    private static final String MAGIC_HEADER = "Flows";
+    private static final byte[] MAGIC_HEADER_BYTES = MAGIC_HEADER.getBytes(StandardCharsets.UTF_8);
+
+    private final JAXBContext jaxbContext;
+
+    /**
+     * Load the JAXBContext.
+     */
+    public JAXBSerializer(final Class<T> clazz) {
+        try {
+            this.jaxbContext = JAXBContext.newInstance(clazz);
+        } catch (JAXBException e) {
+            throw new RuntimeException("Unable to create JAXBContext: " + e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public void serialize(final int dataModelVersion, final T t, final OutputStream out) throws SerializationException {
+        if (t == null) {
+            throw new IllegalArgumentException("The object to serialize cannot be null");
+        }
+
+        if (out == null) {
+            throw new IllegalArgumentException("OutputStream cannot be null");
+        }
+
+        final ByteBuffer byteBuffer = ByteBuffer.allocate(9);
+        byteBuffer.put(MAGIC_HEADER_BYTES);
+        byteBuffer.putInt(dataModelVersion);
+
+        try {
+            out.write(byteBuffer.array());
+        } catch (final IOException e) {
+            throw new SerializationException("Unable to write header while serializing process group", e);
+        }
+
+        try {
+            final Marshaller marshaller = jaxbContext.createMarshaller();
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+            marshaller.marshal(t, out);
+        } catch (JAXBException e) {
+            throw new SerializationException("Unable to serialize object", e);
+        }
+    }
+
+    @Override
+    public T deserialize(final InputStream input) throws SerializationException {
+        if (input == null) {
+            throw new IllegalArgumentException("InputStream cannot be null");
+        }
+
+        try {
+            // Consume the header bytes.
+            readDataModelVersion(input);
+            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+            return (T) unmarshaller.unmarshal(input);
+        } catch (JAXBException e) {
+            throw new SerializationException("Unable to deserialize object", e);
+        }
+    }
+
+    @Override
+    public int readDataModelVersion(InputStream input) throws SerializationException {
+        final int headerLength = 9;
+        final byte[] buffer = new byte[headerLength];
+
+        int bytesRead = -1;
+        try {
+            bytesRead = input.read(buffer, 0, headerLength);
+        } catch (final IOException e) {
+            throw new SerializationException("Unable to read header while deserializing process group", e);
+        }
+
+        if (bytesRead < headerLength) {
+            throw new SerializationException("Unable to read header while deserializing process group, expected"
+                    + headerLength + " bytes, but found " + bytesRead);
+        }
+
+        final ByteBuffer bb = ByteBuffer.wrap(buffer);
+        final byte[] magicHeaderBytes = new byte[MAGIC_HEADER_BYTES.length];
+        bb.get(magicHeaderBytes);
+        for (int i = 0; i < MAGIC_HEADER_BYTES.length; i++) {
+            if (MAGIC_HEADER_BYTES[i] != magicHeaderBytes[i]) {
+                throw new SerializationException("Unable to read header while deserializing process group." +
+                        " Header byte sequence does not match");
+            }
+        }
+
+        return bb.getInt(MAGIC_HEADER_BYTES.length);
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBVersionedProcessGroupSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBVersionedProcessGroupSerializer.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBVersionedProcessGroupSerializer.java
new file mode 100644
index 0000000..3efdd33
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBVersionedProcessGroupSerializer.java
@@ -0,0 +1,30 @@
+/*
+ * 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.serialization.jaxb;
+
+import org.apache.nifi.registry.flow.VersionedProcessGroup;
+
+/**
+ * A JAXB serializer for VersionedFlowSnapshots.
+ */
+public class JAXBVersionedProcessGroupSerializer extends JAXBSerializer<VersionedProcessGroup> {
+
+    public JAXBVersionedProcessGroupSerializer() {
+        super(VersionedProcessGroup.class);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/6f26290d/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/AuthorizationService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/AuthorizationService.java b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/AuthorizationService.java
new file mode 100644
index 0000000..204f966
--- /dev/null
+++ b/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/AuthorizationService.java
@@ -0,0 +1,811 @@
+/*
+ * 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.service;
+
+import org.apache.nifi.registry.authorization.AccessPolicy;
+import org.apache.nifi.registry.authorization.AccessPolicySummary;
+import org.apache.nifi.registry.authorization.CurrentUser;
+import org.apache.nifi.registry.authorization.Permissions;
+import org.apache.nifi.registry.authorization.Resource;
+import org.apache.nifi.registry.authorization.ResourcePermissions;
+import org.apache.nifi.registry.authorization.Tenant;
+import org.apache.nifi.registry.authorization.User;
+import org.apache.nifi.registry.authorization.UserGroup;
+import org.apache.nifi.registry.bucket.Bucket;
+import org.apache.nifi.registry.security.authorization.AccessPolicyProvider;
+import org.apache.nifi.registry.security.authorization.AccessPolicyProviderInitializationContext;
+import org.apache.nifi.registry.security.authorization.AuthorizableLookup;
+import org.apache.nifi.registry.security.authorization.Authorizer;
+import org.apache.nifi.registry.security.authorization.AuthorizerCapabilityDetection;
+import org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext;
+import org.apache.nifi.registry.security.authorization.ConfigurableAccessPolicyProvider;
+import org.apache.nifi.registry.security.authorization.ConfigurableUserGroupProvider;
+import org.apache.nifi.registry.security.authorization.Group;
+import org.apache.nifi.registry.security.authorization.ManagedAuthorizer;
+import org.apache.nifi.registry.security.authorization.RequestAction;
+import org.apache.nifi.registry.security.authorization.UserAndGroups;
+import org.apache.nifi.registry.security.authorization.UserGroupProvider;
+import org.apache.nifi.registry.security.authorization.UserGroupProviderInitializationContext;
+import org.apache.nifi.registry.security.authorization.exception.AccessDeniedException;
+import org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException;
+import org.apache.nifi.registry.security.authorization.resource.Authorizable;
+import org.apache.nifi.registry.security.authorization.resource.ResourceFactory;
+import org.apache.nifi.registry.security.authorization.resource.ResourceType;
+import org.apache.nifi.registry.security.authorization.user.NiFiUser;
+import org.apache.nifi.registry.security.authorization.user.NiFiUserUtils;
+import org.apache.nifi.registry.security.exception.SecurityProviderCreationException;
+import org.apache.nifi.registry.security.exception.SecurityProviderDestructionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.stream.Collectors;
+
+@Service
+public class AuthorizationService {
+
+    public static final String MSG_NON_MANAGED_AUTHORIZER = "This NiFi Registry is not configured to internally manage users, groups, or policies. Please contact your system administrator.";
+    public static final String MSG_NON_CONFIGURABLE_POLICIES = "This NiFi Registry is not configured to allow configurable policies. Please contact your system administrator.";
+    public static final String MSG_NON_CONFIGURABLE_USERS = "This NiFi Registry is not configured to allow configurable users and groups. Please contact your system administrator.";
+
+    private AuthorizableLookup authorizableLookup;
+    private Authorizer authorizer;
+    private RegistryService registryService;
+    private UserGroupProvider userGroupProvider;
+    private AccessPolicyProvider accessPolicyProvider;
+
+    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+    private final Lock readLock = lock.readLock();
+    private final Lock writeLock = lock.writeLock();
+
+    @Autowired
+    public AuthorizationService(
+            final AuthorizableLookup authorizableLookup,
+            final Authorizer authorizer,
+            final RegistryService registryService) {
+        this.authorizableLookup = authorizableLookup;
+        this.authorizer = authorizer;
+        this.registryService = registryService;
+
+        if (AuthorizerCapabilityDetection.isManagedAuthorizer(this.authorizer)) {
+            this.accessPolicyProvider = ((ManagedAuthorizer) authorizer).getAccessPolicyProvider();
+        } else {
+            this.accessPolicyProvider = createExceptionThrowingAccessPolicyProvider();
+        }
+        this.userGroupProvider = accessPolicyProvider.getUserGroupProvider();
+    }
+
+
+    // ---------------------- Authorization methods -------------------------------------
+
+    public AuthorizableLookup getAuthorizableLookup() {
+        return authorizableLookup;
+    }
+
+    public Authorizer getAuthorizer() {
+        return authorizer;
+    }
+
+    public void authorize(Authorizable authorizable, RequestAction action) throws AccessDeniedException {
+        authorizable.authorize(authorizer, action, NiFiUserUtils.getNiFiUser());
+    }
+
+    // ---------------------- Permissions methods ---------------------------------------
+
+    public CurrentUser getCurrentUser() {
+        final NiFiUser user = NiFiUserUtils.getNiFiUser();
+        final CurrentUser currentUser = new CurrentUser();
+        currentUser.setIdentity(user.getIdentity());
+        currentUser.setAnonymous(user.isAnonymous());
+        currentUser.setResourcePermissions(getTopLevelPermissions());
+        return currentUser;
+    }
+
+    public Permissions getPermissionsForResource(Authorizable authorizableResource) {
+        NiFiUser user = NiFiUserUtils.getNiFiUser();
+        final Permissions permissions = new Permissions();
+        permissions.setCanRead(authorizableResource.isAuthorized(authorizer, RequestAction.READ, user));
+        permissions.setCanWrite(authorizableResource.isAuthorized(authorizer, RequestAction.WRITE, user));
+        permissions.setCanDelete(authorizableResource.isAuthorized(authorizer, RequestAction.DELETE, user));
+        return permissions;
+    }
+
+    public Permissions getPermissionsForResource(Authorizable authorizableResource, Permissions knownParentAuthorizablePermissions) {
+        if (knownParentAuthorizablePermissions == null) {
+            return getPermissionsForResource(authorizableResource);
+        }
+
+        final Permissions permissions = new Permissions(knownParentAuthorizablePermissions);
+        NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+        if (!permissions.getCanRead()) {
+            permissions.setCanRead(authorizableResource.isAuthorized(authorizer, RequestAction.READ, user));
+        }
+
+        if (!permissions.getCanWrite()) {
+            permissions.setCanWrite(authorizableResource.isAuthorized(authorizer, RequestAction.WRITE, user));
+        }
+
+        if (!permissions.getCanDelete()) {
+            permissions.setCanDelete(authorizableResource.isAuthorized(authorizer, RequestAction.DELETE, user));
+        }
+
+        return permissions;
+    }
+
+    private ResourcePermissions getTopLevelPermissions() {
+
+        NiFiUser user = NiFiUserUtils.getNiFiUser();
+        ResourcePermissions resourcePermissions = new ResourcePermissions();
+
+        final Permissions bucketsPermissions = getPermissionsForResource(authorizableLookup.getBucketsAuthorizable());
+        resourcePermissions.setBuckets(bucketsPermissions);
+
+        final Permissions policiesPermissions = getPermissionsForResource(authorizableLookup.getPoliciesAuthorizable());
+        resourcePermissions.setPolicies(policiesPermissions);
+
+        final Permissions tenantsPermissions = getPermissionsForResource(authorizableLookup.getTenantsAuthorizable());
+        resourcePermissions.setTenants(tenantsPermissions);
+
+        final Permissions proxyPermissions = getPermissionsForResource(authorizableLookup.getProxyAuthorizable());
+        resourcePermissions.setProxy(proxyPermissions);
+
+        return resourcePermissions;
+    }
+
+    // ---------------------- User methods ----------------------------------------------
+
+    public User createUser(User user) {
+        verifyUserGroupProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            final org.apache.nifi.registry.security.authorization.User createdUser =
+                ((ConfigurableUserGroupProvider) userGroupProvider).addUser(userFromDTO(user));
+            return userToDTO(createdUser);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    public List<User> getUsers() {
+        this.readLock.lock();
+        try {
+            return userGroupProvider.getUsers().stream().map(this::userToDTO).collect(Collectors.toList());
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    public User getUser(String identifier) {
+        this.readLock.lock();
+        try {
+            return userToDTO(userGroupProvider.getUser(identifier));
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    public User getUserByIdentity(String identity) {
+        this.readLock.lock();
+        try {
+            return userToDTO(userGroupProvider.getUserByIdentity(identity));
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    public User updateUser(User user) {
+        verifyUserGroupProviderIsConfigurable();
+        this.writeLock.lock();
+        try {
+            final org.apache.nifi.registry.security.authorization.User updatedUser =
+                    ((ConfigurableUserGroupProvider) userGroupProvider).updateUser(userFromDTO(user));
+            if (updatedUser == null) {
+                return null;
+            }
+            return userToDTO(updatedUser);
+        } finally {
+            this.writeLock.unlock();
+        }
+    }
+
+    public User deleteUser(String identifier) {
+        verifyUserGroupProviderIsConfigurable();
+        this.writeLock.lock();
+        try {
+            User deletedUserDTO = getUser(identifier);
+            if (deletedUserDTO != null) {
+                ((ConfigurableUserGroupProvider) userGroupProvider).deleteUser(identifier);
+            }
+            return deletedUserDTO;
+        } finally {
+            this.writeLock.unlock();
+        }
+    }
+
+
+    // ---------------------- User Group methods --------------------------------------
+
+    public UserGroup createUserGroup(UserGroup userGroup) {
+        verifyUserGroupProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            final org.apache.nifi.registry.security.authorization.Group createdGroup =
+                    ((ConfigurableUserGroupProvider) userGroupProvider).addGroup(userGroupFromDTO(userGroup));
+            return userGroupToDTO(createdGroup);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    public List<UserGroup> getUserGroups() {
+        this.readLock.lock();
+        try {
+            return userGroupProvider.getGroups().stream().map(this::userGroupToDTO).collect(Collectors.toList());
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    public UserGroup getUserGroup(String identifier) {
+        this.readLock.lock();
+        try {
+            return userGroupToDTO(userGroupProvider.getGroup(identifier));
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    public UserGroup updateUserGroup(UserGroup userGroup) {
+        verifyUserGroupProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            final org.apache.nifi.registry.security.authorization.Group updatedGroup =
+                    ((ConfigurableUserGroupProvider) userGroupProvider).updateGroup(userGroupFromDTO(userGroup));
+            if (updatedGroup == null) {
+                return null;
+            }
+            return userGroupToDTO(updatedGroup);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    public UserGroup deleteUserGroup(String identifier) {
+        verifyUserGroupProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            final UserGroup userGroupDTO = getUserGroup(identifier);
+            if (userGroupDTO != null) {
+                ((ConfigurableUserGroupProvider) userGroupProvider).deleteGroup(identifier);
+            }
+            return userGroupDTO;
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+
+    // ---------------------- Access Policy methods ----------------------------------------
+
+    public AccessPolicy createAccessPolicy(AccessPolicy accessPolicy) {
+        verifyAccessPolicyProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            org.apache.nifi.registry.security.authorization.AccessPolicy createdAccessPolicy =
+                    ((ConfigurableAccessPolicyProvider) accessPolicyProvider).addAccessPolicy(accessPolicyFromDTO(accessPolicy));
+            return accessPolicyToDTO(createdAccessPolicy);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    public AccessPolicy getAccessPolicy(String identifier) {
+        readLock.lock();
+        try {
+            return accessPolicyToDTO(accessPolicyProvider.getAccessPolicy(identifier));
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public AccessPolicy getAccessPolicy(String resource, RequestAction action) {
+        readLock.lock();
+        try {
+            return accessPolicyToDTO(accessPolicyProvider.getAccessPolicy(resource, action));
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public List<AccessPolicy> getAccessPolicies() {
+        readLock.lock();
+        try {
+            return accessPolicyProvider.getAccessPolicies().stream().map(this::accessPolicyToDTO).collect(Collectors.toList());
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public List<AccessPolicySummary> getAccessPolicySummaries() {
+        readLock.lock();
+        try {
+            return accessPolicyProvider.getAccessPolicies().stream().map(this::accessPolicyToSummaryDTO).collect(Collectors.toList());
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    private List<AccessPolicySummary> getAccessPolicySummariesForUser(String userIdentifier) {
+        readLock.lock();
+        try {
+            return accessPolicyProvider.getAccessPolicies().stream()
+                    .filter(accessPolicy -> accessPolicy.getUsers().contains(userIdentifier))
+                    .map(this::accessPolicyToSummaryDTO)
+                    .collect(Collectors.toList());
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    private List<AccessPolicySummary> getAccessPolicySummariesForUserGroup(String userGroupIdentifier) {
+        readLock.lock();
+        try {
+            return accessPolicyProvider.getAccessPolicies().stream()
+                    .filter(accessPolicy -> accessPolicy.getGroups().contains(userGroupIdentifier))
+                    .map(this::accessPolicyToSummaryDTO)
+                    .collect(Collectors.toList());
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy) {
+        verifyAccessPolicyProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            // Don't allow changing action or resource of existing policy (should only be adding/removing users/groups)
+            org.apache.nifi.registry.security.authorization.AccessPolicy currentAccessPolicy =
+                    accessPolicyProvider.getAccessPolicy(accessPolicy.getIdentifier());
+            if (currentAccessPolicy == null) {
+                return null;
+            }
+            accessPolicy.setResource(currentAccessPolicy.getResource());
+            accessPolicy.setAction(currentAccessPolicy.getAction().toString());
+
+            org.apache.nifi.registry.security.authorization.AccessPolicy updatedAccessPolicy =
+                    ((ConfigurableAccessPolicyProvider) accessPolicyProvider).updateAccessPolicy(accessPolicyFromDTO(accessPolicy));
+            if (updatedAccessPolicy == null) {
+                return null;
+            }
+            return accessPolicyToDTO(updatedAccessPolicy);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    public AccessPolicy deleteAccessPolicy(String identifier) {
+        verifyAccessPolicyProviderIsConfigurable();
+        writeLock.lock();
+        try {
+            AccessPolicy deletedAccessPolicyDTO = getAccessPolicy(identifier);
+            if (deletedAccessPolicyDTO != null) {
+                ((ConfigurableAccessPolicyProvider) accessPolicyProvider).deleteAccessPolicy(identifier);
+            }
+            return deletedAccessPolicyDTO;
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+
+    // ---------------------- Resource Lookup methods --------------------------------------
+
+    public List<Resource> getResources() {
+        final List<Resource> dtoResources =
+                getAuthorizableResources()
+                        .stream()
+                        .map(AuthorizationService::resourceToDTO)
+                        .collect(Collectors.toList());
+        return dtoResources;
+    }
+
+    public List<Resource> getAuthorizedResources(RequestAction actionType) {
+        return getAuthorizedResources(actionType, null);
+    }
+
+    public List<Resource> getAuthorizedResources(RequestAction actionType, ResourceType resourceType) {
+        final List<Resource> authorizedResources =
+                getAuthorizableResources(resourceType)
+                        .stream()
+                        .filter(resource -> {
+                            String resourceId = resource.getIdentifier();
+                            try {
+                                authorizableLookup
+                                        .getAuthorizableByResource(resource.getIdentifier())
+                                        .authorize(authorizer, actionType, NiFiUserUtils.getNiFiUser());
+                                return true;
+                            } catch (AccessDeniedException e) {
+                                return false;
+                            }
+                        })
+                        .map(AuthorizationService::resourceToDTO)
+                        .collect(Collectors.toList());
+
+        return authorizedResources;
+    }
+
+    // ---------------------- Private Helper methods --------------------------------------
+
+    private void verifyUserGroupProviderIsConfigurable() {
+        if (!(userGroupProvider instanceof ConfigurableUserGroupProvider)) {
+            throw new IllegalStateException(MSG_NON_CONFIGURABLE_USERS);
+        }
+    }
+
+    private void verifyAccessPolicyProviderIsConfigurable() {
+        if (!(accessPolicyProvider instanceof ConfigurableAccessPolicyProvider)) {
+            throw new IllegalStateException(MSG_NON_CONFIGURABLE_POLICIES);
+        }
+    }
+
+    private ResourcePermissions getTopLevelPermissions(String tenantIdentifier) {
+        ResourcePermissions resourcePermissions = new ResourcePermissions();
+
+        final Permissions bucketsPermissions = getPermissionsForResource(tenantIdentifier, ResourceFactory.getBucketsResource());
+        resourcePermissions.setBuckets(bucketsPermissions);
+
+        final Permissions policiesPermissions = getPermissionsForResource(tenantIdentifier, ResourceFactory.getPoliciesResource());
+        resourcePermissions.setPolicies(policiesPermissions);
+
+        final Permissions tenantsPermissions = getPermissionsForResource(tenantIdentifier, ResourceFactory.getTenantsResource());
+        resourcePermissions.setTenants(tenantsPermissions);
+
+        final Permissions proxyPermissions = getPermissionsForResource(tenantIdentifier, ResourceFactory.getProxyResource());
+        resourcePermissions.setProxy(proxyPermissions);
+
+        return resourcePermissions;
+    }
+
+    private Permissions getPermissionsForResource(String tenantIdentifier, org.apache.nifi.registry.security.authorization.Resource resource) {
+
+        Permissions permissions = new Permissions();
+        permissions.setCanRead(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.READ));
+        permissions.setCanWrite(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.WRITE));
+        permissions.setCanDelete(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.DELETE));
+        return permissions;
+
+    }
+
+    private boolean checkTenantBelongsToPolicy(String tenantIdentifier, org.apache.nifi.registry.security.authorization.Resource resource, RequestAction action) {
+        org.apache.nifi.registry.security.authorization.AccessPolicy policy =
+                accessPolicyProvider.getAccessPolicy(resource.getIdentifier(), action);
+
+        if (policy == null) {
+            return false;
+        }
+
+        boolean tenantInPolicy = policy.getUsers().contains(tenantIdentifier) || policy.getGroups().contains(tenantIdentifier);
+        return tenantInPolicy;
+    }
+
+    private List<org.apache.nifi.registry.security.authorization.Resource> getAuthorizableResources() {
+        return getAuthorizableResources(null);
+    }
+
+    private List<org.apache.nifi.registry.security.authorization.Resource> getAuthorizableResources(ResourceType includeFilter) {
+
+        final List<org.apache.nifi.registry.security.authorization.Resource> resources = new ArrayList<>();
+
+        if (includeFilter == null || includeFilter.equals(ResourceType.Policy)) {
+            resources.add(ResourceFactory.getPoliciesResource());
+        }
+        if (includeFilter == null || includeFilter.equals(ResourceType.Tenant)) {
+            resources.add(ResourceFactory.getTenantsResource());
+        }
+        if (includeFilter == null || includeFilter.equals(ResourceType.Proxy)) {
+            resources.add(ResourceFactory.getProxyResource());
+        }
+        if (includeFilter == null || includeFilter.equals(ResourceType.Actuator)) {
+            resources.add(ResourceFactory.getActuatorResource());
+        }
+        if (includeFilter == null || includeFilter.equals(ResourceType.Swagger)) {
+            resources.add(ResourceFactory.getSwaggerResource());
+        }
+        if (includeFilter == null || includeFilter.equals(ResourceType.Bucket)) {
+            resources.add(ResourceFactory.getBucketsResource());
+            // add all buckets
+            for (final Bucket bucket : registryService.getBuckets()) {
+                resources.add(ResourceFactory.getBucketResource(bucket.getIdentifier(), bucket.getName()));
+            }
+        }
+
+        return resources;
+    }
+
+    private User userToDTO(
+            final org.apache.nifi.registry.security.authorization.User user) {
+        if (user == null) {
+            return null;
+        }
+        String userIdentifier = user.getIdentifier();
+
+        Collection<Tenant> groupsContainingUser = userGroupProvider.getGroups().stream()
+                .filter(group -> group.getUsers().contains(userIdentifier))
+                .map(this::tenantToDTO)
+                .collect(Collectors.toList());
+        Collection<AccessPolicySummary> accessPolicySummaries = getAccessPolicySummariesForUser(userIdentifier);
+
+        User userDTO = new User(user.getIdentifier(), user.getIdentity());
+        userDTO.setConfigurable(AuthorizerCapabilityDetection.isUserConfigurable(authorizer, user));
+        userDTO.setResourcePermissions(getTopLevelPermissions(userDTO.getIdentifier()));
+        userDTO.addUserGroups(groupsContainingUser);
+        userDTO.addAccessPolicies(accessPolicySummaries);
+        return userDTO;
+    }
+
+    private UserGroup userGroupToDTO(
+            final org.apache.nifi.registry.security.authorization.Group userGroup) {
+        if (userGroup == null) {
+            return null;
+        }
+
+        Collection<Tenant> userTenants = userGroup.getUsers() != null
+                ? userGroup.getUsers().stream().map(this::tenantIdToDTO).collect(Collectors.toSet()) : null;
+        Collection<AccessPolicySummary> accessPolicySummaries = getAccessPolicySummariesForUserGroup(userGroup.getIdentifier());
+
+        UserGroup userGroupDTO = new UserGroup(userGroup.getIdentifier(), userGroup.getName());
+        userGroupDTO.setConfigurable(AuthorizerCapabilityDetection.isGroupConfigurable(authorizer, userGroup));
+        userGroupDTO.setResourcePermissions(getTopLevelPermissions(userGroupDTO.getIdentifier()));
+        userGroupDTO.addUsers(userTenants);
+        userGroupDTO.addAccessPolicies(accessPolicySummaries);
+        return userGroupDTO;
+    }
+
+    private AccessPolicy accessPolicyToDTO(
+            final org.apache.nifi.registry.security.authorization.AccessPolicy accessPolicy) {
+        if (accessPolicy == null) {
+            return null;
+        }
+
+        Collection<Tenant> users = accessPolicy.getUsers() != null
+                ? accessPolicy.getUsers().stream().map(this::tenantIdToDTO).filter(Objects::nonNull).collect(Collectors.toList()) : null;
+        Collection<Tenant> userGroups = accessPolicy.getGroups() != null
+                ? accessPolicy.getGroups().stream().map(this::tenantIdToDTO).filter(Objects::nonNull).collect(Collectors.toList()) : null;
+
+        Boolean isConfigurable = AuthorizerCapabilityDetection.isAccessPolicyConfigurable(authorizer, accessPolicy);
+
+        return accessPolicyToDTO(accessPolicy, userGroups, users, isConfigurable);
+    }
+
+    private Tenant tenantIdToDTO(String identifier) {
+        this.readLock.lock();
+        try {
+            org.apache.nifi.registry.security.authorization.User user = userGroupProvider.getUser(identifier);
+            if (user != null) {
+                return tenantToDTO(user);
+            } else {
+                org.apache.nifi.registry.security.authorization.Group group = userGroupProvider.getGroup(identifier);
+                return tenantToDTO(group);
+            }
+        } finally {
+            this.readLock.unlock();
+        }
+    }
+
+    private AccessPolicySummary accessPolicyToSummaryDTO(
+            final org.apache.nifi.registry.security.authorization.AccessPolicy accessPolicy) {
+        if (accessPolicy == null) {
+            return null;
+        }
+
+        Boolean isConfigurable = AuthorizerCapabilityDetection.isAccessPolicyConfigurable(authorizer, accessPolicy);
+
+        final AccessPolicySummary accessPolicySummaryDTO = new AccessPolicySummary();
+        accessPolicySummaryDTO.setIdentifier(accessPolicy.getIdentifier());
+        accessPolicySummaryDTO.setAction(accessPolicy.getAction().toString());
+        accessPolicySummaryDTO.setResource(accessPolicy.getResource());
+        accessPolicySummaryDTO.setConfigurable(isConfigurable);
+        return accessPolicySummaryDTO;
+    }
+
+    private Tenant tenantToDTO(org.apache.nifi.registry.security.authorization.User user) {
+        if (user == null) {
+            return null;
+        }
+        Tenant tenantDTO = new Tenant(user.getIdentifier(), user.getIdentity());
+        tenantDTO.setConfigurable(AuthorizerCapabilityDetection.isUserConfigurable(authorizer, user));
+        return tenantDTO;
+    }
+
+    private Tenant tenantToDTO(org.apache.nifi.registry.security.authorization.Group group) {
+        if (group == null) {
+            return null;
+        }
+        Tenant tenantDTO = new Tenant(group.getIdentifier(), group.getName());
+        tenantDTO.setConfigurable(AuthorizerCapabilityDetection.isGroupConfigurable(authorizer, group));
+        return tenantDTO;
+    }
+
+    private static Resource resourceToDTO(org.apache.nifi.registry.security.authorization.Resource resource) {
+        if (resource == null) {
+            return null;
+        }
+        Resource resourceDto = new Resource();
+        resourceDto.setIdentifier(resource.getIdentifier());
+        resourceDto.setName(resource.getName());
+        return resourceDto;
+    }
+
+    private static org.apache.nifi.registry.security.authorization.User userFromDTO(
+            final User userDTO) {
+        if (userDTO == null) {
+            return null;
+        }
+        return new org.apache.nifi.registry.security.authorization.User.Builder()
+                .identifier(userDTO.getIdentifier() != null ? userDTO.getIdentifier() : UUID.randomUUID().toString())
+                .identity(userDTO.getIdentity())
+                .build();
+    }
+
+    private static org.apache.nifi.registry.security.authorization.Group userGroupFromDTO(
+            final UserGroup userGroupDTO) {
+        if (userGroupDTO == null) {
+            return null;
+        }
+        org.apache.nifi.registry.security.authorization.Group.Builder groupBuilder = new org.apache.nifi.registry.security.authorization.Group.Builder()
+                .identifier(userGroupDTO.getIdentifier() != null ? userGroupDTO.getIdentifier() : UUID.randomUUID().toString())
+                .name(userGroupDTO.getIdentity());
+        Set<Tenant> users = userGroupDTO.getUsers();
+        if (users != null) {
+            groupBuilder.addUsers(users.stream().map(Tenant::getIdentifier).collect(Collectors.toSet()));
+        }
+        return groupBuilder.build();
+    }
+
+    private static org.apache.nifi.registry.security.authorization.AccessPolicy accessPolicyFromDTO(
+            final AccessPolicy accessPolicyDTO) {
+        org.apache.nifi.registry.security.authorization.AccessPolicy.Builder accessPolicyBuilder =
+                new org.apache.nifi.registry.security.authorization.AccessPolicy.Builder()
+                        .identifier(accessPolicyDTO.getIdentifier() != null ? accessPolicyDTO.getIdentifier() : UUID.randomUUID().toString())
+                        .resource(accessPolicyDTO.getResource())
+                        .action(RequestAction.valueOfValue(accessPolicyDTO.getAction()));
+
+        Set<Tenant> dtoUsers = accessPolicyDTO.getUsers();
+        if (accessPolicyDTO.getUsers() != null) {
+            accessPolicyBuilder.addUsers(dtoUsers.stream().map(Tenant::getIdentifier).collect(Collectors.toSet()));
+        }
+
+        Set<Tenant> dtoUserGroups = accessPolicyDTO.getUserGroups();
+        if (dtoUserGroups != null) {
+            accessPolicyBuilder.addGroups(dtoUserGroups.stream().map(Tenant::getIdentifier).collect(Collectors.toSet()));
+        }
+
+        return accessPolicyBuilder.build();
+    }
+
+    private static AccessPolicy accessPolicyToDTO(
+            final org.apache.nifi.registry.security.authorization.AccessPolicy accessPolicy,
+            final Collection<? extends Tenant> userGroups,
+            final Collection<? extends Tenant> users,
+            final Boolean isConfigurable) {
+
+        if (accessPolicy == null) {
+            return null;
+        }
+
+        final AccessPolicy accessPolicyDTO = new AccessPolicy();
+        accessPolicyDTO.setIdentifier(accessPolicy.getIdentifier());
+        accessPolicyDTO.setAction(accessPolicy.getAction().toString());
+        accessPolicyDTO.setResource(accessPolicy.getResource());
+        accessPolicyDTO.setConfigurable(isConfigurable);
+        accessPolicyDTO.addUsers(users);
+        accessPolicyDTO.addUserGroups(userGroups);
+        return accessPolicyDTO;
+    }
+
+    private static AccessPolicyProvider createExceptionThrowingAccessPolicyProvider() {
+
+        return new AccessPolicyProvider() {
+            @Override
+            public Set<org.apache.nifi.registry.security.authorization.AccessPolicy> getAccessPolicies() throws AuthorizationAccessException {
+                throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+            }
+
+            @Override
+            public org.apache.nifi.registry.security.authorization.AccessPolicy getAccessPolicy(String identifier) throws AuthorizationAccessException {
+                throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+            }
+
+            @Override
+            public org.apache.nifi.registry.security.authorization.AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action) throws AuthorizationAccessException {
+                throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+            }
+
+            @Override
+            public UserGroupProvider getUserGroupProvider() {
+                return new UserGroupProvider() {
+                    @Override
+                    public Set<org.apache.nifi.registry.security.authorization.User> getUsers() throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public org.apache.nifi.registry.security.authorization.User getUser(String identifier) throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public org.apache.nifi.registry.security.authorization.User getUserByIdentity(String identity) throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public Set<Group> getGroups() throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public Group getGroup(String identifier) throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public UserAndGroups getUserAndGroups(String identity) throws AuthorizationAccessException {
+                        throw new IllegalStateException(MSG_NON_MANAGED_AUTHORIZER);
+                    }
+
+                    @Override
+                    public void initialize(UserGroupProviderInitializationContext initializationContext) throws SecurityProviderCreationException {
+
+                    }
+
+                    @Override
+                    public void onConfigured(AuthorizerConfigurationContext configurationContext) throws SecurityProviderCreationException {
+
+                    }
+
+                    @Override
+                    public void preDestruction() throws SecurityProviderDestructionException {
+
+                    }
+                };
+            }
+
+            @Override
+            public void initialize(AccessPolicyProviderInitializationContext initializationContext) throws SecurityProviderCreationException {
+            }
+
+            @Override
+            public void onConfigured(AuthorizerConfigurationContext configurationContext) throws SecurityProviderCreationException {
+            }
+
+            @Override
+            public void preDestruction() throws SecurityProviderDestructionException {
+            }
+        };
+
+    }
+
+}