Search in sources :

Example 16 with FunnelEntity

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

the class EntityFactory method createFunnelEntity.

public FunnelEntity createFunnelEntity(final FunnelDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) {
    final FunnelEntity entity = new FunnelEntity();
    entity.setRevision(revision);
    if (dto != null) {
        entity.setPermissions(permissions);
        entity.setId(dto.getId());
        entity.setPosition(dto.getPosition());
        if (permissions != null && permissions.getCanRead()) {
            entity.setComponent(dto);
        }
    }
    return entity;
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity)

Example 17 with FunnelEntity

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

the class ITFunnelAccessControl method testReadUserPutFunnel.

/**
 * Ensures the READ user cannot put a funnel.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserPutFunnel() throws Exception {
    final FunnelEntity entity = getRandomFunnel(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    // attempt update the position
    entity.getRevision().setClientId(READ_CLIENT_ID);
    entity.getComponent().setPosition(new PositionDTO(0.0, 10.0));
    // perform the request
    final Response response = updateFunnel(helper.getReadUser(), entity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Response(javax.ws.rs.core.Response) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Example 18 with FunnelEntity

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

the class ITFunnelAccessControl method testNoneUserPutFunnel.

/**
 * Ensures the NONE user cannot put a funnel.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutFunnel() throws Exception {
    final FunnelEntity entity = getRandomFunnel(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    // attempt to update the position
    final FunnelDTO requestDto = new FunnelDTO();
    requestDto.setId(entity.getId());
    requestDto.setPosition(new PositionDTO(0.0, 15.0));
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
    final FunnelEntity requestEntity = new FunnelEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateFunnel(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Response(javax.ws.rs.core.Response) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 19 with FunnelEntity

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

the class ITFunnelAccessControl method testWriteUserPutFunnel.

/**
 * Ensures the WRITE user can put a funnel.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutFunnel() throws Exception {
    final FunnelEntity entity = getRandomFunnel(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final double y = 15.0;
    // attempt to update the position
    final FunnelDTO requestDto = new FunnelDTO();
    requestDto.setId(entity.getId());
    requestDto.setPosition(new PositionDTO(0.0, y));
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
    final FunnelEntity requestEntity = new FunnelEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateFunnel(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final FunnelEntity responseEntity = response.readEntity(FunnelEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Response(javax.ws.rs.core.Response) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 20 with FunnelEntity

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

the class ITFunnelAccessControl method verifyDelete.

private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
    final FunnelEntity entity = createFunnel();
    // create the entity body
    final Map<String, String> queryParams = new HashMap<>();
    queryParams.put("version", String.valueOf(entity.getRevision().getVersion()));
    queryParams.put("clientId", clientId);
    // perform the request
    Response response = user.testDelete(entity.getUri(), queryParams);
    // ensure the request is failed with a forbidden status code
    assertEquals(responseCode, response.getStatus());
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap)

Aggregations

FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)21 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Authorizable (org.apache.nifi.authorization.resource.Authorizable)5 FunnelDTO (org.apache.nifi.web.api.dto.FunnelDTO)5 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)5 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 HashMap (java.util.HashMap)3 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)3 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)3 PortEntity (org.apache.nifi.web.api.entity.PortEntity)3 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)3 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)3 Map (java.util.Map)2 GET (javax.ws.rs.GET)2