Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21178#discussion_r184626752
  
    --- Diff: 
sql/hive-thriftserver/src/main/java/org/apache/hive/service/auth/HiveAuthFactory.java
 ---
    @@ -362,4 +371,34 @@ public static void verifyProxyAccess(String realUser, 
String proxyUser, String i
         }
       }
     
    +  public static boolean needUgiLogin(UserGroupInformation ugi, String 
principal, String keytab) {
    +    return null == ugi || !ugi.hasKerberosCredentials() || 
!ugi.getUserName().equals(principal) ||
    +      !keytab.equals(getKeytabFromUgi());
    +  }
    +
    +  private static String getKeytabFromUgi() {
    +    Class<?> clz = UserGroupInformation.class;
    +    try {
    +      synchronized (clz) {
    +        Field field = clz.getDeclaredField("keytabFile");
    +        field.setAccessible(true);
    +        return (String) field.get(null);
    +      }
    +    } catch (NoSuchFieldException e) {
    +      try {
    +        synchronized (clz) {
    +          // In Hadoop 3 we don't have "keytabFile" field, instead we 
should use private method
    +          // getKeytab().
    +          Method method = clz.getDeclaredMethod("getKeytab");
    +          method.setAccessible(true);
    +          return (String) 
method.invoke(UserGroupInformation.getCurrentUser());
    +        }
    +      } catch (Throwable t) {
    +        return null;
    +      }
    +    } catch (Throwable t) {
    +      return null;
    +    }
    --- End diff --
    
    Let us catch specific exceptions for method/field invocation; not throwable.
    The code I had initially written was poor in this regard btw, and was 
catching throwable - was bad form.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to