emiliosetiadarma commented on code in PR #6054:
URL: https://github.com/apache/nifi/pull/6054#discussion_r876445911


##########
nifi-commons/nifi-flow-encryptor/src/main/java/org/apache/nifi/flow/encryptor/JsonFlowEncryptor.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.flow.encryptor;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.encrypt.PropertyEncryptor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class JsonFlowEncryptor implements FlowEncryptor {
+    private static final Pattern ENCRYPTED_PATTERN = 
Pattern.compile("enc\\{([^\\}]+?)\\}");
+
+    private static final int FIRST_GROUP = 1;
+
+    private static final String ENCRYPTED_FORMAT = "enc{%s}";
+
+
+    @Override
+    public void processFlow(InputStream inputStream, OutputStream 
outputStream, PropertyEncryptor inputEncryptor, PropertyEncryptor 
outputEncryptor) {
+        final JsonFactory factory = new JsonFactory();
+        try (final JsonGenerator generator = 
factory.createGenerator(outputStream)){
+            try (final JsonParser parser = factory.createParser(inputStream)) {
+                parser.setCodec(new ObjectMapper());
+                processJsonByTokens(parser, generator, inputEncryptor, 
outputEncryptor);
+            }
+        } catch (IOException e) {
+            throw new UncheckedIOException("Failed Processing Flow 
Configuration", e);
+        }
+    }
+
+    private void processJsonByTokens(final JsonParser parser, final 
JsonGenerator generator,
+                                     final PropertyEncryptor inputEncryptor, 
final PropertyEncryptor outputEncryptor) throws IOException {
+        while (true) {
+            final JsonToken token = parser.nextToken();
+            if (token == null) {
+                return;
+            }

Review Comment:
   That will do the same thing, making the changes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to