Search in sources :

Example 66 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class TestHttpFlowFileServerProtocol method testUnauthorized.

@Test
public void testUnauthorized() throws Exception {
    final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
    final Peer peer = getDefaultPeer();
    ((HttpServerCommunicationsSession) peer.getCommunicationsSession()).putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    final RootGroupPort port = mock(RootGroupPort.class);
    final PortAuthorizationResult authResult = mock(PortAuthorizationResult.class);
    doReturn(true).when(processGroup).isRootGroup();
    doReturn(port).when(processGroup).getOutputPort("port-identifier");
    doReturn(authResult).when(port).checkUserAuthorization(any(String.class));
    serverProtocol.setRootProcessGroup(processGroup);
    try {
        serverProtocol.handshake(peer);
        fail();
    } catch (final HandshakeException e) {
        assertEquals(ResponseCode.UNAUTHORIZED, e.getResponseCode());
    }
    assertFalse(serverProtocol.isHandshakeSuccessful());
}
Also used : HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Peer(org.apache.nifi.remote.Peer) ProcessGroup(org.apache.nifi.groups.ProcessGroup) PortAuthorizationResult(org.apache.nifi.remote.PortAuthorizationResult) HandshakeException(org.apache.nifi.remote.exception.HandshakeException) Test(org.junit.Test)

Example 67 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ProcessGroupAuditor method createProcessGroupAdvice.

/**
 * Audits the creation of process groups via createProcessGroup().
 *
 * 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 group
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup createProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.ProcessGroupDTO))")
public ProcessGroup createProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the process group
    ProcessGroup processGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the process group action...
    // audit process group creation
    final Action action = generateAuditRecord(processGroup, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return processGroup;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Around(org.aspectj.lang.annotation.Around)

Example 68 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ProcessGroupAuditor method updateVersionControlInformationAdvice.

@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateVersionControlInformation(..))")
public ProcessGroup updateVersionControlInformationAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final VersionControlInformationDTO vciDto = (VersionControlInformationDTO) proceedingJoinPoint.getArgs()[0];
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(vciDto.getGroupId());
    final VersionControlInformation vci = processGroup.getVersionControlInformation();
    final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    final Operation operation;
    if (vci == null) {
        operation = Operation.StartVersionControl;
    } else {
        operation = Operation.CommitLocalChanges;
    }
    saveUpdateAction(NiFiUserUtils.getNiFiUser(), vciDto.getGroupId(), operation);
    return updatedProcessGroup;
}
Also used : ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Operation(org.apache.nifi.action.Operation) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) Around(org.aspectj.lang.annotation.Around)

Example 69 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ProcessGroupAuditor method saveUpdateAction.

private void saveUpdateAction(final NiFiUser user, final String groupId, final Operation operation) throws Throwable {
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    // if the user was starting/stopping this process group
    FlowChangeAction action = new FlowChangeAction();
    action.setUserIdentity(user.getIdentity());
    action.setSourceId(processGroup.getIdentifier());
    action.setSourceName(processGroup.getName());
    action.setSourceType(Component.ProcessGroup);
    action.setTimestamp(new Date());
    action.setOperation(operation);
    // add this action
    saveAction(action, logger);
}
Also used : ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 70 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class ProcessGroupAuditor method updateProcessGroupAdvice.

/**
 * Audits the update of process group configuration.
 *
 * @param proceedingJoinPoint join point
 * @param processGroupDTO dto
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroup(org.apache.nifi.web.api.dto.ProcessGroupDTO)) && " + "args(processGroupDTO)")
public ProcessGroup updateProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessGroupDTO processGroupDTO) throws Throwable {
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupDTO.getId());
    String name = processGroup.getName();
    String comments = processGroup.getComments();
    // perform the underlying operation
    ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<ActionDetails> details = new ArrayList<>();
        // see if the name has changed
        if (name != null && updatedProcessGroup.getName() != null && !name.equals(updatedProcessGroup.getName())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("name");
            configDetails.setValue(updatedProcessGroup.getName());
            configDetails.setPreviousValue(name);
            details.add(configDetails);
        }
        // see if the comments has changed
        if (comments != null && updatedProcessGroup.getComments() != null && !comments.equals(updatedProcessGroup.getComments())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("comments");
            configDetails.setValue(updatedProcessGroup.getComments());
            configDetails.setPreviousValue(comments);
            details.add(configDetails);
        }
        // hold all actions
        Collection<Action> actions = new ArrayList<>();
        // save the actions if necessary
        if (!details.isEmpty()) {
            Date timestamp = new Date();
            // create the actions
            for (ActionDetails detail : details) {
                // determine the type of operation being performed
                Operation operation = Operation.Configure;
                if (detail instanceof FlowChangeMoveDetails) {
                    operation = Operation.Move;
                }
                // create the port action for updating the name
                FlowChangeAction processGroupAction = new FlowChangeAction();
                processGroupAction.setUserIdentity(user.getIdentity());
                processGroupAction.setOperation(operation);
                processGroupAction.setTimestamp(timestamp);
                processGroupAction.setSourceId(updatedProcessGroup.getIdentifier());
                processGroupAction.setSourceName(updatedProcessGroup.getName());
                processGroupAction.setSourceType(Component.ProcessGroup);
                processGroupAction.setActionDetails(detail);
                actions.add(processGroupAction);
            }
        }
        // save actions if necessary
        if (!actions.isEmpty()) {
            saveActions(actions, logger);
        }
    }
    return updatedProcessGroup;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ActionDetails(org.apache.nifi.action.details.ActionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)185 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)97 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)68 ProcessorNode (org.apache.nifi.controller.ProcessorNode)50 Port (org.apache.nifi.connectable.Port)40 RootGroupPort (org.apache.nifi.remote.RootGroupPort)37 Connection (org.apache.nifi.connectable.Connection)36 ArrayList (java.util.ArrayList)35 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)35 Test (org.junit.Test)35 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)34 HashSet (java.util.HashSet)32 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)32 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)29 FlowController (org.apache.nifi.controller.FlowController)27 Connectable (org.apache.nifi.connectable.Connectable)26 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)25 Funnel (org.apache.nifi.connectable.Funnel)24 List (java.util.List)22 Label (org.apache.nifi.controller.label.Label)22