Search in sources :

Example 76 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.

the class ITAccessTokenEndpoint method createProcessor.

private ProcessorDTO createProcessor(final String token) throws Exception {
    String url = BASE_URL + "/process-groups/root/processors";
    // authorization header
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "Bearer " + token);
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("Copy");
    processor.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(CLIENT_ID);
    revision.setVersion(0l);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request
    Response response = TOKEN_USER.testPostWithHeaders(url, entity, headers);
    // ensure the request is successful
    Assert.assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(ProcessorEntity.class);
    // verify creation
    processor = entity.getComponent();
    Assert.assertEquals("Copy", processor.getName());
    Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
    return processor;
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 77 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.

the class ITConnectionAccessControl method testWriteUserPutConnection.

/**
 * Ensures the WRITE user can put a connection.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutConnection() throws Exception {
    final ConnectionEntity entity = getRandomConnection(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final ConnectionDTO requestDto = new ConnectionDTO();
    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 ConnectionEntity requestEntity = new ConnectionEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateConnection(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final ConnectionEntity responseEntity = response.readEntity(ConnectionEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : Response(javax.ws.rs.core.Response) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 78 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO in project nifi by apache.

the class ITConnectionAccessControl method testNoneUserPutConnection.

/**
 * Ensures the NONE user cannot put a connection.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutConnection() throws Exception {
    final ConnectionEntity entity = getRandomConnection(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final ConnectionDTO requestDto = new ConnectionDTO();
    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 ConnectionEntity requestEntity = new ConnectionEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateConnection(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 79 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO 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 80 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO 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)

Aggregations

RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)91 Response (javax.ws.rs.core.Response)45 Authorizable (org.apache.nifi.authorization.resource.Authorizable)30 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)29 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)26 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)26 PortEntity (org.apache.nifi.web.api.entity.PortEntity)25 HashMap (java.util.HashMap)24 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)24 Map (java.util.Map)23 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)23 Set (java.util.Set)22 Collectors (java.util.stream.Collectors)22 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)22 ControllerServiceEntity (org.apache.nifi.web.api.entity.ControllerServiceEntity)22 ScheduledState (org.apache.nifi.controller.ScheduledState)21 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)21 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)21 HashSet (java.util.HashSet)20 Authorizer (org.apache.nifi.authorization.Authorizer)19