Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Jan 12, 2024
1 parent 098a37b commit c01a99e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class JdbcConnectionParams {
public static final String AUTH_KYUUBI_CLIENT_TICKET_CACHE = "kyuubiClientTicketCache";
public static final String AUTH_PASSWD = "password";
public static final String AUTH_KERBEROS_AUTH_TYPE = "kerberosAuthType";
public static final String AUTH_KERBEROS_AUTH_TYPE_FROM_KEYTAB = "fromKeytab";
public static final String AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT = "fromSubject";
public static final String AUTH_KERBEROS_AUTH_TYPE_FROM_TICKET_CACHE = "fromTicketCache";
public static final String ANONYMOUS_USER = "anonymous";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,30 +847,59 @@ private boolean isHadoopUserGroupInformationDoAs() {
}
}

private boolean isForciblyFromKeytabAuthMode() {
return AUTH_KERBEROS_AUTH_TYPE_FROM_KEYTAB.equalsIgnoreCase(
sessConfMap.get(AUTH_KERBEROS_AUTH_TYPE));
}

private boolean isForciblyFromSubjectAuthMode() {
return AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equalsIgnoreCase(
sessConfMap.get(AUTH_KERBEROS_AUTH_TYPE));
}

private boolean isForciblyTgtCacheAuthMode() {
return AUTH_KERBEROS_AUTH_TYPE_FROM_TICKET_CACHE.equalsIgnoreCase(
sessConfMap.get(AUTH_KERBEROS_AUTH_TYPE));
}

private boolean isKeytabAuthMode() {
return isSaslAuthMode()
&& hasSessionValue(AUTH_PRINCIPAL)
// handle explicit cases first
if (isForciblyFromSubjectAuthMode() || isForciblyTgtCacheAuthMode()) {
return false;
}
if (isKerberosAuthMode() && isForciblyFromKeytabAuthMode()) {
return true;
}
// handle implicit cases then
return isKerberosAuthMode()
&& hasSessionValue(AUTH_KYUUBI_CLIENT_PRINCIPAL)
&& hasSessionValue(AUTH_KYUUBI_CLIENT_KEYTAB);
}

private boolean isFromSubjectAuthMode() {
return isSaslAuthMode()
&& hasSessionValue(AUTH_PRINCIPAL)
&& !hasSessionValue(AUTH_KYUUBI_CLIENT_PRINCIPAL)
// handle explicit cases first
if (isForciblyFromKeytabAuthMode() || isForciblyTgtCacheAuthMode()) {
return false;
}
if (isKerberosAuthMode() && isForciblyFromSubjectAuthMode()) {
return true;
}
// handle implicit cases then
return isKerberosAuthMode()
&& !hasSessionValue(AUTH_KYUUBI_CLIENT_KEYTAB)
&& (AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equalsIgnoreCase(
sessConfMap.get(AUTH_KERBEROS_AUTH_TYPE))
|| (!AUTH_KERBEROS_AUTH_TYPE_FROM_TICKET_CACHE.equalsIgnoreCase(
sessConfMap.get(AUTH_KERBEROS_AUTH_TYPE))
&& isHadoopUserGroupInformationDoAs()));
&& isHadoopUserGroupInformationDoAs();
}

private boolean isTgtCacheAuthMode() {
return isSaslAuthMode()
&& hasSessionValue(AUTH_PRINCIPAL)
&& !hasSessionValue(AUTH_KYUUBI_CLIENT_PRINCIPAL)
&& !hasSessionValue(AUTH_KYUUBI_CLIENT_KEYTAB);
// handle explicit cases first
if (isForciblyFromKeytabAuthMode() || isForciblyFromSubjectAuthMode()) {
return false;
}
if (isKerberosAuthMode() && isForciblyTgtCacheAuthMode()) {
return true;
}
// handle implicit cases then
return isKerberosAuthMode() && !hasSessionValue(AUTH_KYUUBI_CLIENT_KEYTAB);
}

private boolean isPlainSaslAuthMode() {
Expand Down

0 comments on commit c01a99e

Please sign in to comment.