You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/10/29 14:33:41 UTC

[GitHub] [nifi] adenes commented on a change in pull request #4629: NIFI-7954 Wrapping HBase_*_ClientService calls in getUgi().doAs()

adenes commented on a change in pull request #4629:
URL: https://github.com/apache/nifi/pull/4629#discussion_r514300383



##########
File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
##########
@@ -141,4 +143,37 @@ public static boolean isSecurityEnabled(final Configuration config) {
         Validate.notNull(config);
         return KERBEROS.equalsIgnoreCase(config.get(HADOOP_SECURITY_AUTHENTICATION));
     }
+
+    public static <T> T callWithUgi(CallableThrowingException<UserGroupInformation, IOException> ugiProvider, CallableThrowingException<T, IOException> function) throws IOException {

Review comment:
       In my opinion passing in a `UserGroupProvider` instance instead of the `ugiProvider` would make no difference from the functionality point of view but it'd simplify the usage/improve the readability.
   
   As for the second parameter I'm not fully sure why we need the `CallableThrowingException` class. For me simple `Callable` seems to be ok too, even though it doesn't specify its exception type, but I don't see the need for that.

##########
File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
##########
@@ -141,4 +143,37 @@ public static boolean isSecurityEnabled(final Configuration config) {
         Validate.notNull(config);
         return KERBEROS.equalsIgnoreCase(config.get(HADOOP_SECURITY_AUTHENTICATION));
     }
+
+    public static <T> T callWithUgi(CallableThrowingException<UserGroupInformation, IOException> ugiProvider, CallableThrowingException<T, IOException> function) throws IOException {
+        try {
+            return ugiProvider.call().doAs((PrivilegedExceptionAction<T>)() -> function.call());

Review comment:
       minor nit: `() -> function.call()` could be replaced with method reference, i.e. `function::call`




----------------------------------------------------------------
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:
users@infra.apache.org