Search in sources :

Example 1 with Action

use of org.apache.nifi.action.Action 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 Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class AccessPolicyAuditor method removePolicyAdvice.

/**
 * Audits the removal of a policy via deleteAccessPolicy().
 *
 * @param proceedingJoinPoint join point
 * @param policyId policy id
 * @param accessPolicyDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.AccessPolicyDAO+) && " + "execution(org.apache.nifi.authorization.AccessPolicy deleteAccessPolicy(java.lang.String)) && " + "args(policyId) && " + "target(accessPolicyDAO)")
public AccessPolicy removePolicyAdvice(ProceedingJoinPoint proceedingJoinPoint, String policyId, AccessPolicyDAO accessPolicyDAO) throws Throwable {
    // get the policy before removing it
    AccessPolicy accessPolicy = accessPolicyDAO.getAccessPolicy(policyId);
    // remove the policy
    final AccessPolicy removedAccessPolicy = (AccessPolicy) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the policy removal
    final Action action = generateAuditRecord(accessPolicy, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return removedAccessPolicy;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) Around(org.aspectj.lang.annotation.Around)

Example 3 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ControllerServiceAuditor method updateControllerServiceReferenceAdvice.

/**
 * Audits the update of a component referencing a controller service.
 *
 * @param proceedingJoinPoint join point
 * @return object
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(org.apache.nifi.controller.service.ControllerServiceReference " + "updateControllerServiceReferencingComponents(java.lang.String, org.apache.nifi.controller.ScheduledState, " + "org.apache.nifi.controller.service.ControllerServiceState))")
public Object updateControllerServiceReferenceAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // update the controller service references
    final ControllerServiceReference controllerServiceReference = (ControllerServiceReference) proceedingJoinPoint.proceed();
    // get the current user
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user != null) {
        final Collection<Action> actions = new ArrayList<>();
        final Collection<String> visitedServices = new ArrayList<>();
        visitedServices.add(controllerServiceReference.getReferencedComponent().getIdentifier());
        // get all applicable actions
        getUpdateActionsForReferencingComponents(user, actions, visitedServices, controllerServiceReference.getReferencingComponents());
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return controllerServiceReference;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) ArrayList(java.util.ArrayList) Around(org.aspectj.lang.annotation.Around)

Example 4 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ControllerServiceAuditor method updateControllerServiceAdvice.

/**
 * Audits the configuration of a single controller service.
 *
 * @param proceedingJoinPoint join point
 * @param controllerServiceDTO dto
 * @param controllerServiceDAO dao
 * @return object
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(org.apache.nifi.controller.service.ControllerServiceNode updateControllerService(org.apache.nifi.web.api.dto.ControllerServiceDTO)) && " + "args(controllerServiceDTO) && " + "target(controllerServiceDAO)")
public Object updateControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceDTO controllerServiceDTO, ControllerServiceDAO controllerServiceDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(controllerService, controllerServiceDTO);
    final boolean isDisabled = isDisabled(controllerService);
    // update the controller service state
    final ControllerServiceNode updatedControllerService = (ControllerServiceNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the controller service action...
    controllerService = controllerServiceDAO.getControllerService(updatedControllerService.getIdentifier());
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(controllerService, controllerServiceDTO);
        // create the controller service details
        FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
        serviceDetails.setType(controllerService.getComponentType());
        // create a controller service action
        Date actionTimestamp = new Date();
        Collection<Action> actions = new ArrayList<>();
        // go through each updated value
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            Operation operation = null;
            // determine the type of operation
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                operation = Operation.Configure;
            }
            // create a configuration action accordingly
            if (operation != null) {
                // clear the value if this property is sensitive
                final PropertyDescriptor propertyDescriptor = controllerService.getControllerServiceImplementation().getPropertyDescriptor(property);
                if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
                    if (newValue != null) {
                        newValue = "********";
                    }
                    if (oldValue != null) {
                        oldValue = "********";
                    }
                } else if (ANNOTATION_DATA.equals(property)) {
                    if (newValue != null) {
                        newValue = "<annotation data not shown>";
                    }
                    if (oldValue != null) {
                        oldValue = "<annotation data not shown>";
                    }
                }
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(controllerService.getIdentifier());
                configurationAction.setSourceName(controllerService.getName());
                configurationAction.setSourceType(Component.ControllerService);
                configurationAction.setComponentDetails(serviceDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final boolean updateIsDisabled = isDisabled(updatedControllerService);
        // determine if the running state has changed and its not disabled
        if (isDisabled != updateIsDisabled) {
            // create a controller service action
            FlowChangeAction serviceAction = new FlowChangeAction();
            serviceAction.setUserIdentity(user.getIdentity());
            serviceAction.setTimestamp(new Date());
            serviceAction.setSourceId(controllerService.getIdentifier());
            serviceAction.setSourceName(controllerService.getName());
            serviceAction.setSourceType(Component.ControllerService);
            serviceAction.setComponentDetails(serviceDetails);
            // set the operation accordingly
            if (updateIsDisabled) {
                serviceAction.setOperation(Operation.Disable);
            } else {
                serviceAction.setOperation(Operation.Enable);
            }
            actions.add(serviceAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedControllerService;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 5 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ControllerServiceAuditor method createControllerServiceAdvice.

/**
 * Audits the creation of controller service via createControllerService().
 *
 * This method only needs to be run 'after returning'. However, in Java 7 the order in which these methods are returned from Class.getDeclaredMethods (even though there is no order guaranteed)
 * seems to differ from Java 6. SpringAOP depends on this ordering to determine advice precedence. By normalizing all advice into Around advice we can alleviate this issue.
 *
 * @param proceedingJoinPoint join point
 * @return node
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(org.apache.nifi.controller.service.ControllerServiceNode createControllerService(org.apache.nifi.web.api.dto.ControllerServiceDTO))")
public ControllerServiceNode createControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // update the controller service state
    ControllerServiceNode controllerService = (ControllerServiceNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the controller service action...
    final Action action = generateAuditRecord(controllerService, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return controllerService;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) Around(org.aspectj.lang.annotation.Around)

Aggregations

Action (org.apache.nifi.action.Action)68 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)46 Around (org.aspectj.lang.annotation.Around)40 ArrayList (java.util.ArrayList)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)21 Date (java.util.Date)19 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)19 Test (org.junit.Test)19 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)15 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)12 Operation (org.apache.nifi.action.Operation)8 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)8 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 ActionDetails (org.apache.nifi.action.details.ActionDetails)5 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)5 Connection (org.apache.nifi.connectable.Connection)5 Port (org.apache.nifi.connectable.Port)5 ProcessorNode (org.apache.nifi.controller.ProcessorNode)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)5