bbende commented on a change in pull request #5277:
URL: https://github.com/apache/nifi/pull/5277#discussion_r691329560



##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
##########
@@ -450,6 +476,36 @@ HdfsResources resetHDFSResources(final List<String> 
resourceLocations, ProcessCo
         return new HdfsResources(config, fs, ugi, kerberosUser);
     }
 
+    private KerberosUser getKerberosUser(final ProcessContext context) throws 
IOException {
+        // Check Kerberos User Service first, if present then get the 
KerberosUser from the service
+        // The customValidate method ensures that KerberosUserService can't be 
set at the same time as the credentials service or explicit properties
+        final KerberosUserService kerberosUserService = 
context.getProperty(KERBEROS_USER_SERVICE).asControllerService(KerberosUserService.class);
+        if (kerberosUserService != null) {
+            return kerberosUserService.createKerberosUser();
+        }
+
+        // Kerberos User Service wasn't set, so create KerberosUser based on 
credentials service or explicit properties...
+        String principal = 
context.getProperty(kerberosProperties.getKerberosPrincipal()).evaluateAttributeExpressions().getValue();
+        String keyTab = 
context.getProperty(kerberosProperties.getKerberosKeytab()).evaluateAttributeExpressions().getValue();
+        String password = 
context.getProperty(kerberosProperties.getKerberosPassword()).getValue();
+
+        // If the Kerberos Credentials Service is specified, we need to use 
its configuration, not the explicit properties for principal/keytab.
+        // The customValidate method ensures that only one can be set, so we 
know that the principal & keytab above are null.
+        final KerberosCredentialsService credentialsService = 
context.getProperty(KERBEROS_CREDENTIALS_SERVICE).asControllerService(KerberosCredentialsService.class);
+        if (credentialsService != null) {
+            principal = credentialsService.getPrincipal();
+            keyTab = credentialsService.getKeytab();
+        }
+
+        if (keyTab != null) {
+            return new KerberosKeytabUser(principal, keyTab);
+        } else if (password != null) {
+            return new KerberosPasswordUser(principal, password);
+        } else {
+            throw new IOException("Unable to authenticate with Kerberos, no 
keytab or password was provided");

Review comment:
       At first I was hesitant to change this due to being unsure about 
existing exception handling, but it seems like the code path originates from 
the onScheduled method, so I think it is fair to change it. I'm fine with 
IllegalArgumentException, or would IllegalStateException make sense since it is 
really an unexpected situation to end up in this state? There should really be 
no way for this exception to happen with all of the validation that exists.




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