Search in sources :

Example 16 with PortEntity

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

the class ITInputPortAccessControl method createInputPort.

private PortEntity createInputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/input-ports";
    final String updatedName = name + count++;
    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.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(inputPort);
    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(PortEntity.class);
    // verify creation
    inputPort = entity.getComponent();
    assertEquals(updatedName, inputPort.getName());
    // get the input port
    return entity;
}
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)

Example 17 with PortEntity

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

the class ITInputPortAccessControl method testWriteUserPutInputPort.

/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(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.WRITE_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.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
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)

Example 18 with PortEntity

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

the class ITInputPortAccessControl method testWriteUserGetInputPort.

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

Example 19 with PortEntity

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

the class ITInputPortAccessControl method testNoneUserGetInputPort.

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

Example 20 with PortEntity

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

the class ITOutputPortAccessControl method testReadWriteUserPutOutputPortThroughInheritedPolicy.

/**
 * 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 Response response = updateOutputPort(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedName, responseEntity.getComponent().getName());
}
Also used : Response(javax.ws.rs.core.Response) 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