@Test public void testSearchInThirdLevelParentNotAuthorizedWithVersionControlInTheGroup() { final ProcessGroup rootProcessGroup = setupMockedProcessGroup("root", null, true, variableRegistry, null); final ProcessGroup firstLevelAProcessGroup = setupMockedProcessGroup("firstLevelA", rootProcessGroup, true, variableRegistry, null); final ProcessGroup firstLevelBProcessGroup = setupMockedProcessGroup("firstLevelB", rootProcessGroup, true, variableRegistry, null); final ProcessGroup secondLevelAProcessGroup = setupMockedProcessGroup("secondLevelA", firstLevelAProcessGroup, true, variableRegistry, null); final ProcessGroup secondLevelBProcessGroup = setupMockedProcessGroup("secondLevelB", firstLevelBProcessGroup, true, variableRegistry, null); final VersionControlInformation versionControlInformation = setupVC(); final ProcessGroup thirdLevelAProcessGroup = setupMockedProcessGroup("thirdLevelA", secondLevelAProcessGroup, false, variableRegistry, versionControlInformation); final ProcessGroup thirdLevelBProcessGroup = setupMockedProcessGroup("thirdLevelB", secondLevelAProcessGroup, false, variableRegistry, null); Mockito.doReturn(new HashSet<ProcessGroup>() { { add(firstLevelAProcessGroup); add(firstLevelBProcessGroup); } }).when(rootProcessGroup).getProcessGroups(); Mockito.doReturn(new HashSet<ProcessGroup>() { { add(secondLevelAProcessGroup); } }).when(firstLevelAProcessGroup).getProcessGroups(); Mockito.doReturn(new HashSet<ProcessGroup>() { { add(secondLevelBProcessGroup); } }).when(firstLevelBProcessGroup).getProcessGroups(); Mockito.doReturn(new HashSet<ProcessGroup>() { { add(thirdLevelAProcessGroup); add(thirdLevelBProcessGroup); } }).when(secondLevelAProcessGroup).getProcessGroups(); setupMockedProcessor("foobar", thirdLevelAProcessGroup, true, variableRegistry); service.search(searchResultsDTO, "foo", rootProcessGroup); assertTrue(searchResultsDTO.getProcessorResults().size() == 1); assertTrue(searchResultsDTO.getProcessorResults().get(0).getId().equals("foobarId")); assertTrue(searchResultsDTO.getProcessorResults().get(0).getParentGroup().getId().equals("thirdLevelAId")); assertTrue(searchResultsDTO.getProcessorResults().get(0).getParentGroup().getName() == null); assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup() != null); assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup().getId().equals("thirdLevelAId")); assertTrue(searchResultsDTO.getProcessorResults().get(0).getVersionedGroup().getName() == null); }
public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (group.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO groupMatch = search(search, group); if (groupMatch != null) { groupMatch.setParentGroup(buildResultGroup(group.getParent(), user)); groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user)); results.getProcessGroupResults().add(groupMatch); } } for (final ProcessorNode procNode : group.getProcessors()) { if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, procNode); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getProcessorResults().add(match); } } } for (final Connection connection : group.getConnections()) { if (connection.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, connection); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getConnectionResults().add(match); } } } for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) { if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, remoteGroup); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getRemoteProcessGroupResults().add(match); } } } for (final Port port : group.getInputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getInputPortResults().add(match); } } } for (final Port port : group.getOutputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getOutputPortResults().add(match); } } } for (final Funnel funnel : group.getFunnels()) { if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, funnel); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getFunnelResults().add(match); } } } for (final ProcessGroup processGroup : group.getProcessGroups()) { search(results, search, processGroup); } }
ControllerSearchService { public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (group.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO groupMatch = search(search, group); if (groupMatch != null) { groupMatch.setParentGroup(buildResultGroup(group.getParent(), user)); groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user)); results.getProcessGroupResults().add(groupMatch); } } for (final ProcessorNode procNode : group.getProcessors()) { if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, procNode); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getProcessorResults().add(match); } } } for (final Connection connection : group.getConnections()) { if (connection.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, connection); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getConnectionResults().add(match); } } } for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) { if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, remoteGroup); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getRemoteProcessGroupResults().add(match); } } } for (final Port port : group.getInputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getInputPortResults().add(match); } } } for (final Port port : group.getOutputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getOutputPortResults().add(match); } } } for (final Funnel funnel : group.getFunnels()) { if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, funnel); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getFunnelResults().add(match); } } } for (final ProcessGroup processGroup : group.getProcessGroups()) { search(results, search, processGroup); } } }
ControllerSearchService { public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (group.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO groupMatch = search(search, group); if (groupMatch != null) { groupMatch.setParentGroup(buildResultGroup(group.getParent(), user)); groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user)); results.getProcessGroupResults().add(groupMatch); } } for (final ProcessorNode procNode : group.getProcessors()) { if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, procNode); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getProcessorResults().add(match); } } } for (final Connection connection : group.getConnections()) { if (connection.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, connection); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getConnectionResults().add(match); } } } for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) { if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, remoteGroup); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getRemoteProcessGroupResults().add(match); } } } for (final Port port : group.getInputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getInputPortResults().add(match); } } } for (final Port port : group.getOutputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getOutputPortResults().add(match); } } } for (final Funnel funnel : group.getFunnels()) { if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, funnel); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getFunnelResults().add(match); } } } for (final ProcessGroup processGroup : group.getProcessGroups()) { search(results, search, processGroup); } }  }
ControllerSearchService { public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (group.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO groupMatch = search(search, group); if (groupMatch != null) { groupMatch.setParentGroup(buildResultGroup(group.getParent(), user)); groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user)); results.getProcessGroupResults().add(groupMatch); } } for (final ProcessorNode procNode : group.getProcessors()) { if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, procNode); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getProcessorResults().add(match); } } } for (final Connection connection : group.getConnections()) { if (connection.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, connection); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getConnectionResults().add(match); } } } for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) { if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, remoteGroup); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getRemoteProcessGroupResults().add(match); } } } for (final Port port : group.getInputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getInputPortResults().add(match); } } } for (final Port port : group.getOutputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getOutputPortResults().add(match); } } } for (final Funnel funnel : group.getFunnels()) { if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, funnel); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getFunnelResults().add(match); } } } for (final ProcessGroup processGroup : group.getProcessGroups()) { search(results, search, processGroup); } }  void search(final SearchResultsDTO results, final String search, final ProcessGroup group); void setFlowController(FlowController flowController); void setAuthorizer(Authorizer authorizer); void setVariableRegistry(VariableRegistry variableRegistry); }
ControllerSearchService { public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); if (group.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO groupMatch = search(search, group); if (groupMatch != null) { groupMatch.setParentGroup(buildResultGroup(group.getParent(), user)); groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user)); results.getProcessGroupResults().add(groupMatch); } } for (final ProcessorNode procNode : group.getProcessors()) { if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, procNode); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getProcessorResults().add(match); } } } for (final Connection connection : group.getConnections()) { if (connection.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, connection); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getConnectionResults().add(match); } } } for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) { if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, remoteGroup); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getRemoteProcessGroupResults().add(match); } } } for (final Port port : group.getInputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getInputPortResults().add(match); } } } for (final Port port : group.getOutputPorts()) { if (port.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, port); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getOutputPortResults().add(match); } } } for (final Funnel funnel : group.getFunnels()) { if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) { final ComponentSearchResultDTO match = search(search, funnel); if (match != null) { match.setGroupId(group.getIdentifier()); match.setParentGroup(buildResultGroup(group, user)); match.setVersionedGroup(buildVersionedGroup(group, user)); results.getFunnelResults().add(match); } } } for (final ProcessGroup processGroup : group.getProcessGroups()) { search(results, search, processGroup); } }  void search(final SearchResultsDTO results, final String search, final ProcessGroup group); void setFlowController(FlowController flowController); void setAuthorizer(Authorizer authorizer); void setVariableRegistry(VariableRegistry variableRegistry);  }