Search in sources :

Example 1 with ActionEntity

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

the class StandardNiFiServiceFacade method getActions.

@Override
public HistoryDTO getActions(final HistoryQueryDTO historyQueryDto) {
    // extract the query criteria
    final HistoryQuery historyQuery = new HistoryQuery();
    historyQuery.setStartDate(historyQueryDto.getStartDate());
    historyQuery.setEndDate(historyQueryDto.getEndDate());
    historyQuery.setSourceId(historyQueryDto.getSourceId());
    historyQuery.setUserIdentity(historyQueryDto.getUserIdentity());
    historyQuery.setOffset(historyQueryDto.getOffset());
    historyQuery.setCount(historyQueryDto.getCount());
    historyQuery.setSortColumn(historyQueryDto.getSortColumn());
    historyQuery.setSortOrder(historyQueryDto.getSortOrder());
    // perform the query
    final History history = auditService.getActions(historyQuery);
    // only retain authorized actions
    final HistoryDTO historyDto = dtoFactory.createHistoryDto(history);
    if (history.getActions() != null) {
        final List<ActionEntity> actionEntities = new ArrayList<>();
        for (final Action action : history.getActions()) {
            final AuthorizationResult result = authorizeAction(action);
            actionEntities.add(entityFactory.createActionEntity(dtoFactory.createActionDto(action), Result.Approved.equals(result.getResult())));
        }
        historyDto.setActions(actionEntities);
    }
    // create the response
    return historyDto;
}
Also used : HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) PropertyHistoryDTO(org.apache.nifi.web.api.dto.PropertyHistoryDTO) ComponentHistoryDTO(org.apache.nifi.web.api.dto.ComponentHistoryDTO) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) RequestAction(org.apache.nifi.authorization.RequestAction) Action(org.apache.nifi.action.Action) HistoryQuery(org.apache.nifi.history.HistoryQuery) ArrayList(java.util.ArrayList) History(org.apache.nifi.history.History) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity)

Example 2 with ActionEntity

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

the class EntityFactory method createActionEntity.

public ActionEntity createActionEntity(final ActionDTO dto, final boolean canRead) {
    final ActionEntity entity = new ActionEntity();
    if (dto != null) {
        entity.setId(dto.getId());
        entity.setSourceId(dto.getSourceId());
        entity.setTimestamp(dto.getTimestamp());
        entity.setCanRead(canRead);
        if (canRead) {
            entity.setAction(dto);
        }
    }
    return entity;
}
Also used : ActionEntity(org.apache.nifi.web.api.entity.ActionEntity)

Example 3 with ActionEntity

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

the class FlowResource method getAction.

/**
 * Gets the action for the corresponding id.
 *
 * @param id The id of the action to get.
 * @return An actionEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("history/{id}")
@ApiOperation(value = "Gets an action", notes = NON_GUARANTEED_ENDPOINT, response = ActionEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @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 getAction(@ApiParam(value = "The action id.", required = true) @PathParam("id") IntegerParameter id) {
    authorizeFlow();
    // ensure the id was specified
    if (id == null) {
        throw new IllegalArgumentException("The action id must be specified.");
    }
    // Note: History requests are not replicated throughout the cluster and are instead handled by the nodes independently
    // get the response entity for the specified action
    final ActionEntity entity = serviceFacade.getAction(id.getInteger());
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ActionEntity(org.apache.nifi.web.api.entity.ActionEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ActionEntity

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

the class StandardNiFiServiceFacadeTest method testGetActionApprovedThroughController.

@Test
public void testGetActionApprovedThroughController() throws Exception {
    // set the user
    final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
    SecurityContextHolder.getContext().setAuthentication(authentication);
    // get the action
    final ActionEntity entity = serviceFacade.getAction(ACTION_ID_2);
    // verify
    assertEquals(ACTION_ID_2, entity.getId());
    assertTrue(entity.getCanRead());
    // component does not exists, so only checks against the controller
    verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {

        @Override
        public boolean matches(Object o) {
            return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_2);
        }
    }));
    verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {

        @Override
        public boolean matches(Object o) {
            return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
        }
    }));
}
Also used : AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) Authentication(org.springframework.security.core.Authentication) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ArgumentMatcher(org.mockito.ArgumentMatcher) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Test(org.junit.Test)

Example 5 with ActionEntity

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

the class StandardNiFiServiceFacadeTest method testGetActionApprovedThroughAction.

@Test
public void testGetActionApprovedThroughAction() throws Exception {
    // set the user
    final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_1).build()));
    SecurityContextHolder.getContext().setAuthentication(authentication);
    // get the action
    final ActionEntity entity = serviceFacade.getAction(ACTION_ID_1);
    // verify
    assertEquals(ACTION_ID_1, entity.getId());
    assertTrue(entity.getCanRead());
    // resource exists and is approved, no need to check the controller
    verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {

        @Override
        public boolean matches(Object o) {
            return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_1);
        }
    }));
    verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {

        @Override
        public boolean matches(Object o) {
            return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
        }
    }));
}
Also used : AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) Authentication(org.springframework.security.core.Authentication) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) ArgumentMatcher(org.mockito.ArgumentMatcher) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Test(org.junit.Test)

Aggregations

ActionEntity (org.apache.nifi.web.api.entity.ActionEntity)5 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)2 Builder (org.apache.nifi.authorization.user.StandardNiFiUser.Builder)2 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)2 Test (org.junit.Test)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 Authentication (org.springframework.security.core.Authentication)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Action (org.apache.nifi.action.Action)1 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)1 AuthorizationResult (org.apache.nifi.authorization.AuthorizationResult)1 RequestAction (org.apache.nifi.authorization.RequestAction)1 History (org.apache.nifi.history.History)1