Search in sources :

Example 16 with ConnectionEntity

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

the class FlowFileQueueResource method createDropRequest.

/**
 * Creates a request to delete the flowfiles in the queue of the specified connection.
 *
 * @param httpServletRequest request
 * @param id                 The id of the connection
 * @return A dropRequestEntity
 */
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/drop-requests")
@ApiOperation(value = "Creates a request to drop the contents of the queue in this connection.", response = DropRequestEntity.class, authorizations = { @Authorization(value = "Write Source Data - /data/{component-type}/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 202, message = "The request has been accepted. A HTTP response header will contain the URI where the response can be polled."), @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response createDropRequest(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The connection id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST);
    }
    final ConnectionEntity requestConnectionEntity = new ConnectionEntity();
    requestConnectionEntity.setId(id);
    return withWriteLock(serviceFacade, requestConnectionEntity, lookup -> {
        final ConnectionAuthorizable connAuth = lookup.getConnection(id);
        final Authorizable dataAuthorizable = connAuth.getSourceData();
        dataAuthorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, (connectionEntity) -> {
        // ensure the id is the same across the cluster
        final String dropRequestId = generateUuid();
        // submit the drop request
        final DropRequestDTO dropRequest = serviceFacade.createFlowFileDropRequest(connectionEntity.getId(), dropRequestId);
        dropRequest.setUri(generateResourceUri("flowfile-queues", connectionEntity.getId(), "drop-requests", dropRequest.getId()));
        // create the response entity
        final DropRequestEntity entity = new DropRequestEntity();
        entity.setDropRequest(dropRequest);
        // generate the URI where the response will be
        final URI location = URI.create(dropRequest.getUri());
        return Response.status(Status.ACCEPTED).location(location).entity(entity).build();
    });
}
Also used : DropRequestDTO(org.apache.nifi.web.api.dto.DropRequestDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) URI(java.net.URI) DropRequestEntity(org.apache.nifi.web.api.entity.DropRequestEntity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with ConnectionEntity

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

the class ITConnectionAccessControl method testWriteUserGetConnection.

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

Example 18 with ConnectionEntity

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

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

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

the class ITConnectionAccessControl method testReadWriteUserPutConnection.

/**
 * Ensures the READ_WRITE user can put a connection.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutConnection() throws Exception {
    final ConnectionEntity entity = getRandomConnection(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
    entity.getComponent().setName(updatedName);
    // perform the request
    final Response response = updateConnection(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final ConnectionEntity responseEntity = response.readEntity(ConnectionEntity.class);
    // verify
    assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedName, responseEntity.getComponent().getName());
}
Also used : Response(javax.ws.rs.core.Response) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) Test(org.junit.Test)

Aggregations

ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)25 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 Authorizable (org.apache.nifi.authorization.resource.Authorizable)7 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)7 ConnectionAuthorizable (org.apache.nifi.authorization.ConnectionAuthorizable)5 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)5 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3 POST (javax.ws.rs.POST)3 Revision (org.apache.nifi.web.Revision)3 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)3 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)3 PortEntity (org.apache.nifi.web.api.entity.PortEntity)3