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;
}
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;
}
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();
}
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());
}
}));
}
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());
}
}));
}
Aggregations