tpalfy commented on code in PR #6034:
URL: https://github.com/apache/nifi/pull/6034#discussion_r911044471


##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/ListenTrapSNMP.java:
##########
@@ -99,29 +151,69 @@ public class ListenTrapSNMP extends 
AbstractSessionFactoryProcessor {
     )));
 
     private volatile SNMPTrapReceiverHandler snmpTrapReceiverHandler;
+    private volatile List<UsmUser> usmUsers;
+
+
+    @Override
+    public List<ConfigVerificationResult> verify(ProcessContext context, 
ComponentLog verificationLogger, Map<String, String> attributes) {
+        final List<ConfigVerificationResult> results = new ArrayList<>();
+
+        final String usmUserSource = 
context.getProperty(SNMP_USM_USER_SOURCE).getValue();
+
+        if (usmUserSource != null) {
+            final String usmUsersJsonFilePath = 
context.getProperty(SNMP_USM_USERS_JSON_FILE_PATH).getValue();
+            final String usmUsersJson = 
context.getProperty(SNMP_USM_USERS_JSON).getValue();
+            final String usmSecurityNames = 
context.getProperty(SNMP_USM_SECURITY_NAMES).getValue();
+
+            UsmReader usmReader = null;
+
+            if (USM_JSON_FILE_PATH.getValue().equals(usmUserSource)) {
+                usmReader = new JsonFileUsmReader(usmUsersJsonFilePath);
+            } else if (USM_JSON_CONTENT.getValue().equals(usmUserSource)) {
+                usmReader = new JsonUsmReader(usmUsersJson);
+            } else if (USM_SECURITY_NAMES.getValue().equals(usmUserSource)) {
+                usmReader = new SecurityNamesUsmReader(usmSecurityNames);
+            }
+
+            try {
+                if (usmReader != null) {
+                    usmUsers = usmReader.readUsm();

Review Comment:
   I see the check for the USM users parsing is moved from the `customValidate` 
to `verify` which is good.
   However the `setting of the state`  (i.e. `usmUsers =`) should not be done 
here as well.
   
   `Verify` may not be called by the user before using the processor nor after 
changing any configuration.
   
   The state should be set in the `@OnScheduled` instead.



##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/utils/UsmJsonParser.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.snmp.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.snmp4j.security.UsmUser;
+
+import java.util.List;
+
+public class UsmJsonParser {
+
+    static List<UsmUser> parse(final String json) throws 
JsonProcessingException {
+        ObjectMapper mapper = new ObjectMapper();
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(UsmUser.class, new UsmUserDeserializer());

Review Comment:
   `ObjectMapper` is thread safe, we could extract this into a static constant. 



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to