Search in sources :

Example 81 with RevisionDTO

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

Example 82 with RevisionDTO

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

the class ITLabelAccessControl method createLabel.

private LabelEntity createLabel(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/labels";
    // create the label
    LabelDTO label = new LabelDTO();
    label.setLabel(name);
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    LabelEntity entity = new LabelEntity();
    entity.setRevision(revision);
    entity.setComponent(label);
    // 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(LabelEntity.class);
    // verify creation
    label = entity.getComponent();
    assertEquals(name, label.getLabel());
    // get the label id
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 83 with RevisionDTO

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

the class ITLabelAccessControl method testNoneUserPutLabel.

/**
 * Ensures the NONE user cannot put a label.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutLabel() throws Exception {
    final LabelEntity entity = getRandomLabel(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final LabelDTO requestDto = new LabelDTO();
    requestDto.setId(entity.getId());
    requestDto.setLabel(updatedName);
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
    final LabelEntity requestEntity = new LabelEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateLabel(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 84 with RevisionDTO

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

the class ITLabelAccessControl method testWriteUserPutLabel.

/**
 * Ensures the WRITE user can put a label.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutLabel() throws Exception {
    final LabelEntity entity = getRandomLabel(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedLabel = "Updated Name";
    // attempt to update the label
    final LabelDTO requestDto = new LabelDTO();
    requestDto.setId(entity.getId());
    requestDto.setLabel(updatedLabel);
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
    final LabelEntity requestEntity = new LabelEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateLabel(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final LabelEntity responseEntity = response.readEntity(LabelEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 85 with RevisionDTO

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

the class ITOutputPortAccessControl method createOutputPort.

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
    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
    outputPort = entity.getComponent();
    assertEquals(updatedName, outputPort.getName());
    // get the output 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)

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