Search in sources :

Example 11 with FlowChangeAction

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

the class RemoteProcessGroupAuditor method createFlowChangeAction.

private FlowChangeAction createFlowChangeAction(final NiFiUser user, final Date timestamp, final RemoteProcessGroup remoteProcessGroup, final FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails) {
    FlowChangeAction remoteProcessGroupAction = new FlowChangeAction();
    remoteProcessGroupAction.setUserIdentity(user.getIdentity());
    remoteProcessGroupAction.setTimestamp(timestamp);
    remoteProcessGroupAction.setSourceId(remoteProcessGroup.getIdentifier());
    remoteProcessGroupAction.setSourceName(remoteProcessGroup.getName());
    remoteProcessGroupAction.setSourceType(Component.RemoteProcessGroup);
    remoteProcessGroupAction.setComponentDetails(remoteProcessGroupDetails);
    return remoteProcessGroupAction;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 12 with FlowChangeAction

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

the class ReportingTaskAuditor method updateReportingTaskAdvice.

/**
 * Audits the configuration of a reporting task.
 *
 * @param proceedingJoinPoint joinpoint
 * @param reportingTaskDTO dto
 * @param reportingTaskDAO dao
 * @return object
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && " + "execution(org.apache.nifi.controller.ReportingTaskNode updateReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO)) && " + "args(reportingTaskDTO) && " + "target(reportingTaskDAO)")
public Object updateReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskDTO reportingTaskDTO, ReportingTaskDAO reportingTaskDAO) throws Throwable {
    // determine the initial values for each property/setting thats changing
    ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
    final ScheduledState scheduledState = reportingTask.getScheduledState();
    // update the reporting task state
    final ReportingTaskNode updatedReportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the reporting task action...
    reportingTask = reportingTaskDAO.getReportingTask(updatedReportingTask.getIdentifier());
    // get the current user
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
        // create the reporting task details
        FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
        taskDetails.setType(reportingTask.getComponentType());
        // create a reporting task 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 = reportingTask.getReportingTask().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(reportingTask.getIdentifier());
                configurationAction.setSourceName(reportingTask.getName());
                configurationAction.setSourceType(Component.ReportingTask);
                configurationAction.setComponentDetails(taskDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final ScheduledState updatedScheduledState = reportingTask.getScheduledState();
        // determine if the running state has changed and its not disabled
        if (scheduledState != updatedScheduledState) {
            // create a reporting task action
            FlowChangeAction taskAction = new FlowChangeAction();
            taskAction.setUserIdentity(user.getIdentity());
            taskAction.setTimestamp(new Date());
            taskAction.setSourceId(reportingTask.getIdentifier());
            taskAction.setSourceName(reportingTask.getName());
            taskAction.setSourceType(Component.ReportingTask);
            taskAction.setComponentDetails(taskDetails);
            // set the operation accordingly
            if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
                taskAction.setOperation(Operation.Start);
            } else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
                taskAction.setOperation(Operation.Disable);
            } else {
                // state is now stopped... consider the previous state
                if (ScheduledState.RUNNING.equals(scheduledState)) {
                    taskAction.setOperation(Operation.Stop);
                } else if (ScheduledState.DISABLED.equals(scheduledState)) {
                    taskAction.setOperation(Operation.Enable);
                }
            }
            actions.add(taskAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedReportingTask;
}
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) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ScheduledState(org.apache.nifi.controller.ScheduledState) 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 13 with FlowChangeAction

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

the class UserAuditor method updateUserAdvice.

/**
 * Audits the configuration of a single user.
 *
 * @param proceedingJoinPoint join point
 * @param userDTO dto
 * @param userDAO dao
 * @return node
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserDAO+) && " + "execution(org.apache.nifi.authorization.User updateUser(org.apache.nifi.web.api.dto.UserDTO)) && " + "args(userDTO) && " + "target(userDAO)")
public User updateUserAdvice(ProceedingJoinPoint proceedingJoinPoint, UserDTO userDTO, UserDAO userDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    User user = userDAO.getUser(userDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(user, userDTO);
    // update the user state
    final User updatedUser = (User) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the user action...
    user = userDAO.getUser(updatedUser.getIdentifier());
    // get the current user
    NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (niFiUser != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(user, userDTO);
        // create a user 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) {
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(niFiUser.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(user.getIdentifier());
                configurationAction.setSourceName(user.getIdentity());
                configurationAction.setSourceType(Component.User);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedUser;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) User(org.apache.nifi.authorization.User) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 14 with FlowChangeAction

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

the class UserGroupAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a user group.
 *
 * @param userGroup userGroup
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(Group userGroup, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (niFiUser != null) {
        // create the user action for adding this user
        action = new FlowChangeAction();
        action.setUserIdentity(niFiUser.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(userGroup.getIdentifier());
        action.setSourceName(userGroup.getName());
        action.setSourceType(Component.UserGroup);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 15 with FlowChangeAction

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

the class StandardNiFiServiceFacadeTest method getAction.

private FlowChangeAction getAction(final Integer actionId, final String processorId) {
    final FlowChangeAction action = new FlowChangeAction();
    action.setId(actionId);
    action.setSourceId(processorId);
    action.setSourceType(Component.Processor);
    action.setOperation(Operation.Add);
    return action;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Aggregations

FlowChangeAction (org.apache.nifi.action.FlowChangeAction)39 Date (java.util.Date)34 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)29 Action (org.apache.nifi.action.Action)19 ArrayList (java.util.ArrayList)18 Around (org.aspectj.lang.annotation.Around)15 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)13 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)13 Operation (org.apache.nifi.action.Operation)9 ActionDetails (org.apache.nifi.action.details.ActionDetails)7 Component (org.apache.nifi.action.Component)5 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)3 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)3 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3