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 2016/06/23 21:10:41 UTC
[02/11] nifi git commit: NIFI-1554: - Addressing access controls for
the Controller resource. - Addressing access controls for RAW site to site
clients. - Addressing access controls for downloading content (from
provenance and queue). - Addressing access
http://git-wip-us.apache.org/repos/asf/nifi/blob/f0811ca4/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/OutputPortAccessControlTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/OutputPortAccessControlTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/OutputPortAccessControlTest.java
deleted file mode 100644
index 900b11f..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/OutputPortAccessControlTest.java
+++ /dev/null
@@ -1,405 +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.integration.accesscontrol;
-
-import com.sun.jersey.api.client.ClientResponse;
-import org.apache.nifi.integration.util.NiFiTestAuthorizer;
-import org.apache.nifi.integration.util.NiFiTestUser;
-import org.apache.nifi.web.api.dto.PortDTO;
-import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.dto.flow.FlowDTO;
-import org.apache.nifi.web.api.entity.PortEntity;
-import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Access control test for output ports.
- */
-public class OutputPortAccessControlTest {
-
- private static final String FLOW_XML_PATH = "target/test-classes/access-control/flow-output-ports.xml";
-
- private static AccessControlHelper helper;
- private static int count = 0;
-
- @BeforeClass
- public static void setup() throws Exception {
- helper = new AccessControlHelper(FLOW_XML_PATH);
- }
-
- /**
- * Ensures the READ user can get an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserGetOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ WRITE user can get an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserGetOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the WRITE user can get an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserGetOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the NONE user can get an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserGetOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ user cannot put an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserPutOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- // attempt update the name
- entity.getRevision().setClientId(READ_CLIENT_ID);
- entity.getComponent().setName("Updated Name" + count++);
-
- // perform the request
- final ClientResponse response = updateOutputPort(helper.getReadUser(), entity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ_WRITE user can put an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateOutputPort(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final PortEntity responseEntity = response.getEntity(PortEntity.class);
-
- // verify
- assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the READ_WRITE user can put an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutOutputPortThroughInheritedPolicy() throws Exception {
- final PortEntity entity = createOutputPort(NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
-
- final String updatedName = "Updated name" + count++;
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateOutputPort(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final PortEntity responseEntity = response.getEntity(PortEntity.class);
-
- // verify
- assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the WRITE user can put an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserPutOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final PortDTO requestDto = new PortDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
-
- final PortEntity requestEntity = new PortEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateOutputPort(helper.getWriteUser(), requestEntity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final PortEntity responseEntity = response.getEntity(PortEntity.class);
-
- // verify
- assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- }
-
- /**
- * Ensures the NONE user cannot put an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserPutOutputPort() throws Exception {
- final PortEntity entity = getRandomOutputPort(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final PortDTO requestDto = new PortDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
-
- final PortEntity requestEntity = new PortEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateOutputPort(helper.getNoneUser(), requestEntity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ user cannot delete an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserDeleteOutputPort() throws Exception {
- verifyDelete(helper.getReadUser(), AccessControlHelper.READ_CLIENT_ID, 403);
- }
-
- /**
- * Ensures the READ WRITE user can delete an output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserDeleteOutputPort() throws Exception {
- verifyDelete(helper.getReadWriteUser(), AccessControlHelper.READ_WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the WRITE user can delete an Output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserDeleteOutputPort() throws Exception {
- verifyDelete(helper.getWriteUser(), AccessControlHelper.WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the NONE user can delete an Output port.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserDeleteOutputPort() throws Exception {
- verifyDelete(helper.getNoneUser(), NONE_CLIENT_ID, 403);
- }
-
- private PortEntity getRandomOutputPort(final NiFiTestUser user) throws Exception {
- final String url = helper.getBaseUrl() + "/flow/process-groups/root";
-
- // get the output ports
- final ClientResponse response = user.testGet(url);
-
- // ensure the response was successful
- assertEquals(200, response.getStatus());
-
- // unmarshal
- final ProcessGroupFlowEntity flowEntity = response.getEntity(ProcessGroupFlowEntity.class);
- final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
- final Set<PortEntity> outputPorts = flowDto.getOutputPorts();
-
- // ensure the correct number of output ports
- assertFalse(outputPorts.isEmpty());
-
- // use the first output port as the target
- Iterator<PortEntity> outputPortIter = outputPorts.iterator();
- assertTrue(outputPortIter.hasNext());
- return outputPortIter.next();
- }
-
- private ClientResponse updateOutputPort(final NiFiTestUser user, final PortEntity entity) throws Exception {
- final String url = helper.getBaseUrl() + "/output-ports/" + entity.getId();
-
- // perform the request
- return user.testPut(url, entity);
- }
-
- private PortEntity createOutputPort(final String name) throws Exception {
- String url = helper.getBaseUrl() + "/process-groups/root/output-ports";
-
- final String updatedName = name + count++;
-
- // create the output port
- PortDTO outputPort = new PortDTO();
- outputPort.setName(updatedName);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(READ_WRITE_CLIENT_ID);
- revision.setVersion(0L);
-
- // create the entity body
- PortEntity entity = new PortEntity();
- entity.setRevision(revision);
- entity.setComponent(outputPort);
-
- // perform the request
- ClientResponse response = helper.getReadWriteUser().testPost(url, entity);
-
- // ensure the request is successful
- assertEquals(201, response.getStatus());
-
- // get the entity body
- entity = response.getEntity(PortEntity.class);
-
- // verify creation
- outputPort = entity.getComponent();
- assertEquals(updatedName, outputPort.getName());
-
- // get the output port
- return entity;
- }
-
- private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
- final PortEntity entity = createOutputPort("Copy");
-
- // create the entity body
- final Map<String, String> queryParams = new HashMap<>();
- queryParams.put("revision", String.valueOf(entity.getRevision().getVersion()));
- queryParams.put("clientId", clientId);
-
- // perform the request
- ClientResponse response = user.testDelete(entity.getComponent().getUri(), queryParams);
-
- // ensure the request is failed with a forbidden status code
- assertEquals(responseCode, response.getStatus());
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- helper.cleanup();
- }
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f0811ca4/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessGroupAccessControlTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessGroupAccessControlTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessGroupAccessControlTest.java
deleted file mode 100644
index b3179b1..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessGroupAccessControlTest.java
+++ /dev/null
@@ -1,405 +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.integration.accesscontrol;
-
-import com.sun.jersey.api.client.ClientResponse;
-import org.apache.nifi.integration.util.NiFiTestAuthorizer;
-import org.apache.nifi.integration.util.NiFiTestUser;
-import org.apache.nifi.web.api.dto.ProcessGroupDTO;
-import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.dto.flow.FlowDTO;
-import org.apache.nifi.web.api.entity.ProcessGroupEntity;
-import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Access control test for process groups.
- */
-public class ProcessGroupAccessControlTest {
-
- private static final String FLOW_XML_PATH = "target/test-classes/access-control/flow-processors.xml";
-
- private static AccessControlHelper helper;
- private static int count = 0;
-
- @BeforeClass
- public static void setup() throws Exception {
- helper = new AccessControlHelper(FLOW_XML_PATH);
- }
-
- /**
- * Ensures the READ user can get a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserGetProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ WRITE user can get a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserGetProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the WRITE user can get a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserGetProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the NONE user can get a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserGetProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ user cannot put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserPutProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- // attempt update the name
- entity.getRevision().setClientId(READ_CLIENT_ID);
- entity.getComponent().setName("Updated Name" + count++);
-
- // perform the request
- final ClientResponse response = updateProcessGroup(helper.getReadUser(), entity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ_WRITE user can put a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateProcessGroup(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessGroupEntity responseEntity = response.getEntity(ProcessGroupEntity.class);
-
- // verify
- assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the READ_WRITE user can put a process grup.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutProcessGroupThroughInheritedPolicy() throws Exception {
- final ProcessGroupEntity entity = createProcessGroup(NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
-
- final String updatedName = "Updated name" + count++;
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateProcessGroup(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessGroupEntity responseEntity = response.getEntity(ProcessGroupEntity.class);
-
- // verify
- assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the WRITE user can put a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserPutProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final ProcessGroupDTO requestDto = new ProcessGroupDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
-
- final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateProcessGroup(helper.getWriteUser(), requestEntity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessGroupEntity responseEntity = response.getEntity(ProcessGroupEntity.class);
-
- // verify
- assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- }
-
- /**
- * Ensures the NONE user cannot put a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserPutProcessGroup() throws Exception {
- final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name" + count++;
-
- // attempt to update the name
- final ProcessGroupDTO requestDto = new ProcessGroupDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
-
- final ProcessGroupEntity requestEntity = new ProcessGroupEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateProcessGroup(helper.getNoneUser(), requestEntity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ user cannot delete a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserDeleteProcessGroup() throws Exception {
- verifyDelete(helper.getReadUser(), AccessControlHelper.READ_CLIENT_ID, 403);
- }
-
- /**
- * Ensures the READ WRITE user can delete a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserDeleteProcessGroup() throws Exception {
- verifyDelete(helper.getReadWriteUser(), AccessControlHelper.READ_WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the WRITE user can delete a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserDeleteProcessGroup() throws Exception {
- verifyDelete(helper.getWriteUser(), AccessControlHelper.WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the NONE user can delete a process group.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserDeleteProcessGroup() throws Exception {
- verifyDelete(helper.getNoneUser(), NONE_CLIENT_ID, 403);
- }
-
- private ProcessGroupEntity getRandomProcessGroup(final NiFiTestUser user) throws Exception {
- final String url = helper.getBaseUrl() + "/flow/process-groups/root";
-
- // get the process groups
- final ClientResponse response = user.testGet(url);
-
- // ensure the response was successful
- assertEquals(200, response.getStatus());
-
- // unmarshal
- final ProcessGroupFlowEntity flowEntity = response.getEntity(ProcessGroupFlowEntity.class);
- final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
- final Set<ProcessGroupEntity> processGroups = flowDto.getProcessGroups();
-
- // ensure the correct number of process groups
- assertFalse(processGroups.isEmpty());
-
- // use the first process group as the target
- Iterator<ProcessGroupEntity> processGroupIter = processGroups.iterator();
- assertTrue(processGroupIter.hasNext());
- return processGroupIter.next();
- }
-
- private ClientResponse updateProcessGroup(final NiFiTestUser user, final ProcessGroupEntity entity) throws Exception {
- final String url = helper.getBaseUrl() + "/process-groups/" + entity.getId();
-
- // perform the request
- return user.testPut(url, entity);
- }
-
- private ProcessGroupEntity createProcessGroup(final String name) throws Exception {
- String url = helper.getBaseUrl() + "/process-groups/root/process-groups";
-
- final String updatedName = name + count++;
-
- // create the process group
- ProcessGroupDTO processor = new ProcessGroupDTO();
- processor.setName(updatedName);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(READ_WRITE_CLIENT_ID);
- revision.setVersion(0L);
-
- // create the entity body
- ProcessGroupEntity entity = new ProcessGroupEntity();
- entity.setRevision(revision);
- entity.setComponent(processor);
-
- // perform the request
- ClientResponse response = helper.getReadWriteUser().testPost(url, entity);
-
- // ensure the request is successful
- assertEquals(201, response.getStatus());
-
- // get the entity body
- entity = response.getEntity(ProcessGroupEntity.class);
-
- // verify creation
- processor = entity.getComponent();
- assertEquals(updatedName, processor.getName());
-
- // get the processor
- return entity;
- }
-
- private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
- final ProcessGroupEntity entity = createProcessGroup("Copy");
-
- // create the entity body
- final Map<String, String> queryParams = new HashMap<>();
- queryParams.put("revision", String.valueOf(entity.getRevision().getVersion()));
- queryParams.put("clientId", clientId);
-
- // perform the request
- ClientResponse response = user.testDelete(entity.getComponent().getUri(), queryParams);
-
- // ensure the request is failed with a forbidden status code
- assertEquals(responseCode, response.getStatus());
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- helper.cleanup();
- }
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f0811ca4/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessorAccessControlTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessorAccessControlTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessorAccessControlTest.java
deleted file mode 100644
index 80b6b76..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ProcessorAccessControlTest.java
+++ /dev/null
@@ -1,489 +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.integration.accesscontrol;
-
-import com.sun.jersey.api.client.ClientResponse;
-import org.apache.nifi.integration.util.NiFiTestAuthorizer;
-import org.apache.nifi.integration.util.NiFiTestUser;
-import org.apache.nifi.integration.util.SourceTestProcessor;
-import org.apache.nifi.web.api.dto.ProcessorDTO;
-import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.dto.flow.FlowDTO;
-import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
-import org.apache.nifi.web.api.entity.ProcessorEntity;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
-import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Access control test for processors.
- */
-public class ProcessorAccessControlTest {
-
- private static final String FLOW_XML_PATH = "target/test-classes/access-control/flow-processors.xml";
-
- private static AccessControlHelper helper;
-
- @BeforeClass
- public static void setup() throws Exception {
- helper = new AccessControlHelper(FLOW_XML_PATH);
- }
-
- /**
- * Ensures the READ user can get a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserGetProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ WRITE user can get a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserGetProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
- }
-
- /**
- * Ensures the WRITE user can get a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserGetProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the NONE user can get a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserGetProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
- }
-
- /**
- * Ensures the READ user cannot put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserPutProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- // attempt update the name
- entity.getRevision().setClientId(READ_CLIENT_ID);
- entity.getComponent().setName("Updated Name");
-
- // perform the request
- final ClientResponse response = updateProcessor(helper.getReadUser(), entity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ_WRITE user can put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadWriteUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String updatedName = "Updated Name";
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateProcessor(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessorEntity responseEntity = response.getEntity(ProcessorEntity.class);
-
- // verify
- assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the READ_WRITE user can put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserPutProcessorThroughInheritedPolicy() throws Exception {
- final ProcessorEntity entity = createProcessor(helper, NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
-
- final String updatedName = "Updated name";
-
- // attempt to update the name
- final long version = entity.getRevision().getVersion();
- entity.getRevision().setClientId(READ_WRITE_CLIENT_ID);
- entity.getComponent().setName(updatedName);
-
- // perform the request
- final ClientResponse response = updateProcessor(helper.getReadWriteUser(), entity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessorEntity responseEntity = response.getEntity(ProcessorEntity.class);
-
- // verify
- assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- assertEquals(updatedName, responseEntity.getComponent().getName());
- }
-
- /**
- * Ensures the WRITE user can put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserPutProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getWriteUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertTrue(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name";
-
- // attempt to update the name
- final ProcessorDTO requestDto = new ProcessorDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
-
- final ProcessorEntity requestEntity = new ProcessorEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateProcessor(helper.getWriteUser(), requestEntity);
-
- // ensure successful response
- assertEquals(200, response.getStatus());
-
- // get the response
- final ProcessorEntity responseEntity = response.getEntity(ProcessorEntity.class);
-
- // verify
- assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
- assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
- }
-
- /**
- * Ensures the NONE user cannot put a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserPutProcessor() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getNoneUser());
- assertFalse(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNull(entity.getComponent());
-
- final String updatedName = "Updated Name";
-
- // attempt to update the name
- final ProcessorDTO requestDto = new ProcessorDTO();
- requestDto.setId(entity.getId());
- requestDto.setName(updatedName);
-
- final long version = entity.getRevision().getVersion();
- final RevisionDTO requestRevision = new RevisionDTO();
- requestRevision.setVersion(version);
- requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
-
- final ProcessorEntity requestEntity = new ProcessorEntity();
- requestEntity.setId(entity.getId());
- requestEntity.setRevision(requestRevision);
- requestEntity.setComponent(requestDto);
-
- // perform the request
- final ClientResponse response = updateProcessor(helper.getNoneUser(), requestEntity);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ user cannot clear state.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserClearState() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
-
- // perform the request
- final ClientResponse response = helper.getReadUser().testPost(url);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the NONE user cannot clear state.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserClearState() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
-
- // perform the request
- final ClientResponse response = helper.getNoneUser().testPost(url);
-
- // ensure forbidden response
- assertEquals(403, response.getStatus());
- }
-
- /**
- * Ensures the READ WRITE user can clear state.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserClearState() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
-
- // perform the request
- final ClientResponse response = helper.getReadWriteUser().testPost(url);
-
- // ensure ok response
- assertEquals(200, response.getStatus());
- }
-
- /**
- * Ensures the WRITE user can clear state.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserClearState() throws Exception {
- final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
- assertTrue(entity.getAccessPolicy().getCanRead());
- assertFalse(entity.getAccessPolicy().getCanWrite());
- assertNotNull(entity.getComponent());
-
- final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
-
- // perform the request
- final ClientResponse response = helper.getWriteUser().testPost(url);
-
- // ensure ok response
- assertEquals(200, response.getStatus());
- }
-
- /**
- * Ensures the READ user cannot delete a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadUserDeleteProcessor() throws Exception {
- verifyDelete(helper.getReadUser(), AccessControlHelper.READ_CLIENT_ID, 403);
- }
-
- /**
- * Ensures the READ WRITE user can delete a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testReadWriteUserDeleteProcessor() throws Exception {
- verifyDelete(helper.getReadWriteUser(), AccessControlHelper.READ_WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the WRITE user can delete a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testWriteUserDeleteProcessor() throws Exception {
- verifyDelete(helper.getWriteUser(), AccessControlHelper.WRITE_CLIENT_ID, 200);
- }
-
- /**
- * Ensures the NONE user can delete a processor.
- *
- * @throws Exception ex
- */
- @Test
- public void testNoneUserDeleteProcessor() throws Exception {
- verifyDelete(helper.getNoneUser(), NONE_CLIENT_ID, 403);
- }
-
- private ProcessorEntity getRandomProcessor(final NiFiTestUser user) throws Exception {
- final String url = helper.getBaseUrl() + "/flow/process-groups/root";
-
- // get the processors
- final ClientResponse response = user.testGet(url);
-
- // ensure the response was successful
- assertEquals(200, response.getStatus());
-
- // unmarshal
- final ProcessGroupFlowEntity flowEntity = response.getEntity(ProcessGroupFlowEntity.class);
- final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
- final Set<ProcessorEntity> processors = flowDto.getProcessors();
-
- // ensure the correct number of processors
- assertFalse(processors.isEmpty());
-
- // use the first processor as the target
- Iterator<ProcessorEntity> processorIter = processors.iterator();
- assertTrue(processorIter.hasNext());
- return processorIter.next();
- }
-
- private ClientResponse updateProcessor(final NiFiTestUser user, final ProcessorEntity entity) throws Exception {
- final String url = helper.getBaseUrl() + "/processors/" + entity.getId();
-
- // perform the request
- return user.testPut(url, entity);
- }
-
- public static ProcessorEntity createProcessor(final AccessControlHelper ach, final String name) throws Exception {
- String url = ach.getBaseUrl() + "/process-groups/root/processors";
-
- // create the processor
- ProcessorDTO processor = new ProcessorDTO();
- processor.setName(name);
- processor.setType(SourceTestProcessor.class.getName());
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(READ_WRITE_CLIENT_ID);
- revision.setVersion(0L);
-
- // create the entity body
- ProcessorEntity entity = new ProcessorEntity();
- entity.setRevision(revision);
- entity.setComponent(processor);
-
- // perform the request
- ClientResponse response = ach.getReadWriteUser().testPost(url, entity);
-
- // ensure the request is successful
- assertEquals(201, response.getStatus());
-
- // get the entity body
- entity = response.getEntity(ProcessorEntity.class);
-
- // verify creation
- processor = entity.getComponent();
- assertEquals(name, processor.getName());
- assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
-
- // get the processor
- return entity;
- }
-
- private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
- final ProcessorEntity entity = createProcessor(helper, "Copy");
-
- // create the entity body
- final Map<String, String> queryParams = new HashMap<>();
- queryParams.put("revision", String.valueOf(entity.getRevision().getVersion()));
- queryParams.put("clientId", clientId);
-
- // perform the request
- ClientResponse response = user.testDelete(entity.getComponent().getUri(), queryParams);
-
- // ensure the request is failed with a forbidden status code
- assertEquals(responseCode, response.getStatus());
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- helper.cleanup();
- }
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/f0811ca4/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ReadOnlyAccessControlTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ReadOnlyAccessControlTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ReadOnlyAccessControlTest.java
deleted file mode 100644
index d7e6a7a..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/ReadOnlyAccessControlTest.java
+++ /dev/null
@@ -1,983 +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.integration.accesscontrol;
-
-import com.sun.jersey.api.client.ClientResponse;
-import org.apache.nifi.integration.NiFiWebApiTest;
-import org.apache.nifi.integration.util.NiFiTestServer;
-import org.apache.nifi.integration.util.NiFiTestUser;
-import org.apache.nifi.nar.ExtensionManager;
-import org.apache.nifi.nar.NarClassLoaders;
-import org.apache.nifi.util.NiFiProperties;
-import org.apache.nifi.web.api.dto.FlowSnippetDTO;
-import org.apache.nifi.web.api.dto.ProcessGroupDTO;
-import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.entity.AuthorityEntity;
-import org.apache.nifi.web.api.entity.BannerEntity;
-import org.apache.nifi.web.api.entity.ConnectionEntity;
-import org.apache.nifi.web.api.entity.ConnectionsEntity;
-import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
-import org.apache.nifi.web.api.entity.InputPortsEntity;
-import org.apache.nifi.web.api.entity.LabelEntity;
-import org.apache.nifi.web.api.entity.LabelsEntity;
-import org.apache.nifi.web.api.entity.OutputPortsEntity;
-import org.apache.nifi.web.api.entity.PortEntity;
-import org.apache.nifi.web.api.entity.PrioritizerTypesEntity;
-import org.apache.nifi.web.api.entity.ProcessGroupEntity;
-import org.apache.nifi.web.api.entity.ProcessGroupsEntity;
-import org.apache.nifi.web.api.entity.ProcessorEntity;
-import org.apache.nifi.web.api.entity.ProcessorTypesEntity;
-import org.apache.nifi.web.api.entity.ProcessorsEntity;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Access control test for a read only user.
- */
-@Ignore
-public class ReadOnlyAccessControlTest {
-
- public static final String READ_ONLY_USER_DN = "CN=Lastname Firstname Middlename monitor, OU=Unknown, OU=Unknown, OU=Unknown, O=Unknown, C=Unknown";
-
- private static final String CLIENT_ID = "readonly-client-id";
- private static final String CONTEXT_PATH = "/nifi-api";
- private static final String FLOW_XML_PATH = "target/test-classes/access-control/flow-monitor.xml";
-
- private static NiFiTestServer SERVER;
- private static NiFiTestUser READ_ONLY_USER;
- private static String BASE_URL;
-
- @BeforeClass
- public static void setup() throws Exception {
- // configure the location of the nifi properties
- File nifiPropertiesFile = new File("src/test/resources/access-control/nifi.properties");
- System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, nifiPropertiesFile.getAbsolutePath());
-
- // update the flow.xml property
- NiFiProperties props = NiFiProperties.getInstance();
- props.setProperty("nifi.flow.configuration.file", FLOW_XML_PATH);
-
- // load extensions
- NarClassLoaders.load(props);
- ExtensionManager.discoverExtensions();
-
- // start the server
- SERVER = new NiFiTestServer("src/main/webapp", CONTEXT_PATH);
- SERVER.startServer();
- SERVER.loadFlow();
-
- // get the base url
- BASE_URL = SERVER.getBaseUrl() + CONTEXT_PATH;
-
- // create the user
- READ_ONLY_USER = new NiFiTestUser(SERVER.getClient(), READ_ONLY_USER_DN);
-
- // populate the flow
- NiFiWebApiTest.populateFlow(SERVER.getClient(), BASE_URL, CLIENT_ID);
- }
-
- // ----------------------------------------------
- // PROCESS GROUPS
- // ----------------------------------------------
- /**
- * Ensures the admin user can get a groups content.
- *
- * @throws Exception ex
- */
- @Test
- public void testGroupGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root";
-
- // build the query params
- Map<String, String> queryParams = new HashMap<>();
- queryParams.put("verbose", Boolean.TRUE.toString());
-
- ClientResponse response = READ_ONLY_USER.testGet(url, queryParams);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // extract the process group
- ProcessGroupEntity processGroupEntity = response.getEntity(ProcessGroupEntity.class);
-
- // ensure there is content
- Assert.assertNotNull(processGroupEntity);
-
- // extract the process group dto
- ProcessGroupDTO processGroupDTO = processGroupEntity.getComponent();
- FlowSnippetDTO processGroupContentsDTO = processGroupDTO.getContents();
-
- // verify graph
- Assert.assertEquals(2, processGroupContentsDTO.getProcessors().size());
- Assert.assertEquals(1, processGroupContentsDTO.getConnections().size());
- Assert.assertEquals(1, processGroupContentsDTO.getProcessGroups().size());
- Assert.assertEquals(1, processGroupContentsDTO.getInputPorts().size());
- Assert.assertEquals(1, processGroupContentsDTO.getOutputPorts().size());
- Assert.assertEquals(1, processGroupContentsDTO.getLabels().size());
- }
-
- /**
- * Verifies the admin user cannot update a group.
- *
- * @throws Exception ex
- */
- @Test
- public void testGroupPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root";
-
- // create the entity body
- Map<String, String> formData = new HashMap<>();
- formData.put("revision", String.valueOf(NiFiTestUser.REVISION));
- formData.put("clientId", CLIENT_ID);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, formData);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // CONTROLLER
- // ----------------------------------------------
- /**
- * Verifies the read only user can retrieve the controller configuration.
- *
- * @throws Exception ex
- */
- @Test
- public void testControllerConfigurationGet() throws Exception {
- String url = BASE_URL + "/controller/config";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // verify the results
- ControllerConfigurationEntity entity = response.getEntity(ControllerConfigurationEntity.class);
- Assert.assertNotNull(entity);
- Assert.assertNotNull(entity.getConfig());
- Assert.assertEquals(10, entity.getConfig().getMaxTimerDrivenThreadCount().intValue());
- Assert.assertEquals(5, entity.getConfig().getMaxEventDrivenThreadCount().intValue());
- Assert.assertEquals(30, entity.getConfig().getAutoRefreshIntervalSeconds().intValue());
- }
-
- /**
- * Verifies the read only user cannot update the controller configuration.
- *
- * @throws Exception ex
- */
- @Test
- public void testControllerConfigurationPut() throws Exception {
- String url = BASE_URL + "/controller/config";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ControllerConfigurationEntity entity = new ControllerConfigurationEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies the read only user cannot create a new flow archive.
- *
- * @throws Exception ex
- */
- @Test
- public void testFlowConfigurationArchivePost() throws Exception {
- String url = BASE_URL + "/controller/archive";
-
- // create the entity body
- Map<String, String> formData = new HashMap<>();
- formData.put("revision", String.valueOf(NiFiTestUser.REVISION));
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, formData);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies the read only user can retrieve his credentials.
- *
- * @throws Exception ex
- */
- @Test
- public void testAuthoritiesGet() throws Exception {
- String url = BASE_URL + "/controller/authorities";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // verify the result
- AuthorityEntity entity = response.getEntity(AuthorityEntity.class);
- Assert.assertNotNull(entity);
- Assert.assertNotNull(entity.getAuthorities());
- Assert.assertEquals(1, entity.getAuthorities().size());
- Assert.assertEquals("ROLE_MONITOR", entity.getAuthorities().toArray()[0]);
- }
-
- /**
- * Verifies the read only user can retrieve the banners.
- *
- * @throws Exception ex
- */
- @Test
- public void testBannersGet() throws Exception {
- String url = BASE_URL + "/controller/banners";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // verify the result
- BannerEntity entity = response.getEntity(BannerEntity.class);
- Assert.assertNotNull(entity);
- Assert.assertNotNull(entity.getBanners());
- Assert.assertEquals("TEST BANNER", entity.getBanners().getHeaderText());
- Assert.assertEquals("TEST BANNER", entity.getBanners().getFooterText());
- }
-
- /**
- * Verifies the read only user can retrieve the processor types.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorTypesGet() throws Exception {
- String url = BASE_URL + "/controller/processor-types";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // verify the result
- ProcessorTypesEntity entity = response.getEntity(ProcessorTypesEntity.class);
- Assert.assertNotNull(entity);
- Assert.assertNotNull(entity.getProcessorTypes());
- Assert.assertFalse(entity.getProcessorTypes().isEmpty());
- }
-
- /**
- * Verifies the read only user can retrieve the prioritizer types.
- *
- * @throws Exception ex
- */
- @Test
- public void testPrioritizerTypesGet() throws Exception {
- String url = BASE_URL + "/controller/prioritizers";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is successful
- Assert.assertEquals(200, response.getStatus());
-
- // verify the result
- PrioritizerTypesEntity entity = response.getEntity(PrioritizerTypesEntity.class);
- Assert.assertNotNull(entity);
- Assert.assertNotNull(entity.getPrioritizerTypes());
- Assert.assertFalse(entity.getPrioritizerTypes().isEmpty());
- }
-
- // ----------------------------------------------
- // PROCESS GROUP
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get process groups.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorGroupsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/process-group-references";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- ProcessGroupsEntity entity = response.getEntity(ProcessGroupsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getProcessGroups());
- Assert.assertEquals(1, entity.getProcessGroups().size());
- }
-
- /**
- * Verifies that the operator user cannot create new process groups.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessGroupPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/process-group-references";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ProcessGroupEntity entity = new ProcessGroupEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the operator user cannot update process group configuration.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessGroupPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/process-group-references/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ProcessGroupEntity entity = new ProcessGroupEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the operator user cannot delete process groups.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessGroupDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/process-group-references/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // PROCESSOR
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get processors.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/processors";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- ProcessorsEntity entity = response.getEntity(ProcessorsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getProcessors());
- Assert.assertEquals(2, entity.getProcessors().size());
- }
-
- /**
- * Verifies that the read only user cannot create new processors.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/processors";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ProcessorEntity entity = new ProcessorEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot create new processors.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/processors/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ProcessorEntity entity = new ProcessorEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot delete processors.
- *
- * @throws Exception ex
- */
- @Test
- public void testProcessorDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/processors/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // CONNECTION
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get connections.
- *
- * @throws Exception ex
- */
- @Test
- public void testConnectionsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/connections";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- ConnectionsEntity entity = response.getEntity(ConnectionsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getConnections());
- Assert.assertEquals(1, entity.getConnections().size());
- }
-
- /**
- * Verifies that the read only user cannot create connections.
- *
- * @throws Exception ex
- */
- @Test
- public void testConnectionPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/connections";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ConnectionEntity entity = new ConnectionEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot create connections.
- *
- * @throws Exception ex
- */
- @Test
- public void testConnectionPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/connections/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- ConnectionEntity entity = new ConnectionEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot delete connections.
- *
- * @throws Exception ex
- */
- @Test
- public void testConnectionDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/connections/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // INPUT PORTS
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testInputPortsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/input-ports";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- InputPortsEntity entity = response.getEntity(InputPortsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getInputPorts());
- Assert.assertEquals(1, entity.getInputPorts().size());
- }
-
- /**
- * Verifies that the admin user cannot create input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testInputPortPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/input-ports";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- PortEntity entity = new PortEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the admin user cannot create input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testInputPortPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/input-ports/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- PortEntity entity = new PortEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the admin user cannot delete input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testInputPortDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/input-ports/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // OUTPUT PORTS
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get output ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testOutputPortsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/output-ports";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- OutputPortsEntity entity = response.getEntity(OutputPortsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getOutputPorts());
- Assert.assertEquals(1, entity.getOutputPorts().size());
- }
-
- /**
- * Verifies that the admin user cannot create output ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testOutputPortPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/output-ports";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- PortEntity entity = new PortEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the admin user cannot create input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testOutputPortPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/output-ports/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(CLIENT_ID);
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- PortEntity entity = new PortEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the admin user cannot delete output ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testOutputPortDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/output-ports/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // LABEL
- // ----------------------------------------------
- /**
- * Verifies that the admin user can get input ports.
- *
- * @throws Exception ex
- */
- @Test
- public void testLabelsGet() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/labels";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // get the response
- LabelsEntity entity = response.getEntity(LabelsEntity.class);
-
- // ensure the request was successful
- Assert.assertEquals(200, response.getStatus());
- Assert.assertNotNull(entity.getLabels());
- Assert.assertEquals(1, entity.getLabels().size());
- }
-
- /**
- * Verifies that the read only user cannot create labels.
- *
- * @throws Exception ex
- */
- @Test
- public void testLabelPost() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/labels";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- LabelEntity entity = new LabelEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPost(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot create labels.
- *
- * @throws Exception ex
- */
- @Test
- public void testLabelPut() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/labels/1";
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setVersion(NiFiTestUser.REVISION);
-
- // create the entity body
- LabelEntity entity = new LabelEntity();
- entity.setRevision(revision);
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, entity);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies that the read only user cannot delete labels.
- *
- * @throws Exception ex
- */
- @Test
- public void testLabelDelete() throws Exception {
- String url = BASE_URL + "/controller/process-groups/root/labels/1";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // HISTORY
- // ----------------------------------------------
- /**
- * Tests the ability to retrieve the NiFi history.
- *
- * @throws Exception ex
- */
- @Test
- public void testHistoryGet() throws Exception {
- String url = BASE_URL + "/controller/history";
-
- Map<String, String> queryParams = new HashMap<>();
- queryParams.put("offset", "1");
- queryParams.put("count", "1");
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url, queryParams);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(200, response.getStatus());
- }
-
- /**
- * Tests the ability to retrieve a specific action.
- *
- * @throws Exception ex
- */
- @Test
- public void testActionGet() throws Exception {
- int nonExistentActionId = 98775;
- String url = BASE_URL + "/controller/history/" + nonExistentActionId;
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(404, response.getStatus());
- }
-
- /**
- * Verifies the read only user cannot purge history.
- *
- * @throws Exception ex
- */
- @Test
- public void testHistoryDelete() throws Exception {
- String url = BASE_URL + "/controller/history";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testDelete(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- // ----------------------------------------------
- // USER
- // ----------------------------------------------
- /**
- * Tests the ability to retrieve the NiFi users.
- *
- * @throws Exception ex
- */
- @Test
- public void testUsersGet() throws Exception {
- String url = BASE_URL + "/controller/users";
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Tests the ability to retrieve a specific user.
- *
- * @throws Exception ex
- */
- @Test
- public void testUserGet() throws Exception {
- int nonExistentUserId = 98775;
- String url = BASE_URL + "/controller/users/" + nonExistentUserId;
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testGet(url);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- /**
- * Verifies the admin user can update a person.
- *
- * @throws Exception ex
- */
- @Test
- public void testUserPut() throws Exception {
- int nonExistentUserId = 98775;
- String url = BASE_URL + "/controller/users/" + nonExistentUserId;
-
- // create the form data
- Map<String, String> formData = new HashMap<>();
- formData.put("status", "DISABLED");
-
- // perform the request
- ClientResponse response = READ_ONLY_USER.testPut(url, formData);
-
- // ensure the request is failed with a forbidden status code
- Assert.assertEquals(403, response.getStatus());
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- // shutdown the server
- if (SERVER != null) {
- SERVER.shutdownServer();
- }
- SERVER = null;
-
- // look for the flow.xml
- File flow = new File(FLOW_XML_PATH);
- if (flow.exists()) {
- flow.delete();
- }
- }
-}