Search in sources :

Example 21 with ProcessorEntity

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

the class ITProcessorAccessControl method testReadUserClearState.

/**
 * Ensures the READ user cannot clear state.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserClearState() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
    // perform the request
    final Response response = helper.getReadUser().testPost(url);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Test(org.junit.Test)

Example 22 with ProcessorEntity

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

the class ITProcessorAccessControl method testReadWriteUserClearState.

/**
 * Ensures the READ WRITE user can clear state.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserClearState() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String url = helper.getBaseUrl() + "/processors/" + entity.getId() + "/state/clear-requests";
    // perform the request
    final Response response = helper.getReadWriteUser().testPost(url);
    // ensure ok response
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Test(org.junit.Test)

Example 23 with ProcessorEntity

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

the class ITProcessorAccessControl method testWriteUserGetProcessor.

/**
 * Ensures the WRITE user can get a processor.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserGetProcessor() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
}
Also used : ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Test(org.junit.Test)

Example 24 with ProcessorEntity

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

the class ITProcessorAccessControl method createProcessor.

public static ProcessorEntity createProcessor(final AccessControlHelper ach, final String name) throws Exception {
    String url = ach.getBaseUrl() + "/process-groups/root/processors";
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName(name);
    processor.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request
    Response response = ach.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(ProcessorEntity.class);
    // verify creation
    processor = entity.getComponent();
    assertEquals(name, processor.getName());
    assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
    // get the processor
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) 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 25 with ProcessorEntity

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

the class ITProcessorAccessControl method testWriteUserPutProcessor.

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

Aggregations

ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)60 Response (javax.ws.rs.core.Response)29 Test (org.junit.Test)26 HashMap (java.util.HashMap)20 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)19 HashSet (java.util.HashSet)17 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)17 URI (java.net.URI)16 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)16 Map (java.util.Map)15 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)12 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)11 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)11 Authentication (org.springframework.security.core.Authentication)11 Set (java.util.Set)10 Authorizable (org.apache.nifi.authorization.resource.Authorizable)10 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)8