Search in sources :

Example 16 with LabelEntity

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

the class ITLabelAccessControl method verifyDelete.

private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
    final LabelEntity entity = createLabel("Copy");
    // 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 : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) HashMap(java.util.HashMap)

Example 17 with LabelEntity

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

the class ITLabelAccessControl method testReadWriteUserPutLabel.

/**
 * Ensures the READ_WRITE user can put a label.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutLabel() throws Exception {
    final LabelEntity entity = getRandomLabel(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String updatedLabel = "Updated Name";
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(AccessControlHelper.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(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 18 with LabelEntity

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

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

the class ITLabelAccessControl method testReadWriteUserGetLabel.

/**
 * Ensures the READ WRITE user can get a label.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserGetLabel() throws Exception {
    final LabelEntity entity = getRandomLabel(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Test(org.junit.Test)

Example 20 with LabelEntity

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

the class ITLabelAccessControl method testWriteUserGetLabel.

/**
 * Ensures the WRITE user can get a label.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserGetLabel() throws Exception {
    final LabelEntity entity = getRandomLabel(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) 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