You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2018/09/19 19:30:08 UTC
[3/4] nifi git commit: NIFI-375: Added operation policy
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java
index f14b696..099f2ae 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java
@@ -128,7 +128,8 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger<Cont
final Map<String, Integer> activeThreadCounts = new HashMap<>();
final Map<String, String> states = new HashMap<>();
- final Map<String, PermissionsDTO> canReads = new HashMap<>();
+ final Map<String, PermissionsDTO> permissionsHolder = new HashMap<>();
+ final Map<String, PermissionsDTO> operatePermissionsHolder = new HashMap<>();
for (final Map.Entry<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeEntry : referencingComponentMap.entrySet()) {
final Set<ControllerServiceReferencingComponentEntity> nodeReferencingComponents = nodeEntry.getValue();
@@ -160,15 +161,8 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger<Cont
}
// handle read permissions
- final PermissionsDTO mergedPermissions = canReads.get(nodeReferencingComponentEntity.getId());
- final PermissionsDTO permissions = nodeReferencingComponentEntity.getPermissions();
- if (permissions != null) {
- if (mergedPermissions == null) {
- canReads.put(nodeReferencingComponentEntity.getId(), permissions);
- } else {
- PermissionsDtoMerger.mergePermissions(mergedPermissions, permissions);
- }
- }
+ mergePermissions(permissionsHolder, nodeReferencingComponentEntity, nodeReferencingComponentEntity.getPermissions());
+ mergePermissions(operatePermissionsHolder, nodeReferencingComponentEntity, nodeReferencingComponentEntity.getOperatePermissions());
}
}
}
@@ -176,7 +170,8 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger<Cont
// go through each referencing components
if (referencingComponents != null) {
for (final ControllerServiceReferencingComponentEntity referencingComponent : referencingComponents) {
- final PermissionsDTO permissions = canReads.get(referencingComponent.getId());
+ final PermissionsDTO permissions = permissionsHolder.get(referencingComponent.getId());
+ final PermissionsDTO operatePermissions = operatePermissionsHolder.get(referencingComponent.getId());
if (permissions != null && permissions.getCanRead() != null && permissions.getCanRead()) {
final Integer activeThreadCount = activeThreadCounts.get(referencingComponent.getId());
if (activeThreadCount != null) {
@@ -203,12 +198,24 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger<Cont
mergeControllerServiceReferencingComponent(referencingComponent, nodeEntities);
} else {
referencingComponent.setPermissions(permissions);
+ referencingComponent.setOperatePermissions(operatePermissions);
referencingComponent.setComponent(null);
}
}
}
}
+ private static void mergePermissions(Map<String, PermissionsDTO> permissionsHolder, ControllerServiceReferencingComponentEntity nodeReferencingComponentEntity, PermissionsDTO permissions) {
+ final PermissionsDTO mergedPermissions = permissionsHolder.get(nodeReferencingComponentEntity.getId());
+ if (permissions != null) {
+ if (mergedPermissions == null) {
+ permissionsHolder.put(nodeReferencingComponentEntity.getId(), permissions);
+ } else {
+ PermissionsDtoMerger.mergePermissions(mergedPermissions, permissions);
+ }
+ }
+ }
+
private static void mergeControllerServiceReferencingComponent(ControllerServiceReferencingComponentEntity clientEntity, Map<NodeIdentifier,
ControllerServiceReferencingComponentEntity> nodeEntities) {
final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PermissionsDtoMerger.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PermissionsDtoMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PermissionsDtoMerger.java
index 688a594..2c30888 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PermissionsDtoMerger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PermissionsDtoMerger.java
@@ -27,6 +27,9 @@ public class PermissionsDtoMerger {
* @param entityPermissions an {@link PermissionsDTO} to be merged
*/
public static void mergePermissions(PermissionsDTO mergedEntityPermissions, PermissionsDTO entityPermissions) {
+ if (mergedEntityPermissions == null || entityPermissions == null) {
+ return;
+ }
if (mergedEntityPermissions.getCanRead() && !entityPermissions.getCanRead()) {
mergedEntityPermissions.setCanRead(false);
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java
index d15e4f6..b44f8d6 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/StatusMerger.java
@@ -304,6 +304,7 @@ public class StatusMerger {
target.setId(toMerge.getId());
target.setName(toMerge.getName());
target.setTargetUri(toMerge.getTargetUri());
+ target.setValidationStatus(toMerge.getValidationStatus());
}
merge(target.getAggregateSnapshot(), targetReadablePermission, toMerge.getAggregateSnapshot(), toMergeReadablePermission);
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy
index f616891..bb1d595 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy
@@ -49,42 +49,96 @@ class ControllerServiceEntityMergerSpec extends Specification {
where:
nodeEntityMap ||
expectedMergedEntity
+
// Simple ControllerServiceEntity merging
- [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceDTO()),
- (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: false, canWrite: false),
+
+ (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: false, canWrite: false),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceDTO()),
- (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: false),
component: new ControllerServiceDTO())] ||
- new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: false, canWrite: false))
+
+ new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: false, canWrite: false),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: false))
+
+
// Controller Reference merging for canRead==false
- [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))])),
- (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: false, canWrite: false),
+
+ (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: false, canWrite: false),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: false),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))])),
- (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))]))] ||
- new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
bulletins: [],
component: new ControllerServiceDTO(validationErrors: [], validationStatus: "VALID",
- referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: false, canWrite: false))]))
+ referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: false, canWrite: false),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: false))]))
+
+
// Controller Reference merging for canRead==true
- [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ [(createNodeIdentifier(1)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))])),
- (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ (createNodeIdentifier(2)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))])),
- (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
- component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ (createNodeIdentifier(3)): new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
+ component: new ControllerServiceDTO(referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 1, state: ControllerServiceState.ENABLING.name()))]))] ||
- new ControllerServiceEntity(id: '1', permissions: new PermissionsDTO(canRead: true, canWrite: true),
+
+ new ControllerServiceEntity(id: '1',
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
bulletins: [],
component: new ControllerServiceDTO(validationErrors: [], validationStatus: "VALID",
- referencingComponents: [new ControllerServiceReferencingComponentEntity(permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ referencingComponents: [new ControllerServiceReferencingComponentEntity(
+ permissions: new PermissionsDTO(canRead: true, canWrite: true),
+ operatePermissions: new PermissionsDTO(canRead: false, canWrite: true),
component: new ControllerServiceReferencingComponentDTO(activeThreadCount: 3, state: ControllerServiceState.ENABLING.name()))]))
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
index 3faa622..ac73df7 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
@@ -40,9 +40,13 @@ public class RemoteProcessGroupEntityMergerTest {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);
- final PermissionsDTO permissed = new PermissionsDTO();
- permissed.setCanRead(true);
- permissed.setCanWrite(true);
+ final PermissionsDTO permissions = new PermissionsDTO();
+ permissions.setCanRead(true);
+ permissions.setCanWrite(true);
+
+ final PermissionsDTO opsPermissions = new PermissionsDTO();
+ opsPermissions.setCanRead(false);
+ opsPermissions.setCanWrite(false);
final RemoteProcessGroupStatusDTO status = new RemoteProcessGroupStatusDTO();
status.setAggregateSnapshot(new RemoteProcessGroupStatusSnapshotDTO());
@@ -71,7 +75,8 @@ public class RemoteProcessGroupEntityMergerTest {
rpg1.setContents(contents1);
final RemoteProcessGroupEntity entity1 = new RemoteProcessGroupEntity();
- entity1.setPermissions(permissed);
+ entity1.setPermissions(permissions);
+ entity1.setOperatePermissions(opsPermissions);
entity1.setStatus(status);
entity1.setComponent(rpg1);
@@ -99,7 +104,8 @@ public class RemoteProcessGroupEntityMergerTest {
rpg2.setContents(contents2);
final RemoteProcessGroupEntity entity2 = new RemoteProcessGroupEntity();
- entity2.setPermissions(permissed);
+ entity2.setPermissions(permissions);
+ entity2.setOperatePermissions(opsPermissions);
entity2.setStatus(status);
entity2.setComponent(rpg2);
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
index a70c8ef..90c87fc 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
@@ -219,6 +219,12 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-authorizer</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-mock-authorizer</artifactId>
+ <version>1.8.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
deleted file mode 100644
index 9b50b50..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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.authorization;
-
-import org.apache.nifi.authorization.exception.AuthorizationAccessException;
-import org.apache.nifi.authorization.exception.AuthorizerCreationException;
-import org.apache.nifi.authorization.exception.AuthorizerDestructionException;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * Mock implementation of AbstractPolicyBasedAuthorizer.
- */
-public class MockPolicyBasedAuthorizer extends AbstractPolicyBasedAuthorizer {
-
- private Set<Group> groups = new HashSet<>();
- private Set<User> users = new HashSet<>();
- private Set<AccessPolicy> policies = new HashSet<>();
-
- public MockPolicyBasedAuthorizer() {
-
- }
-
- public MockPolicyBasedAuthorizer(Set<Group> groups, Set<User> users, Set<AccessPolicy> policies) {
- if (groups != null) {
- this.groups.addAll(groups);
- }
- if (users != null) {
- this.users.addAll(users);
- }
- if (policies != null) {
- this.policies.addAll(policies);
- }
- }
-
- @Override
- public Group doAddGroup(Group group) throws AuthorizationAccessException {
- groups.add(group);
- return group;
- }
-
- @Override
- public Group getGroup(String identifier) throws AuthorizationAccessException {
- return groups.stream().filter(g -> g.getIdentifier().equals(identifier)).findFirst().get();
- }
-
- @Override
- public Group doUpdateGroup(Group group) throws AuthorizationAccessException {
- deleteGroup(group);
- return addGroup(group);
- }
-
- @Override
- public Group deleteGroup(Group group) throws AuthorizationAccessException {
- groups.remove(group);
- return group;
- }
-
- @Override
- public Set<Group> getGroups() throws AuthorizationAccessException {
- return groups;
- }
-
- @Override
- public User doAddUser(User user) throws AuthorizationAccessException {
- users.add(user);
- return user;
- }
-
- @Override
- public User getUser(String identifier) throws AuthorizationAccessException {
- return users.stream().filter(u -> u.getIdentifier().equals(identifier)).findFirst().get();
- }
-
- @Override
- public User getUserByIdentity(String identity) throws AuthorizationAccessException {
- return users.stream().filter(u -> u.getIdentity().equals(identity)).findFirst().get();
- }
-
- @Override
- public User doUpdateUser(User user) throws AuthorizationAccessException {
- deleteUser(user);
- return addUser(user);
- }
-
- @Override
- public User deleteUser(User user) throws AuthorizationAccessException {
- users.remove(user);
- return user;
- }
-
- @Override
- public Set<User> getUsers() throws AuthorizationAccessException {
- return users;
- }
-
- @Override
- protected AccessPolicy doAddAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException {
- policies.add(accessPolicy);
- return accessPolicy;
- }
-
- @Override
- public AccessPolicy getAccessPolicy(String identifier) throws AuthorizationAccessException {
- return policies.stream().filter(p -> p.getIdentifier().equals(identifier)).findFirst().get();
- }
-
- @Override
- public AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException {
- deleteAccessPolicy(accessPolicy);
- return addAccessPolicy(accessPolicy);
- }
-
- @Override
- public AccessPolicy deleteAccessPolicy(AccessPolicy policy) throws AuthorizationAccessException {
- policies.remove(policy);
- return policy;
- }
-
- @Override
- public Set<AccessPolicy> getAccessPolicies() throws AuthorizationAccessException {
- return policies;
- }
-
- @Override
- public UsersAndAccessPolicies getUsersAndAccessPolicies() throws AuthorizationAccessException {
- return new UsersAndAccessPolicies() {
- @Override
- public AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action) {
- return null;
- }
-
- @Override
- public User getUser(String identity) {
- return getUserByIdentity(identity);
- }
-
- @Override
- public Set<Group> getGroups(String userIdentity) {
- User user = getUserByIdentity(userIdentity);
- if (user == null) {
- return new HashSet<>();
- } else {
- return groups.stream()
- .filter(g -> g.getUsers().contains(user.getIdentifier()))
- .collect(Collectors.toSet());
- }
- }
- };
- }
-
- @Override
- public void initialize(AuthorizerInitializationContext initializationContext) throws AuthorizerCreationException {
-
- }
-
- @Override
- public void doOnConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
-
- }
-
- @Override
- public void preDestruction() throws AuthorizerDestructionException {
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/pom.xml
new file mode 100644
index 0000000..73ab439
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>nifi-framework</artifactId>
+ <groupId>org.apache.nifi</groupId>
+ <version>1.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>nifi-mock-authorizer</artifactId>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-framework-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/src/main/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/src/main/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/src/main/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
new file mode 100644
index 0000000..b2a9662
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-mock-authorizer/src/main/java/org/apache/nifi/authorization/MockPolicyBasedAuthorizer.java
@@ -0,0 +1,196 @@
+/*
+ * 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.authorization;
+
+import org.apache.nifi.authorization.exception.AuthorizationAccessException;
+import org.apache.nifi.authorization.exception.AuthorizerCreationException;
+import org.apache.nifi.authorization.exception.AuthorizerDestructionException;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Mock implementation of AbstractPolicyBasedAuthorizer.
+ */
+public class MockPolicyBasedAuthorizer extends AbstractPolicyBasedAuthorizer implements AuthorizationAuditor {
+
+ private Set<Group> groups = new HashSet<>();
+ private Set<User> users = new HashSet<>();
+ private Set<AccessPolicy> policies = new HashSet<>();
+
+ private Set<AuthorizationRequest> audited = new HashSet();
+
+ public MockPolicyBasedAuthorizer() {
+
+ }
+
+ public MockPolicyBasedAuthorizer(Set<Group> groups, Set<User> users, Set<AccessPolicy> policies) {
+ if (groups != null) {
+ this.groups.addAll(groups);
+ }
+ if (users != null) {
+ this.users.addAll(users);
+ }
+ if (policies != null) {
+ this.policies.addAll(policies);
+ }
+ }
+
+ @Override
+ public Group doAddGroup(Group group) throws AuthorizationAccessException {
+ groups.add(group);
+ return group;
+ }
+
+ @Override
+ public Group getGroup(String identifier) throws AuthorizationAccessException {
+ return groups.stream().filter(g -> g.getIdentifier().equals(identifier)).findFirst().get();
+ }
+
+ @Override
+ public Group doUpdateGroup(Group group) throws AuthorizationAccessException {
+ deleteGroup(group);
+ return addGroup(group);
+ }
+
+ @Override
+ public Group deleteGroup(Group group) throws AuthorizationAccessException {
+ groups.remove(group);
+ return group;
+ }
+
+ @Override
+ public Set<Group> getGroups() throws AuthorizationAccessException {
+ return groups;
+ }
+
+ @Override
+ public User doAddUser(User user) throws AuthorizationAccessException {
+ users.add(user);
+ return user;
+ }
+
+ @Override
+ public User getUser(String identifier) throws AuthorizationAccessException {
+ return users.stream().filter(u -> u.getIdentifier().equals(identifier)).findFirst().get();
+ }
+
+ @Override
+ public User getUserByIdentity(String identity) throws AuthorizationAccessException {
+ return users.stream().filter(u -> u.getIdentity().equals(identity)).findFirst().get();
+ }
+
+ @Override
+ public User doUpdateUser(User user) throws AuthorizationAccessException {
+ deleteUser(user);
+ return addUser(user);
+ }
+
+ @Override
+ public User deleteUser(User user) throws AuthorizationAccessException {
+ users.remove(user);
+ return user;
+ }
+
+ @Override
+ public Set<User> getUsers() throws AuthorizationAccessException {
+ return users;
+ }
+
+ @Override
+ protected AccessPolicy doAddAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException {
+ policies.add(accessPolicy);
+ return accessPolicy;
+ }
+
+ @Override
+ public AccessPolicy getAccessPolicy(String identifier) throws AuthorizationAccessException {
+ return policies.stream().filter(p -> p.getIdentifier().equals(identifier)).findFirst().get();
+ }
+
+ @Override
+ public AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException {
+ deleteAccessPolicy(accessPolicy);
+ return addAccessPolicy(accessPolicy);
+ }
+
+ @Override
+ public AccessPolicy deleteAccessPolicy(AccessPolicy policy) throws AuthorizationAccessException {
+ policies.remove(policy);
+ return policy;
+ }
+
+ @Override
+ public Set<AccessPolicy> getAccessPolicies() throws AuthorizationAccessException {
+ return policies;
+ }
+
+ @Override
+ public UsersAndAccessPolicies getUsersAndAccessPolicies() throws AuthorizationAccessException {
+ return new UsersAndAccessPolicies() {
+ @Override
+ public AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action) {
+ return policies.stream()
+ .filter(policy -> policy.getResource().equals(resourceIdentifier) && policy.getAction().equals(action))
+ .findFirst().orElse(null);
+ }
+
+ @Override
+ public User getUser(String identity) {
+ return getUserByIdentity(identity);
+ }
+
+ @Override
+ public Set<Group> getGroups(String userIdentity) {
+ User user = getUserByIdentity(userIdentity);
+ if (user == null) {
+ return new HashSet<>();
+ } else {
+ return groups.stream()
+ .filter(g -> g.getUsers().contains(user.getIdentifier()))
+ .collect(Collectors.toSet());
+ }
+ }
+ };
+ }
+
+ @Override
+ public void auditAccessAttempt(AuthorizationRequest request, AuthorizationResult result) {
+ audited.add(request);
+ }
+
+ public boolean isAudited(AuthorizationRequest request) {
+ return audited.contains(request);
+ }
+
+ @Override
+ public void initialize(AuthorizerInitializationContext initializationContext) throws AuthorizerCreationException {
+
+ }
+
+ @Override
+ public void doOnConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
+
+ }
+
+ @Override
+ public void preDestruction() throws AuthorizerDestructionException {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java
index 88d8c46..2d79006 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java
@@ -26,6 +26,7 @@ import org.apache.nifi.authorization.resource.ProvenanceDataAuthorizable;
import org.apache.nifi.authorization.resource.ResourceFactory;
import org.apache.nifi.authorization.resource.ResourceType;
import org.apache.nifi.authorization.resource.RestrictedComponentsAuthorizableFactory;
+import org.apache.nifi.authorization.resource.OperationAuthorizable;
import org.apache.nifi.authorization.resource.TenantAuthorizable;
import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.bundle.BundleCoordinate;
@@ -468,63 +469,59 @@ class StandardAuthorizableLookup implements AuthorizableLookup {
}
@Override
- public Authorizable getAuthorizableFromResource(String resource) {
+ public Authorizable getAuthorizableFromResource(final String resource) {
// parse the resource type
- ResourceType resourceType = null;
- for (ResourceType type : ResourceType.values()) {
- if (resource.equals(type.getValue()) || resource.startsWith(type.getValue() + "/")) {
- resourceType = type;
- }
- }
-
+ final ResourceType resourceType = ResourceType.fromRawValue(resource);
if (resourceType == null) {
throw new ResourceNotFoundException("Unrecognized resource: " + resource);
}
// if this is a policy, data or a provenance event resource, there should be another resource type
- if (ResourceType.Policy.equals(resourceType) || ResourceType.Data.equals(resourceType) || ResourceType.DataTransfer.equals(resourceType) || ResourceType.ProvenanceData.equals(resourceType)) {
- final ResourceType primaryResourceType = resourceType;
- resourceType = null;
+ switch (resourceType) {
+ case Policy:
+ case Data:
+ case DataTransfer:
+ case ProvenanceData:
+ case Operation:
- // get the resource type
- resource = StringUtils.substringAfter(resource, primaryResourceType.getValue());
+ // get the resource type
+ final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
+ final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
- for (ResourceType type : ResourceType.values()) {
- if (resource.equals(type.getValue()) || resource.startsWith(type.getValue() + "/")) {
- resourceType = type;
+ if (baseResourceType == null) {
+ throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
}
- }
- if (resourceType == null) {
- throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
- }
+ switch (resourceType) {
+ case Policy:
+ return new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Data:
+ return new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case DataTransfer:
+ return new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case ProvenanceData:
+ return new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Operation:
+ return new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
+ }
- // must either be a policy, event, or data transfer
- if (ResourceType.Policy.equals(primaryResourceType)) {
- return new AccessPolicyAuthorizable(getAccessPolicy(resourceType, resource));
- } else if (ResourceType.Data.equals(primaryResourceType)) {
- return new DataAuthorizable(getAccessPolicy(resourceType, resource));
- } else if (ResourceType.ProvenanceData.equals(primaryResourceType)) {
- return new ProvenanceDataAuthorizable(getAccessPolicy(resourceType, resource));
- } else {
- return new DataTransferAuthorizable(getAccessPolicy(resourceType, resource));
- }
- } else if (ResourceType.RestrictedComponents.equals(resourceType)) {
- final String slashRequiredPermission = StringUtils.substringAfter(resource, resourceType.getValue());
+ case RestrictedComponents:
+ final String slashRequiredPermission = StringUtils.substringAfter(resource, resourceType.getValue());
- if (slashRequiredPermission.startsWith("/")) {
- final RequiredPermission requiredPermission = RequiredPermission.valueOfPermissionIdentifier(slashRequiredPermission.substring(1));
+ if (slashRequiredPermission.startsWith("/")) {
+ final RequiredPermission requiredPermission = RequiredPermission.valueOfPermissionIdentifier(slashRequiredPermission.substring(1));
+
+ if (requiredPermission == null) {
+ throw new ResourceNotFoundException("Unrecognized resource: " + resource);
+ }
- if (requiredPermission == null) {
- throw new ResourceNotFoundException("Unrecognized resource: " + resource);
+ return getRestrictedComponents(requiredPermission);
+ } else {
+ return getRestrictedComponents();
}
- return getRestrictedComponents(requiredPermission);
- } else {
- return getRestrictedComponents();
- }
- } else {
- return getAccessPolicy(resourceType, resource);
+ default:
+ return getAccessPolicy(resourceType, resource);
}
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 700185c..b8ac88a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -40,6 +40,7 @@ import org.apache.nifi.authorization.UserContextKeys;
import org.apache.nifi.authorization.resource.Authorizable;
import org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource;
import org.apache.nifi.authorization.resource.ResourceFactory;
+import org.apache.nifi.authorization.resource.OperationAuthorizable;
import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.authorization.user.NiFiUserUtils;
import org.apache.nifi.cluster.coordination.ClusterCoordinator;
@@ -668,10 +669,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processorNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(processorNode));
final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processorNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processorNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
private void awaitValidationCompletion(final ComponentNode component) {
@@ -796,10 +798,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
port -> dtoFactory.createPortDto(port));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(inputPortNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(inputPortNode));
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(inputPortNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(inputPortNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -811,10 +814,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
port -> dtoFactory.createPortDto(port));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(outputPortNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(outputPortNode), NiFiUserUtils.getNiFiUser());
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getOutputPortStatus(outputPortNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(outputPortNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -827,11 +831,13 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
remoteProcessGroup -> dtoFactory.createRemoteProcessGroupDto(remoteProcessGroup));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroupNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(remoteProcessGroupNode));
final RevisionDTO updateRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
- final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroupNode.getIdentifier()));
+ final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(remoteProcessGroupNode,
+ controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroupNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(remoteProcessGroupNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), updateRevision, permissions, status, bulletinEntities);
+ return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), updateRevision, permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -846,8 +852,9 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
remoteGroupPort -> dtoFactory.createRemoteProcessGroupPortDto(remoteGroupPort));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroupNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(remoteProcessGroupNode));
final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
- return entityFactory.createRemoteProcessGroupPortEntity(snapshot.getComponent(), updatedRevision, permissions);
+ return entityFactory.createRemoteProcessGroupPortEntity(snapshot.getComponent(), updatedRevision, permissions, operatePermissions);
}
@Override
@@ -862,8 +869,9 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
remoteGroupPort -> dtoFactory.createRemoteProcessGroupPortDto(remoteGroupPort));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroupNode);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(remoteProcessGroupNode));
final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
- return entityFactory.createRemoteProcessGroupPortEntity(snapshot.getComponent(), updatedRevision, permissions);
+ return entityFactory.createRemoteProcessGroupPortEntity(snapshot.getComponent(), updatedRevision, permissions, operatePermissions);
}
@Override
@@ -1198,6 +1206,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
public ProcessorEntity deleteProcessor(final Revision revision, final String processorId) {
final ProcessorNode processor = processorDAO.getProcessor(processorId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processor);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(processor));
final ProcessorDTO snapshot = deleteComponent(
revision,
processor.getResource(),
@@ -1205,7 +1214,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createProcessorDto(processor));
- return entityFactory.createProcessorEntity(snapshot, null, permissions, null, null);
+ return entityFactory.createProcessorEntity(snapshot, null, permissions, operatePermissions, null, null);
}
@Override
@@ -1479,6 +1488,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
public PortEntity deleteInputPort(final Revision revision, final String inputPortId) {
final Port port = inputPortDAO.getPort(inputPortId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port));
final PortDTO snapshot = deleteComponent(
revision,
port.getResource(),
@@ -1486,13 +1496,14 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createPortDto(port));
- return entityFactory.createPortEntity(snapshot, null, permissions, null, null);
+ return entityFactory.createPortEntity(snapshot, null, permissions, operatePermissions, null, null);
}
@Override
public PortEntity deleteOutputPort(final Revision revision, final String outputPortId) {
final Port port = outputPortDAO.getPort(outputPortId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port));
final PortDTO snapshot = deleteComponent(
revision,
port.getResource(),
@@ -1500,7 +1511,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createPortDto(port));
- return entityFactory.createPortEntity(snapshot, null, permissions, null, null);
+ return entityFactory.createPortEntity(snapshot, null, permissions, operatePermissions, null, null);
}
@Override
@@ -1537,6 +1548,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
public RemoteProcessGroupEntity deleteRemoteProcessGroup(final Revision revision, final String remoteProcessGroupId) {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroup);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(remoteProcessGroup));
final RemoteProcessGroupDTO snapshot = deleteComponent(
revision,
remoteProcessGroup.getResource(),
@@ -1544,7 +1556,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createRemoteProcessGroupDto(remoteProcessGroup));
- return entityFactory.createRemoteProcessGroupEntity(snapshot, null, permissions, null, null);
+ return entityFactory.createRemoteProcessGroupEntity(snapshot, null, permissions, operatePermissions, null, null);
}
@Override
@@ -1602,10 +1614,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final ProcessorNode processor = processorDAO.getProcessor(processorDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processor);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(processor));
final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processorDTO.getId()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processorDTO.getId()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -1852,10 +1865,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final Port port = inputPortDAO.getPort(inputPortDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port));
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(port.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(port.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -1868,10 +1882,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final Port port = outputPortDAO.getPort(outputPortDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port));
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getOutputPortStatus(port.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(port.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -1900,10 +1915,12 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroup);
- final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroup.getIdentifier()));
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(remoteProcessGroup));
+ final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(remoteProcessGroup, controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroup.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(remoteProcessGroup.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
+ return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()),
+ permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -2194,9 +2211,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(controllerService));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(controllerServiceDTO.getId()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
+ return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, bulletinEntities);
}
@Override
@@ -2217,9 +2235,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(controllerService));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(controllerServiceDTO.getId()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
+ return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, bulletinEntities);
}
@@ -2327,10 +2346,8 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final Set<ControllerServiceReferencingComponentEntity> componentEntities = new HashSet<>();
for (final ComponentNode refComponent : referencingComponents) {
- PermissionsDTO permissions = null;
- if (refComponent instanceof Authorizable) {
- permissions = dtoFactory.createPermissionsDto(refComponent);
- }
+ final PermissionsDTO permissions = dtoFactory.createPermissionsDto(refComponent);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(refComponent));
final Revision revision = revisions.get(refComponent.getIdentifier());
final FlowModification flowMod = new FlowModification(revision, modifier);
@@ -2358,7 +2375,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
}
- componentEntities.add(entityFactory.createControllerServiceReferencingComponentEntity(dto, revisionDto, permissions));
+ componentEntities.add(entityFactory.createControllerServiceReferencingComponentEntity(refComponent.getIdentifier(), dto, revisionDto, permissions, operatePermissions));
}
final ControllerServiceReferencingComponentsEntity entity = new ControllerServiceReferencingComponentsEntity();
@@ -2370,6 +2387,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
public ControllerServiceEntity deleteControllerService(final Revision revision, final String controllerServiceId) {
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(controllerService));
final ControllerServiceDTO snapshot = deleteComponent(
revision,
controllerService.getResource(),
@@ -2377,7 +2395,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createControllerServiceDto(controllerService));
- return entityFactory.createControllerServiceEntity(snapshot, null, permissions, null);
+ return entityFactory.createControllerServiceEntity(snapshot, null, permissions, operatePermissions, null);
}
@@ -2576,9 +2594,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(reportingTask));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
+ return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, bulletinEntities);
}
@Override
@@ -2594,15 +2613,17 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(reportingTask));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
+ return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, operatePermissions, bulletinEntities);
}
@Override
public ReportingTaskEntity deleteReportingTask(final Revision revision, final String reportingTaskId) {
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(reportingTask));
final ReportingTaskDTO snapshot = deleteComponent(
revision,
reportingTask.getResource(),
@@ -2610,7 +2631,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
true,
dtoFactory.createReportingTaskDto(reportingTask));
- return entityFactory.createReportingTaskEntity(snapshot, null, permissions, null);
+ return entityFactory.createReportingTaskEntity(snapshot, null, permissions, operatePermissions, null);
}
@Override
@@ -2850,10 +2871,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
private ProcessorEntity createProcessorEntity(final ProcessorNode processor, final NiFiUser user) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(processor.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processor, user);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(processor));
final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processor.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processor.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createProcessorEntity(dtoFactory.createProcessorDto(processor), revision, permissions, status, bulletinEntities);
+ return entityFactory.createProcessorEntity(dtoFactory.createProcessorDto(processor), revision, permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -3353,19 +3375,21 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
private PortEntity createInputPortEntity(final Port port) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(port.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port, NiFiUserUtils.getNiFiUser());
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port), NiFiUserUtils.getNiFiUser());
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(port.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(port.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(dtoFactory.createPortDto(port), revision, permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(dtoFactory.createPortDto(port), revision, permissions, operatePermissions, status, bulletinEntities);
}
private PortEntity createOutputPortEntity(final Port port) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(port.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(port, NiFiUserUtils.getNiFiUser());
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(port), NiFiUserUtils.getNiFiUser());
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getOutputPortStatus(port.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(port.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createPortEntity(dtoFactory.createPortDto(port), revision, permissions, status, bulletinEntities);
+ return entityFactory.createPortEntity(dtoFactory.createPortDto(port), revision, permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -3445,10 +3469,11 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
private RemoteProcessGroupEntity createRemoteGroupEntity(final RemoteProcessGroup rpg, final NiFiUser user) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(rpg.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(rpg, user);
- final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(rpg.getIdentifier()));
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(rpg), user);
+ final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(rpg, controllerFacade.getRemoteProcessGroupStatus(rpg.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(rpg.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createRemoteProcessGroupEntity(dtoFactory.createRemoteProcessGroupDto(rpg), revision, permissions, status, bulletinEntities);
+ return entityFactory.createRemoteProcessGroupEntity(dtoFactory.createRemoteProcessGroupDto(rpg), revision, permissions, operatePermissions, status, bulletinEntities);
}
@Override
@@ -3498,7 +3523,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
public RemoteProcessGroupStatusEntity getRemoteProcessGroupStatus(final String id) {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(id);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroup);
- final RemoteProcessGroupStatusDTO dto = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(id));
+ final RemoteProcessGroupStatusDTO dto = dtoFactory.createRemoteProcessGroupStatusDto(remoteProcessGroup, controllerFacade.getRemoteProcessGroupStatus(id));
return entityFactory.createRemoteProcessGroupStatusEntity(dto, permissions);
}
@@ -3573,9 +3598,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(serviceNode.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(serviceNode, NiFiUserUtils.getNiFiUser());
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(serviceNode), NiFiUserUtils.getNiFiUser());
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(serviceNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createControllerServiceEntity(dto, revision, permissions, bulletinEntities);
+ return entityFactory.createControllerServiceEntity(dto, revision, permissions, operatePermissions, bulletinEntities);
}
@Override
@@ -3664,9 +3690,10 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
private ReportingTaskEntity createReportingTaskEntity(final ReportingTaskNode reportingTask) {
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(reportingTask.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
+ final PermissionsDTO operatePermissions = dtoFactory.createPermissionsDto(new OperationAuthorizable(reportingTask));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
- return entityFactory.createReportingTaskEntity(dtoFactory.createReportingTaskDto(reportingTask), revision, permissions, bulletinEntities);
+ return entityFactory.createReportingTaskEntity(dtoFactory.createReportingTaskDto(reportingTask), revision, permissions, operatePermissions, bulletinEntities);
}
@Override
http://git-wip-us.apache.org/repos/asf/nifi/blob/f570cb98/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java
index 2d2f5b9..668feba 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java
@@ -28,6 +28,7 @@ import org.apache.nifi.authorization.Authorizer;
import org.apache.nifi.authorization.ComponentAuthorizable;
import org.apache.nifi.authorization.RequestAction;
import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.authorization.resource.OperationAuthorizable;
import org.apache.nifi.authorization.user.NiFiUserUtils;
import org.apache.nifi.controller.ScheduledState;
import org.apache.nifi.controller.service.ControllerServiceState;
@@ -44,6 +45,7 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
import org.apache.nifi.web.api.entity.ComponentStateEntity;
import org.apache.nifi.web.api.entity.ControllerServiceEntity;
import org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity;
+import org.apache.nifi.web.api.entity.ControllerServiceRunStatusEntity;
import org.apache.nifi.web.api.entity.PropertyDescriptorEntity;
import org.apache.nifi.web.api.entity.UpdateControllerServiceReferenceRequestEntity;
import org.apache.nifi.web.api.request.ClientIdParameter;
@@ -437,7 +439,7 @@ public class ControllerServiceResource extends ApplicationResource {
value = "Updates a controller services references",
response = ControllerServiceReferencingComponentsEntity.class,
authorizations = {
- @Authorization(value = "Write - /{component-type}/{uuid} - For each referencing component specified")
+ @Authorization(value = "Write - /{component-type}/{uuid} or /operate/{component-type}/{uuid} - For each referencing component specified")
}
)
@ApiResponses(
@@ -524,7 +526,7 @@ public class ControllerServiceResource extends ApplicationResource {
lookup -> {
requestReferencingRevisions.entrySet().stream().forEach(e -> {
final Authorizable controllerService = lookup.getControllerServiceReferencingComponent(id, e.getKey());
- controllerService.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
+ OperationAuthorizable.authorizeOperation(controllerService, authorizer, NiFiUserUtils.getNiFiUser());
});
},
() -> serviceFacade.verifyUpdateControllerServiceReferencingComponents(requestUpdateReferenceRequest.getId(), verifyScheduledState, verifyControllerServiceState),
@@ -741,6 +743,91 @@ public class ControllerServiceResource extends ApplicationResource {
);
}
+ /**
+ * Updates the operational status for the specified controller service with the specified values.
+ *
+ * @param httpServletRequest request
+ * @param id The id of the controller service to update.
+ * @param requestRunStatus A runStatusEntity.
+ * @return A controllerServiceEntity.
+ */
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{id}/run-status")
+ @ApiOperation(
+ value = "Updates run status of a controller service",
+ response = ControllerServiceEntity.class,
+ authorizations = {
+ @Authorization(value = "Write - /controller-services/{uuid} or /operation/controller-services/{uuid}")
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
+ @ApiResponse(code = 401, message = "Client could not be authenticated."),
+ @ApiResponse(code = 403, message = "Client is not authorized to make this request."),
+ @ApiResponse(code = 404, message = "The specified resource could not be found."),
+ @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.")
+ }
+ )
+ public Response updateRunStatus(
+ @Context HttpServletRequest httpServletRequest,
+ @ApiParam(
+ value = "The controller service id.",
+ required = true
+ )
+ @PathParam("id") final String id,
+ @ApiParam(
+ value = "The controller service run status.",
+ required = true
+ ) final ControllerServiceRunStatusEntity requestRunStatus) {
+
+ if (requestRunStatus == null) {
+ throw new IllegalArgumentException("Controller service run status must be specified.");
+ }
+
+ if (requestRunStatus.getRevision() == null) {
+ throw new IllegalArgumentException("Revision must be specified.");
+ }
+
+ requestRunStatus.validateState();
+
+ if (isReplicateRequest()) {
+ return replicate(HttpMethod.PUT, requestRunStatus);
+ } else if (isDisconnectedFromCluster()) {
+ verifyDisconnectedNodeModification(requestRunStatus.isDisconnectedNodeAcknowledged());
+ }
+
+ // handle expects request (usually from the cluster manager)
+ final Revision requestRevision = getRevision(requestRunStatus.getRevision(), id);
+ return withWriteLock(
+ serviceFacade,
+ requestRunStatus,
+ requestRevision,
+ lookup -> {
+ // authorize the service
+ final Authorizable authorizable = lookup.getControllerService(id).getAuthorizable();
+ OperationAuthorizable.authorizeOperation(authorizable, authorizer, NiFiUserUtils.getNiFiUser());
+ },
+ () -> serviceFacade.verifyUpdateControllerService(createDTOWithDesiredRunStatus(id, requestRunStatus.getState())),
+ (revision, runStatusEntity) -> {
+ // update the controller service
+ final ControllerServiceEntity entity = serviceFacade.updateControllerService(revision, createDTOWithDesiredRunStatus(id, runStatusEntity.getState()));
+ populateRemainingControllerServiceEntityContent(entity);
+
+ return generateOkResponse(entity).build();
+ }
+ );
+ }
+
+ private ControllerServiceDTO createDTOWithDesiredRunStatus(final String id, final String runStatus) {
+ final ControllerServiceDTO dto = new ControllerServiceDTO();
+ dto.setId(id);
+ dto.setState(runStatus);
+ return dto;
+ }
+
// setters
public void setServiceFacade(NiFiServiceFacade serviceFacade) {
this.serviceFacade = serviceFacade;