Search in sources :

Example 41 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.

the class ITInputPortAccessControl method testReadWriteUserGetInputPort.

/**
 * Ensures the READ WRITE user can get an input port.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserGetInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
}
Also used : PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 42 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.

the class ITInputPortAccessControl method testReadUserPutInputPort.

/**
 * Ensures the READ user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    // attempt update the name
    entity.getRevision().setClientId(READ_CLIENT_ID);
    entity.getComponent().setName("Updated Name" + count++);
    // perform the request
    final Response response = updateInputPort(helper.getReadUser(), entity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 43 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.

the class ITInputPortAccessControl method testReadUserGetInputPort.

/**
 * Ensures the READ user can get an input port.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserGetInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
}
Also used : PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 44 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.

the class ITInputPortAccessControl method getRandomInputPort.

private PortEntity getRandomInputPort(final NiFiTestUser user) throws Exception {
    final String url = helper.getBaseUrl() + "/flow/process-groups/root";
    // get the input ports
    final Response response = user.testGet(url);
    // ensure the response was successful
    assertEquals(200, response.getStatus());
    // unmarshal
    final ProcessGroupFlowEntity flowEntity = response.readEntity(ProcessGroupFlowEntity.class);
    final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
    final Set<PortEntity> inputPorts = flowDto.getInputPorts();
    // ensure the correct number of input ports
    assertFalse(inputPorts.isEmpty());
    // use the first input port as the target
    Iterator<PortEntity> inputPortIter = inputPorts.iterator();
    assertTrue(inputPortIter.hasNext());
    return inputPortIter.next();
}
Also used : Response(javax.ws.rs.core.Response) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 45 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.

the class ITInputPortAccessControl method testNoneUserPutInputPort.

/**
 * Ensures the NONE user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().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 Response response = updateInputPort(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Aggregations

PortEntity (org.apache.nifi.web.api.entity.PortEntity)52 Response (javax.ws.rs.core.Response)23 Test (org.junit.Test)18 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)17 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 PortDTO (org.apache.nifi.web.api.dto.PortDTO)16 HashMap (java.util.HashMap)13 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)10 Consumes (javax.ws.rs.Consumes)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)10 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)9 ProcessGroupFlowEntity (org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)9 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)8 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)8 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)8 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)8