Search in sources :

Example 51 with Action

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

the class SnippetAuditor method auditSnippet.

/**
 * Audits the specified snippet.
 */
private void auditSnippet(final FlowSnippetDTO snippet) {
    final Collection<Action> actions = new ArrayList<>();
    final Date timestamp = new Date();
    // input ports
    for (final PortDTO inputPort : snippet.getInputPorts()) {
        actions.add(generateAuditRecord(inputPort.getId(), inputPort.getName(), Component.InputPort, Operation.Add, timestamp));
    }
    // output ports
    for (final PortDTO outputPort : snippet.getOutputPorts()) {
        actions.add(generateAuditRecord(outputPort.getId(), outputPort.getName(), Component.OutputPort, Operation.Add, timestamp));
    }
    // remote processor groups
    for (final RemoteProcessGroupDTO remoteProcessGroup : snippet.getRemoteProcessGroups()) {
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
        remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
        final FlowChangeAction action = generateAuditRecord(remoteProcessGroup.getId(), remoteProcessGroup.getName(), Component.RemoteProcessGroup, Operation.Add, timestamp);
        action.setComponentDetails(remoteProcessGroupDetails);
        actions.add(action);
    }
    // processor groups
    for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
        actions.add(generateAuditRecord(processGroup.getId(), processGroup.getName(), Component.ProcessGroup, Operation.Add, timestamp));
    }
    // processors
    for (final ProcessorDTO processor : snippet.getProcessors()) {
        final FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));
        final FlowChangeAction action = generateAuditRecord(processor.getId(), processor.getName(), Component.Processor, Operation.Add, timestamp);
        action.setComponentDetails(processorDetails);
        actions.add(action);
    }
    // funnels
    for (final FunnelDTO funnel : snippet.getFunnels()) {
        actions.add(generateAuditRecord(funnel.getId(), StringUtils.EMPTY, Component.Funnel, Operation.Add, timestamp));
    }
    // connections
    for (final ConnectionDTO connection : snippet.getConnections()) {
        final ConnectableDTO source = connection.getSource();
        final ConnectableDTO destination = connection.getDestination();
        // determine the relationships and connection name
        final String relationships = CollectionUtils.isEmpty(connection.getSelectedRelationships()) ? StringUtils.EMPTY : StringUtils.join(connection.getSelectedRelationships(), ", ");
        final String name = StringUtils.isBlank(connection.getName()) ? relationships : connection.getName();
        // create the connect details
        FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
        connectDetails.setSourceId(source.getId());
        connectDetails.setSourceName(source.getName());
        connectDetails.setSourceType(determineConnectableType(source));
        connectDetails.setRelationship(relationships);
        connectDetails.setDestinationId(destination.getId());
        connectDetails.setDestinationName(destination.getName());
        connectDetails.setDestinationType(determineConnectableType(destination));
        // create the audit record
        final FlowChangeAction action = generateAuditRecord(connection.getId(), name, Component.Connection, Operation.Connect, timestamp);
        action.setActionDetails(connectDetails);
        actions.add(action);
    }
    // save the actions
    if (!actions.isEmpty()) {
        saveActions(actions, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ArrayList(java.util.ArrayList) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) Date(java.util.Date) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 52 with Action

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

the class SnippetAuditor method removeSnippetAdvice.

/**
 * Audits bulk delete.
 *
 * @param proceedingJoinPoint join point
 * @param snippetId snippet id
 * @param snippetDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(void deleteSnippetComponents(java.lang.String)) && " + "args(snippetId) && " + "target(snippetDAO)")
public void removeSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, String snippetId, SnippetDAO snippetDAO) throws Throwable {
    // get the snippet before removing it
    final Snippet snippet = snippetDAO.getSnippet(snippetId);
    // locate all the components being removed
    final Set<Funnel> funnels = new HashSet<>();
    for (String id : snippet.getFunnels().keySet()) {
        funnels.add(funnelDAO.getFunnel(id));
    }
    final Set<Port> inputPorts = new HashSet<>();
    for (String id : snippet.getInputPorts().keySet()) {
        inputPorts.add(inputPortDAO.getPort(id));
    }
    final Set<Port> outputPorts = new HashSet<>();
    for (String id : snippet.getOutputPorts().keySet()) {
        outputPorts.add(outputPortDAO.getPort(id));
    }
    final Set<RemoteProcessGroup> remoteProcessGroups = new HashSet<>();
    for (String id : snippet.getRemoteProcessGroups().keySet()) {
        remoteProcessGroups.add(remoteProcessGroupDAO.getRemoteProcessGroup(id));
    }
    final Set<ProcessGroup> processGroups = new HashSet<>();
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    for (String id : snippet.getProcessGroups().keySet()) {
        processGroups.add(processGroupDAO.getProcessGroup(id));
    }
    final Set<ProcessorNode> processors = new HashSet<>();
    for (String id : snippet.getProcessors().keySet()) {
        processors.add(processorDAO.getProcessor(id));
    }
    final Set<Connection> connections = new HashSet<>();
    for (String id : snippet.getConnections().keySet()) {
        connections.add(connectionDAO.getConnection(id));
    }
    // remove the snippet and components
    proceedingJoinPoint.proceed();
    final Collection<Action> actions = new ArrayList<>();
    // audit funnel removal
    for (Funnel funnel : funnels) {
        final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port inputPort : inputPorts) {
        final Action action = portAuditor.generateAuditRecord(inputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port outputPort : outputPorts) {
        final Action action = portAuditor.generateAuditRecord(outputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (RemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessGroup processGroup : processGroups) {
        final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessorNode processor : processors) {
        final Action action = processorAuditor.generateAuditRecord(processor, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Connection connection : connections) {
        final ConnectDetails connectDetails = relationshipAuditor.createConnectDetails(connection, connection.getRelationships());
        final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails);
        if (action != null) {
            actions.add(action);
        }
    }
    // save the actions
    if (CollectionUtils.isNotEmpty(actions)) {
        saveActions(actions, logger);
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) Port(org.apache.nifi.connectable.Port) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Snippet(org.apache.nifi.controller.Snippet) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) HashSet(java.util.HashSet) Around(org.aspectj.lang.annotation.Around)

Example 53 with Action

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

the class UserAuditor method removeUserAdvice.

/**
 * Audits the removal of a user via deleteUser().
 *
 * @param proceedingJoinPoint join point
 * @param userId user id
 * @param userDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserDAO+) && " + "execution(org.apache.nifi.authorization.User deleteUser(java.lang.String)) && " + "args(userId) && " + "target(userDAO)")
public User removeUserAdvice(ProceedingJoinPoint proceedingJoinPoint, String userId, UserDAO userDAO) throws Throwable {
    // get the user before removing it
    User user = userDAO.getUser(userId);
    // remove the user
    final User removedUser = (User) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the user removal
    final Action action = generateAuditRecord(user, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return removedUser;
}
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) Around(org.aspectj.lang.annotation.Around)

Example 54 with Action

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

the class UserAuditor method createUserAdvice.

/**
 * Audits the creation of policies via createUser().
 *
 * 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 Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserDAO+) && " + "execution(org.apache.nifi.authorization.User createUser(org.apache.nifi.web.api.dto.UserDTO))")
public User createUserAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the access user
    User user = (User) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the user action...
    final Action action = generateAuditRecord(user, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return user;
}
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) Around(org.aspectj.lang.annotation.Around)

Example 55 with Action

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

the class UserGroupAuditor method createUserGroupAdvice.

/**
 * Audits the creation of policies via createUser().
 *
 * 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 Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserGroupDAO+) && " + "execution(org.apache.nifi.authorization.Group createUserGroup(org.apache.nifi.web.api.dto.UserGroupDTO))")
public Group createUserGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the access user group
    Group userGroup = (Group) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the user action...
    final Action action = generateAuditRecord(userGroup, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return userGroup;
}
Also used : Group(org.apache.nifi.authorization.Group) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) 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