exceptionfactory commented on a change in pull request #4709:
URL: https://github.com/apache/nifi/pull/4709#discussion_r568006661



##########
File path: 
nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/util/CertificateUtils.java
##########
@@ -469,6 +472,12 @@ public static X509Certificate 
generateSelfSignedX509Certificate(KeyPair keyPair,
             // (2) extendedKeyUsage extension
             certBuilder.addExtension(Extension.extendedKeyUsage, false, new 
ExtendedKeyUsage(new KeyPurposeId[]{KeyPurposeId.id_kp_clientAuth, 
KeyPurposeId.id_kp_serverAuth}));
 
+            // (3) subjectAlternativeName extension. Include CN as a SAN entry 
if it exists.
+            final String cn = getCommonName(dn);
+            if(cn != null) {

Review comment:
       Recommend adjusting this check to use `StringUtils.isNotBlank()` and 
adding a space after `if`:
   ```suggestion
               if (StringUtils.isNotBlank(cn)) {
   ```

##########
File path: 
nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/util/CertificateUtils.java
##########
@@ -625,6 +634,20 @@ public static boolean isTlsError(Throwable e) {
         }
     }
 
+    /**
+     *Extracts the common name from the given DN.

Review comment:
       Recommend adding a space after the asterisk to improve readability.
   ```suggestion
        * Extracts the common name from the given DN.
   ```

##########
File path: 
nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/util/CertificateUtils.java
##########
@@ -625,6 +634,20 @@ public static boolean isTlsError(Throwable e) {
         }
     }
 
+    /**
+     *Extracts the common name from the given DN.
+     *
+     * @param dn the distinguished name to evaluate
+     * @return the common name if it exists, null otherwise.
+     */
+    public static String getCommonName(String dn){

Review comment:
       Recommend declaring the parameter as `final`:
   ```suggestion
       public static String getCommonName(final String dn) {
   ```

##########
File path: 
nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/util/CertificateUtils.java
##########
@@ -625,6 +634,20 @@ public static boolean isTlsError(Throwable e) {
         }
     }
 
+    /**
+     *Extracts the common name from the given DN.
+     *
+     * @param dn the distinguished name to evaluate
+     * @return the common name if it exists, null otherwise.
+     */
+    public static String getCommonName(String dn){
+        RDN[] rdns = new X500Name(dn).getRDNs(BCStyle.CN);
+        if(rdns.length == 0) {

Review comment:
       Recommend adding a space after the `if`:
   ```suggestion
           if (rdns.length == 0) {
   ```




----------------------------------------------------------------
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.

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


Reply via email to