Search in sources :

Example 21 with LabelEntity

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

the class ITLabelAccessControl method testReadWriteUserPutLabelThroughInheritedPolicy.

/**
 * Ensures the READ_WRITE user can put a label.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutLabelThroughInheritedPolicy() throws Exception {
    final LabelEntity entity = createLabel(NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
    final String updatedLabel = "Updated name";
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(READ_WRITE_CLIENT_ID);
    entity.getComponent().setLabel(updatedLabel);
    // perform the request
    final Response response = updateLabel(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final LabelEntity responseEntity = response.readEntity(LabelEntity.class);
    // verify
    assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedLabel, responseEntity.getComponent().getLabel());
}
Also used : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Test(org.junit.Test)

Example 22 with LabelEntity

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

Aggregations

LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)22 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)9 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 LabelDTO (org.apache.nifi.web.api.dto.LabelDTO)5 HashMap (java.util.HashMap)3 Revision (org.apache.nifi.web.Revision)3 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)3 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)3 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)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