org.apache.nifi.encrypt.StringEncryptor Java Examples
The following examples show how to use
org.apache.nifi.encrypt.StringEncryptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PopularVoteFlowElectionFactoryBean.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public PopularVoteFlowElection getObject() throws Exception { final String maxWaitTime = properties.getFlowElectionMaxWaitTime(); long maxWaitMillis; try { maxWaitMillis = FormatUtils.getTimeDuration(maxWaitTime, TimeUnit.MILLISECONDS); } catch (final Exception e) { logger.warn("Failed to parse value of property '{}' as a valid time period. Value was '{}'. Ignoring this value and using the default value of '{}'", NiFiProperties.FLOW_ELECTION_MAX_WAIT_TIME, maxWaitTime, NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME); maxWaitMillis = FormatUtils.getTimeDuration(NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME, TimeUnit.MILLISECONDS); } final Integer maxNodes = properties.getFlowElectionMaxCandidates(); final StringEncryptor encryptor = StringEncryptor.createEncryptor(properties); final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor); return new PopularVoteFlowElection(maxWaitMillis, TimeUnit.MILLISECONDS, maxNodes, fingerprintFactory); }
Example #2
Source File: ControllerServiceLoader.java From nifi with Apache License 2.0 | 6 votes |
private static ControllerServiceNode createControllerService(final FlowController flowController, final Element controllerServiceElement, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) { final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor, encodingVersion); BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(flowController.getExtensionManager(), dto.getType(), dto.getBundle()); } catch (final IllegalStateException e) { final BundleDTO bundleDTO = dto.getBundle(); if (bundleDTO == null) { coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion()); } } final ControllerServiceNode node = flowController.getFlowManager().createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false, true); node.setName(dto.getName()); node.setComments(dto.getComments()); node.setVersionedComponentId(dto.getVersionedComponentId()); return node; }
Example #3
Source File: ControllerServiceLoader.java From nifi with Apache License 2.0 | 6 votes |
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller, final ProcessGroup parentGroup, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) { final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>(); for (final Element serviceElement : serviceElements) { final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor, encodingVersion); if (parentGroup == null) { controller.getFlowManager().addRootControllerService(serviceNode); } else { parentGroup.addControllerService(serviceNode); } // We need to clone the node because it will be used in a separate thread below, and // Element is not thread-safe. nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true)); } for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) { configureControllerService(entry.getKey(), entry.getValue(), encryptor, encodingVersion); } return nodeMap; }
Example #4
Source File: FlowFromDOMFactory.java From localization_nifi with Apache License 2.0 | 6 votes |
public static RemoteProcessGroupDTO getRemoteProcessGroup(final Element element, final StringEncryptor encryptor) { final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setTargetUri(getString(element, "url")); dto.setTargetUris(getString(element, "urls")); dto.setTransmitting(getBoolean(element, "transmitting")); dto.setPosition(getPosition(DomUtils.getChild(element, "position"))); dto.setCommunicationsTimeout(getString(element, "timeout")); dto.setComments(getString(element, "comment")); dto.setYieldDuration(getString(element, "yieldPeriod")); dto.setTransportProtocol(getString(element, "transportProtocol")); dto.setProxyHost(getString(element, "proxyHost")); dto.setProxyPort(getOptionalInt(element, "proxyPort")); dto.setProxyUser(getString(element, "proxyUser")); dto.setLocalNetworkInterface(getString(element, "networkInterface")); final String rawPassword = getString(element, "proxyPassword"); final String proxyPassword = encryptor == null ? rawPassword : decrypt(rawPassword, encryptor); dto.setProxyPassword(proxyPassword); return dto; }
Example #5
Source File: ConnectableTask.java From nifi with Apache License 2.0 | 6 votes |
public ConnectableTask(final SchedulingAgent schedulingAgent, final Connectable connectable, final FlowController flowController, final RepositoryContextFactory contextFactory, final LifecycleState scheduleState, final StringEncryptor encryptor) { this.schedulingAgent = schedulingAgent; this.connectable = connectable; this.scheduleState = scheduleState; this.numRelationships = connectable.getRelationships().size(); this.flowController = flowController; final StateManager stateManager = new TaskTerminationAwareStateManager(flowController.getStateManagerProvider().getStateManager(connectable.getIdentifier()), scheduleState::isTerminated); if (connectable instanceof ProcessorNode) { processContext = new StandardProcessContext((ProcessorNode) connectable, flowController.getControllerServiceProvider(), encryptor, stateManager, scheduleState::isTerminated); } else { processContext = new ConnectableProcessContext(connectable, encryptor, stateManager); } repositoryContext = contextFactory.newProcessContext(connectable, new AtomicLong(0L)); }
Example #6
Source File: FlowFromDOMFactory.java From localization_nifi with Apache License 2.0 | 6 votes |
public static ControllerServiceDTO getControllerService(final Element element, final StringEncryptor encryptor) { final ControllerServiceDTO dto = new ControllerServiceDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setComments(getString(element, "comment")); dto.setType(getString(element, "class")); final boolean enabled = getBoolean(element, "enabled"); dto.setState(enabled ? ControllerServiceState.ENABLED.name() : ControllerServiceState.DISABLED.name()); dto.setProperties(getProperties(element, encryptor)); dto.setAnnotationData(getString(element, "annotationData")); return dto; }
Example #7
Source File: StandardXMLFlowConfigurationDAO.java From localization_nifi with Apache License 2.0 | 6 votes |
public StandardXMLFlowConfigurationDAO(final Path flowXml, final StringEncryptor encryptor, final NiFiProperties nifiProperties) throws IOException { this.nifiProperties = nifiProperties; final File flowXmlFile = flowXml.toFile(); if (!flowXmlFile.exists()) { // createDirectories would throw an exception if the directory exists but is a symbolic link if (Files.notExists(flowXml.getParent())) { Files.createDirectories(flowXml.getParent()); } Files.createFile(flowXml); //TODO: find a better solution. With Windows 7 and Java 7, Files.isWritable(source.getParent()) returns false, even when it should be true. } else if (!flowXmlFile.canRead() || !flowXmlFile.canWrite()) { throw new IOException(flowXml + " exists but you have insufficient read/write privileges"); } this.flowXmlPath = flowXml; this.encryptor = encryptor; this.archiveManager = new FlowConfigurationArchiveManager(flowXmlPath, nifiProperties); }
Example #8
Source File: StandardProcessContext.java From nifi with Apache License 2.0 | 6 votes |
public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final StringEncryptor encryptor, final StateManager stateManager, final TaskTermination taskTermination) { this.procNode = processorNode; this.controllerServiceProvider = controllerServiceProvider; this.encryptor = encryptor; this.stateManager = stateManager; this.taskTermination = taskTermination; properties = Collections.unmodifiableMap(processorNode.getEffectivePropertyValues()); preparedQueries = new HashMap<>(); for (final Map.Entry<PropertyDescriptor, String> entry : processorNode.getRawPropertyValues().entrySet()) { final PropertyDescriptor desc = entry.getKey(); String value = entry.getValue(); if (value == null) { value = desc.getDefaultValue(); } if (value != null) { final PreparedQuery pq = Query.prepare(value); preparedQueries.put(desc, pq); } } }
Example #9
Source File: Cluster.java From localization_nifi with Apache License 2.0 | 6 votes |
public Node createNode() { final Map<String, String> addProps = new HashMap<>(); addProps.put(NiFiProperties.ZOOKEEPER_CONNECT_STRING, getZooKeeperConnectString()); addProps.put(NiFiProperties.CLUSTER_IS_NODE, "true"); final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", addProps); final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(nifiProperties)); final FlowElection flowElection = new PopularVoteFlowElection(flowElectionTimeoutMillis, TimeUnit.MILLISECONDS, flowElectionMaxNodes, fingerprintFactory); final Node node = new Node(nifiProperties, flowElection); node.start(); nodes.add(node); return node; }
Example #10
Source File: FlowFromDOMFactory.java From localization_nifi with Apache License 2.0 | 6 votes |
public static ReportingTaskDTO getReportingTask(final Element element, final StringEncryptor encryptor) { final ReportingTaskDTO dto = new ReportingTaskDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setComments(getString(element, "comment")); dto.setType(getString(element, "class")); dto.setSchedulingPeriod(getString(element, "schedulingPeriod")); dto.setState(getString(element, "scheduledState")); dto.setSchedulingStrategy(getString(element, "schedulingStrategy")); dto.setProperties(getProperties(element, encryptor)); dto.setAnnotationData(getString(element, "annotationData")); return dto; }
Example #11
Source File: EventDrivenSchedulingAgent.java From nifi with Apache License 2.0 | 6 votes |
public EventDrivenSchedulingAgent(final FlowEngine flowEngine, final ControllerServiceProvider serviceProvider, final StateManagerProvider stateManagerProvider, final EventDrivenWorkerQueue workerQueue, final RepositoryContextFactory contextFactory, final int maxThreadCount, final StringEncryptor encryptor, final ExtensionManager extensionManager) { super(flowEngine); this.serviceProvider = serviceProvider; this.stateManagerProvider = stateManagerProvider; this.workerQueue = workerQueue; this.contextFactory = contextFactory; this.maxThreadCount = new AtomicInteger(maxThreadCount); this.encryptor = encryptor; this.extensionManager = extensionManager; for (int i = 0; i < maxThreadCount; i++) { final Runnable eventDrivenTask = new EventDrivenTask(workerQueue, activeThreadCount); flowEngine.scheduleWithFixedDelay(eventDrivenTask, 0L, 1L, TimeUnit.NANOSECONDS); } }
Example #12
Source File: StandardProcessScheduler.java From localization_nifi with Apache License 2.0 | 6 votes |
public StandardProcessScheduler( final ControllerServiceProvider controllerServiceProvider, final StringEncryptor encryptor, final StateManagerProvider stateManagerProvider, final VariableRegistry variableRegistry, final NiFiProperties nifiProperties ) { this.controllerServiceProvider = controllerServiceProvider; this.encryptor = encryptor; this.stateManagerProvider = stateManagerProvider; this.variableRegistry = variableRegistry; administrativeYieldDuration = nifiProperties.getAdministrativeYieldDuration(); administrativeYieldMillis = FormatUtils.getTimeDuration(administrativeYieldDuration, TimeUnit.MILLISECONDS); frameworkTaskExecutor = new FlowEngine(4, "Framework Task Thread"); }
Example #13
Source File: EventDrivenSchedulingAgent.java From localization_nifi with Apache License 2.0 | 6 votes |
public EventDrivenSchedulingAgent(final FlowEngine flowEngine, final ControllerServiceProvider serviceProvider, final StateManagerProvider stateManagerProvider, final EventDrivenWorkerQueue workerQueue, final ProcessContextFactory contextFactory, final int maxThreadCount, final StringEncryptor encryptor, final VariableRegistry variableRegistry) { super(flowEngine); this.serviceProvider = serviceProvider; this.stateManagerProvider = stateManagerProvider; this.workerQueue = workerQueue; this.contextFactory = contextFactory; this.maxThreadCount = new AtomicInteger(maxThreadCount); this.encryptor = encryptor; this.variableRegistry = variableRegistry; for (int i = 0; i < maxThreadCount; i++) { final Runnable eventDrivenTask = new EventDrivenTask(workerQueue); flowEngine.scheduleWithFixedDelay(eventDrivenTask, 0L, 1L, TimeUnit.NANOSECONDS); } }
Example #14
Source File: TimerDrivenSchedulingAgent.java From localization_nifi with Apache License 2.0 | 6 votes |
public TimerDrivenSchedulingAgent( final FlowController flowController, final FlowEngine flowEngine, final ProcessContextFactory contextFactory, final StringEncryptor encryptor, final VariableRegistry variableRegistry, final NiFiProperties nifiProperties) { super(flowEngine); this.flowController = flowController; this.contextFactory = contextFactory; this.encryptor = encryptor; this.variableRegistry = variableRegistry; final String boredYieldDuration = nifiProperties.getBoredYieldDuration(); try { noWorkYieldNanos = FormatUtils.getTimeDuration(boredYieldDuration, TimeUnit.NANOSECONDS); } catch (final IllegalArgumentException e) { throw new RuntimeException("Failed to create SchedulingAgent because the " + NiFiProperties.BORED_YIELD_DURATION + " property is set to an invalid time duration: " + boredYieldDuration); } }
Example #15
Source File: Cluster.java From nifi with Apache License 2.0 | 6 votes |
public Node createNode() { final Map<String, String> addProps = new HashMap<>(); addProps.put(NiFiProperties.ZOOKEEPER_CONNECT_STRING, getZooKeeperConnectString()); addProps.put(NiFiProperties.CLUSTER_IS_NODE, "true"); final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", addProps); final String algorithm = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM); final String provider = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_PROVIDER); final String password = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY); final StringEncryptor encryptor = StringEncryptor.createEncryptor(algorithm, provider, password); final ExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager(); final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor, extensionManager); final FlowElection flowElection = new PopularVoteFlowElection(flowElectionTimeoutMillis, TimeUnit.MILLISECONDS, flowElectionMaxNodes, fingerprintFactory); final Node node = new Node(nifiProperties, extensionManager, flowElection); node.start(); nodes.add(node); return node; }
Example #16
Source File: TestConnectableTask.java From nifi with Apache License 2.0 | 6 votes |
private ConnectableTask createTask(final Connectable connectable) { final FlowController flowController = Mockito.mock(FlowController.class); Mockito.when(flowController.getStateManagerProvider()).thenReturn(Mockito.mock(StateManagerProvider.class)); final RepositoryContext repoContext = Mockito.mock(RepositoryContext.class); Mockito.when(repoContext.getFlowFileEventRepository()).thenReturn(Mockito.mock(FlowFileEventRepository.class)); final RepositoryContextFactory contextFactory = Mockito.mock(RepositoryContextFactory.class); Mockito.when(contextFactory.newProcessContext(Mockito.any(Connectable.class), Mockito.any(AtomicLong.class))).thenReturn(repoContext); final LifecycleState scheduleState = new LifecycleState(); final StringEncryptor encryptor = Mockito.mock(StringEncryptor.class); return new ConnectableTask(Mockito.mock(SchedulingAgent.class), connectable, flowController, contextFactory, scheduleState, encryptor); }
Example #17
Source File: StandardProcessContext.java From localization_nifi with Apache License 2.0 | 6 votes |
public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final StringEncryptor encryptor, final StateManager stateManager, final VariableRegistry variableRegistry) { this.procNode = processorNode; this.controllerServiceProvider = controllerServiceProvider; this.encryptor = encryptor; this.stateManager = stateManager; this.variableRegistry = variableRegistry; preparedQueries = new HashMap<>(); for (final Map.Entry<PropertyDescriptor, String> entry : procNode.getProperties().entrySet()) { final PropertyDescriptor desc = entry.getKey(); String value = entry.getValue(); if (value == null) { value = desc.getDefaultValue(); } if (value != null) { final PreparedQuery pq = Query.prepare(value); preparedQueries.put(desc, pq); } } }
Example #18
Source File: FlowFromDOMFactory.java From nifi with Apache License 2.0 | 6 votes |
public static ReportingTaskDTO getReportingTask(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) { final ReportingTaskDTO dto = new ReportingTaskDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setComments(getString(element, "comment")); dto.setType(getString(element, "class")); dto.setBundle(getBundle(DomUtils.getChild(element, "bundle"))); dto.setSchedulingPeriod(getString(element, "schedulingPeriod")); dto.setState(getString(element, "scheduledState")); dto.setSchedulingStrategy(getString(element, "schedulingStrategy")); dto.setProperties(getProperties(element, encryptor, flowEncodingVersion)); dto.setAnnotationData(getString(element, "annotationData")); return dto; }
Example #19
Source File: FlowFromDOMFactory.java From nifi with Apache License 2.0 | 6 votes |
public static RemoteProcessGroupDTO getRemoteProcessGroup(final Element element, final StringEncryptor encryptor) { final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO(); dto.setId(getString(element, "id")); dto.setVersionedComponentId(getString(element, "versionedComponentId")); dto.setName(getString(element, "name")); dto.setTargetUri(getString(element, "url")); dto.setTargetUris(getString(element, "urls")); dto.setTransmitting(getBoolean(element, "transmitting")); dto.setPosition(getPosition(DomUtils.getChild(element, "position"))); dto.setCommunicationsTimeout(getString(element, "timeout")); dto.setComments(getString(element, "comment")); dto.setYieldDuration(getString(element, "yieldPeriod")); dto.setTransportProtocol(getString(element, "transportProtocol")); dto.setProxyHost(getString(element, "proxyHost")); dto.setProxyPort(getOptionalInt(element, "proxyPort")); dto.setProxyUser(getString(element, "proxyUser")); dto.setLocalNetworkInterface(getString(element, "networkInterface")); final String rawPassword = getString(element, "proxyPassword"); final String proxyPassword = encryptor == null ? rawPassword : decrypt(rawPassword, encryptor); dto.setProxyPassword(proxyPassword); return dto; }
Example #20
Source File: FlowController.java From localization_nifi with Apache License 2.0 | 6 votes |
public static FlowController createStandaloneInstance( final FlowFileEventRepository flowFileEventRepo, final NiFiProperties properties, final Authorizer authorizer, final AuditService auditService, final StringEncryptor encryptor, final BulletinRepository bulletinRepo, final VariableRegistry variableRegistry) { return new FlowController( flowFileEventRepo, properties, authorizer, auditService, encryptor, /* configuredForClustering */ false, /* NodeProtocolSender */ null, bulletinRepo, /* cluster coordinator */ null, /* heartbeat monitor */ null, /* leader election manager */ null, /* variable registry */ variableRegistry); }
Example #21
Source File: FlowFromDOMFactory.java From nifi with Apache License 2.0 | 6 votes |
private static LinkedHashMap<String, String> getProperties(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) { final LinkedHashMap<String, String> properties = new LinkedHashMap<>(); final List<Element> propertyNodeList = getChildrenByTagName(element, "property"); final ParameterParser parameterParser = new ExpressionLanguageAwareParameterParser(); for (final Element propertyElement : propertyNodeList) { final String name = getString(propertyElement, "name"); final String rawPropertyValue = getString(propertyElement, "value"); final String value = encryptor == null ? rawPropertyValue : decrypt(rawPropertyValue, encryptor); if (flowEncodingVersion == null || (flowEncodingVersion.getMajorVersion() <= 1 && flowEncodingVersion.getMinorVersion() < 4)) { // Version 1.4 introduced the #{paramName} syntax for referencing parameters. If the version is less than 1.4, we must escpae any // #{...} reference that we find. final ParameterTokenList parameterTokenList = parameterParser.parseTokens(value); final String escaped = parameterTokenList.escape(); properties.put(name, escaped); } else { properties.put(name, value); } } return properties; }
Example #22
Source File: ControllerServiceLoader.java From localization_nifi with Apache License 2.0 | 6 votes |
public static void enableControllerServices(final Map<ControllerServiceNode, Element> nodeMap, final FlowController controller, final StringEncryptor encryptor, final boolean autoResumeState) { // Start services if (autoResumeState) { final Set<ControllerServiceNode> nodesToEnable = new HashSet<>(); for (final ControllerServiceNode node : nodeMap.keySet()) { final Element controllerServiceElement = nodeMap.get(node); final ControllerServiceDTO dto; synchronized (controllerServiceElement.getOwnerDocument()) { dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor); } final ControllerServiceState state = ControllerServiceState.valueOf(dto.getState()); if (state == ControllerServiceState.ENABLED) { nodesToEnable.add(node); } } enableControllerServices(nodesToEnable, controller, autoResumeState); } }
Example #23
Source File: ControllerServiceLoader.java From localization_nifi with Apache License 2.0 | 6 votes |
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller, final ProcessGroup parentGroup, final StringEncryptor encryptor) { final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>(); for (final Element serviceElement : serviceElements) { final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor); if (parentGroup == null) { controller.addRootControllerService(serviceNode); } else { parentGroup.addControllerService(serviceNode); } // We need to clone the node because it will be used in a separate thread below, and // Element is not thread-safe. nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true)); } for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) { configureControllerService(entry.getKey(), entry.getValue(), encryptor); } return nodeMap; }
Example #24
Source File: StandardFlowSerializer.java From nifi with Apache License 2.0 | 6 votes |
public static void addReportingTask(final Element element, final ReportingTaskNode taskNode, final StringEncryptor encryptor) { final Element taskElement = element.getOwnerDocument().createElement("reportingTask"); addTextElement(taskElement, "id", taskNode.getIdentifier()); addTextElement(taskElement, "name", taskNode.getName()); addTextElement(taskElement, "comment", taskNode.getComments()); addTextElement(taskElement, "class", taskNode.getCanonicalClassName()); addBundle(taskElement, taskNode.getBundleCoordinate()); addTextElement(taskElement, "schedulingPeriod", taskNode.getSchedulingPeriod()); addTextElement(taskElement, "scheduledState", taskNode.getScheduledState().name()); addTextElement(taskElement, "schedulingStrategy", taskNode.getSchedulingStrategy().name()); addConfiguration(taskElement, taskNode.getRawPropertyValues(), taskNode.getAnnotationData(), encryptor); element.appendChild(taskElement); }
Example #25
Source File: StandardFlowSerializerTest.java From nifi with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { final FlowFileEventRepository flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class); final AuditService auditService = Mockito.mock(AuditService.class); final Map<String, String> otherProps = new HashMap<>(); otherProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName()); otherProps.put("nifi.remote.input.socket.port", ""); otherProps.put("nifi.remote.input.secure", ""); final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, otherProps); final String algorithm = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM); final String provider = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_PROVIDER); final String password = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY); final StringEncryptor encryptor = StringEncryptor.createEncryptor(algorithm, provider, password); // use the system bundle systemBundle = SystemBundle.create(nifiProperties); extensionManager = new StandardExtensionDiscoveringManager(); extensionManager.discoverExtensions(systemBundle, Collections.emptySet()); final AbstractPolicyBasedAuthorizer authorizer = new MockPolicyBasedAuthorizer(); final VariableRegistry variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()); final BulletinRepository bulletinRepo = Mockito.mock(BulletinRepository.class); controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer, auditService, encryptor, bulletinRepo, variableRegistry, Mockito.mock(FlowRegistryClient.class), extensionManager); serializer = new StandardFlowSerializer(encryptor); }
Example #26
Source File: FlowFromDOMFactory.java From nifi with Apache License 2.0 | 5 votes |
public static ParameterContextDTO getParameterContext(final Element element, final StringEncryptor encryptor) { final ParameterContextDTO dto = new ParameterContextDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setDescription(getString(element, "description")); final Set<ParameterEntity> parameterDtos = new LinkedHashSet<>(); final List<Element> parameterElements = FlowFromDOMFactory.getChildrenByTagName(element, "parameter"); for (final Element parameterElement : parameterElements) { final ParameterDTO parameterDto = new ParameterDTO(); parameterDto.setName(getString(parameterElement, "name")); parameterDto.setDescription(getString(parameterElement, "description")); parameterDto.setSensitive(getBoolean(parameterElement, "sensitive")); final String value = decrypt(getString(parameterElement, "value"), encryptor); parameterDto.setValue(value); final ParameterEntity parameterEntity = new ParameterEntity(); parameterEntity.setParameter(parameterDto); parameterDtos.add(parameterEntity); } dto.setParameters(parameterDtos); return dto; }
Example #27
Source File: StandardFlowService.java From nifi with Apache License 2.0 | 5 votes |
public static StandardFlowService createStandaloneInstance( final FlowController controller, final NiFiProperties nifiProperties, final StringEncryptor encryptor, final RevisionManager revisionManager, final Authorizer authorizer) throws IOException { return new StandardFlowService(controller, nifiProperties, null, encryptor, false, null, revisionManager, authorizer); }
Example #28
Source File: JoinClusterWithDifferentFlow.java From nifi with Apache License 2.0 | 5 votes |
private void verifyFlowContentsOnDisk(final File backupFile) throws IOException, SAXException, ParserConfigurationException { // Read the flow and make sure that the backup looks the same as the original. We don't just do a byte comparison because the compression may result in different // gzipped bytes and because if the two flows do differ, we want to have the String representation so that we can compare to see how they are different. final String flowXml = readFlow(backupFile); final String expectedFlow = readFlow(new File("src/test/resources/flows/mismatched-flows/flow2.xml.gz")); assertEquals(expectedFlow, flowXml); // Verify some of the values that were persisted to disk final File confDir = backupFile.getParentFile(); final String loadedFlow = readFlow(new File(confDir, "flow.xml.gz")); final DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document document = documentBuilder.parse(new InputSource(new StringReader(loadedFlow))); final Element rootElement = (Element) document.getElementsByTagName("flowController").item(0); final FlowEncodingVersion encodingVersion = FlowEncodingVersion.parse(rootElement); final NiFiInstance node2 = getNiFiInstance().getNodeInstance(2); final StringEncryptor encryptor = createEncryptorFromProperties(node2.getProperties()); final Element rootGroupElement = (Element) rootElement.getElementsByTagName("rootGroup").item(0); final ProcessGroupDTO groupDto = FlowFromDOMFactory.getProcessGroup(null, rootGroupElement, encryptor, encodingVersion); final Set<ProcessGroupDTO> childGroupDtos = groupDto.getContents().getProcessGroups(); assertEquals(1, childGroupDtos.size()); final ProcessGroupDTO childGroup = childGroupDtos.iterator().next(); assertFalse(childGroup.getId().endsWith("00")); final FlowSnippetDTO childContents = childGroup.getContents(); final Set<ProcessorDTO> childProcessors = childContents.getProcessors(); assertEquals(1, childProcessors.size()); final ProcessorDTO procDto = childProcessors.iterator().next(); assertFalse(procDto.getId().endsWith("00")); assertFalse(procDto.getName().endsWith("00")); }
Example #29
Source File: TestPopularVoteFlowElection.java From nifi with Apache License 2.0 | 5 votes |
private NiFiProperties getNiFiProperties() { final NiFiProperties nifiProperties = mock(NiFiProperties.class); when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM)).thenReturn("PBEWITHMD5AND256BITAES-CBC-OPENSSL"); when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER)).thenReturn("BC"); when(nifiProperties.getProperty(anyString(), anyString())).then(invocation -> invocation.getArgument(1)); return nifiProperties; }
Example #30
Source File: TestPopularVoteFlowElection.java From nifi with Apache License 2.0 | 5 votes |
/** * Utility method which accepts {@link NiFiProperties} object but calls {@link StringEncryptor#createEncryptor(String, String, String)} with extracted properties. * * @param nifiProperties the NiFiProperties object * @return the StringEncryptor */ private StringEncryptor createEncryptorFromProperties(NiFiProperties nifiProperties) { final String algorithm = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM); final String provider = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_PROVIDER); final String password = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY, "nififtw!"); return StringEncryptor.createEncryptor(algorithm, provider, password); }