Class KerberosConnection
- java.lang.Object
-
- org.apache.calcite.avatica.remote.KerberosConnection
-
public class KerberosConnection extends java.lang.ObjectA utility to perform Kerberos logins and renewals.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classKerberosConnection.RenewalTaskRunnable for performing Kerberos renewals.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringIBM_KRB5_LOGIN_MODULEprivate static booleanIS_IBM_JAVAprivate static java.lang.StringJAAS_CONF_NAMEprivate javax.security.auth.login.ConfigurationjaasConfprivate static java.lang.StringJAVA_VENDOR_NAMEprivate static org.slf4j.LoggerLOGstatic floatPERCENT_OF_LIFETIME_TO_RENEWThe percentage of the Kerberos ticket's lifetime which we should start trying to renew itprivate java.lang.Stringprincipalstatic longRENEWAL_PERIODHow long should we sleep between checks to renew the Kerberos ticketprivate static java.lang.StringRENEWAL_THREAD_NAMEprivate KerberosConnection.RenewalTaskrenewalTaskprivate java.lang.ThreadrenewalThreadprivate javax.security.auth.Subjectsubjectprivate static java.lang.StringSUN_KRB5_LOGIN_MODULE
-
Constructor Summary
Constructors Constructor Description KerberosConnection(java.lang.String principal, java.io.File keytab)Constructs an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) javax.security.auth.login.LoginContextcreateLoginContext(javax.security.auth.login.Configuration conf)(package private) java.util.Map.Entry<KerberosConnection.RenewalTask,java.lang.Thread>createRenewalThread(javax.security.auth.login.LoginContext originalContext, javax.security.auth.Subject originalSubject, long renewalPeriod)Launches a thread to periodically check the current ticket's lifetime and perform a relogin as necessary.static java.lang.StringgetKrb5LoginModuleName()Returns the KRB5 LoginModule implementation.javax.security.auth.SubjectgetSubject()static booleanisIbmJava()Returns whether or not the current environment is IBM Java.(package private) static booleanisTGSPrincipal(javax.security.auth.kerberos.KerberosPrincipal principal)Computes if the givenprincipalis the ticket-granting system's principal ("krbtgt").voidlogin()Perform a Kerberos login and launch a daemon thread to periodically perfrom renewals of that Kerberos login.(package private) java.util.Map.Entry<javax.security.auth.login.LoginContext,javax.security.auth.Subject>login(javax.security.auth.login.LoginContext prevContext, javax.security.auth.login.Configuration conf, javax.security.auth.Subject subject)Performs a kerberos login, possibly logging out first.(package private) java.util.Map.Entry<javax.security.auth.login.LoginContext,javax.security.auth.Subject>performKerberosLogin()Performs a Kerberos login given theprincipalandkeytab.voidstopRenewalThread()Stops the Kerberos renewal thread if it is still running.
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
IBM_KRB5_LOGIN_MODULE
private static final java.lang.String IBM_KRB5_LOGIN_MODULE
- See Also:
- Constant Field Values
-
SUN_KRB5_LOGIN_MODULE
private static final java.lang.String SUN_KRB5_LOGIN_MODULE
- See Also:
- Constant Field Values
-
JAAS_CONF_NAME
private static final java.lang.String JAAS_CONF_NAME
- See Also:
- Constant Field Values
-
RENEWAL_THREAD_NAME
private static final java.lang.String RENEWAL_THREAD_NAME
- See Also:
- Constant Field Values
-
JAVA_VENDOR_NAME
private static final java.lang.String JAVA_VENDOR_NAME
-
IS_IBM_JAVA
private static final boolean IS_IBM_JAVA
-
PERCENT_OF_LIFETIME_TO_RENEW
public static final float PERCENT_OF_LIFETIME_TO_RENEW
The percentage of the Kerberos ticket's lifetime which we should start trying to renew it- See Also:
- Constant Field Values
-
RENEWAL_PERIOD
public static final long RENEWAL_PERIOD
How long should we sleep between checks to renew the Kerberos ticket- See Also:
- Constant Field Values
-
principal
private final java.lang.String principal
-
jaasConf
private final javax.security.auth.login.Configuration jaasConf
-
subject
private javax.security.auth.Subject subject
-
renewalTask
private KerberosConnection.RenewalTask renewalTask
-
renewalThread
private java.lang.Thread renewalThread
-
-
Method Detail
-
getSubject
public javax.security.auth.Subject getSubject()
-
login
public void login()
Perform a Kerberos login and launch a daemon thread to periodically perfrom renewals of that Kerberos login. Exceptions are intentionally caught and rethrown as unchecked exceptions as there is nothing Avatica itself can do if the Kerberos login fails.- Throws:
java.lang.RuntimeException- If the Kerberos login fails
-
performKerberosLogin
java.util.Map.Entry<javax.security.auth.login.LoginContext,javax.security.auth.Subject> performKerberosLogin()
Performs a Kerberos login given theprincipalandkeytab.- Returns:
- The
SubjectandLoginContextfrom the successful login. - Throws:
java.lang.RuntimeException- if the login failed
-
login
java.util.Map.Entry<javax.security.auth.login.LoginContext,javax.security.auth.Subject> login(javax.security.auth.login.LoginContext prevContext, javax.security.auth.login.Configuration conf, javax.security.auth.Subject subject) throws javax.security.auth.login.LoginExceptionPerforms a kerberos login, possibly logging out first.- Parameters:
prevContext- The LoginContext from the previous login, or nullconf- JAAS Configuration objectsubject- The JAAS Subject- Returns:
- The context and subject from the login
- Throws:
javax.security.auth.login.LoginException- If the login failed.
-
createLoginContext
javax.security.auth.login.LoginContext createLoginContext(javax.security.auth.login.Configuration conf) throws javax.security.auth.login.LoginException- Throws:
javax.security.auth.login.LoginException
-
createRenewalThread
java.util.Map.Entry<KerberosConnection.RenewalTask,java.lang.Thread> createRenewalThread(javax.security.auth.login.LoginContext originalContext, javax.security.auth.Subject originalSubject, long renewalPeriod)
Launches a thread to periodically check the current ticket's lifetime and perform a relogin as necessary.- Parameters:
originalContext- The original login's context.originalSubject- The original login's subject.renewalPeriod- The amount of time to sleep inbetween checks to renew
-
stopRenewalThread
public void stopRenewalThread()
Stops the Kerberos renewal thread if it is still running. If the thread was already started or never started, this method does nothing.
-
isTGSPrincipal
static boolean isTGSPrincipal(javax.security.auth.kerberos.KerberosPrincipal principal)
Computes if the givenprincipalis the ticket-granting system's principal ("krbtgt").- Parameters:
principal- AKerberosPrincipal.- Returns:
- True if
principalis the TGS principal, false otherwise.
-
isIbmJava
public static boolean isIbmJava()
Returns whether or not the current environment is IBM Java. Otherwise, assumed to be Oracle Java/OpenJDK.- Returns:
- True if the environment is IBM Java, false otherwise.
-
getKrb5LoginModuleName
public static java.lang.String getKrb5LoginModuleName()
Returns the KRB5 LoginModule implementation. This is JVM-vendor dependent.- Returns:
- The class name of the KRB5 LoginModule
-
-