" Must restart agent to use new principal or keytab. " +
"Previous = %s, New = %s", prevUser, newUser);
// attempt to use cached credential if the user is the same
// this is polite and should avoid flooding the KDC with auth requests
UserGroupInformation curUser = null;
if (prevUser != null && prevUser.equals(newUser)) {
try {
curUser = UserGroupInformation.getLoginUser();
} catch (IOException e) {
LOG.warn("User unexpectedly had no active login. Continuing with " +
"authentication", e);
}
}
if (curUser == null || !curUser.getUserName().equals(principal)) {
try {
// static login
kerberosLogin(this, principal, kerbKeytab);
} catch (IOException e) {
LOG.error("Authentication or file read error while attempting to "
+ "login as kerberos principal (" + principal + ") using "
+ "keytab (" + kerbKeytab + "). Exception follows.", e);
return false;
}
} else {
LOG.debug("{}: Using existing principal login: {}", this, curUser);
}
// we supposedly got through this unscathed... so store the static user
staticLogin.set(newUser);
}
// hadoop impersonation works with or without kerberos security
proxyTicket = null;
if (!proxyUserName.isEmpty()) {
try {
proxyTicket = UserGroupInformation.createProxyUser(
proxyUserName, UserGroupInformation.getLoginUser());
} catch (IOException e) {
LOG.error("Unable to login as proxy user. Exception follows.", e);
return false;
}
}
UserGroupInformation ugi = null;
if (proxyTicket != null) {
ugi = proxyTicket;
} else if (useSecurity) {
try {
ugi = UserGroupInformation.getLoginUser();
} catch (IOException e) {
LOG.error("Unexpected error: Unable to get authenticated user after " +
"apparent successful login! Exception follows.", e);
return false;
}
}
if (ugi != null) {
// dump login information
AuthenticationMethod authMethod = ugi.getAuthenticationMethod();
LOG.info("Auth method: {}", authMethod);
LOG.info(" User name: {}", ugi.getUserName());
LOG.info(" Using keytab: {}", ugi.isFromKeytab());
if (authMethod == AuthenticationMethod.PROXY) {
UserGroupInformation superUser;
try {
superUser = UserGroupInformation.getLoginUser();
LOG.info(" Superuser auth: {}", superUser.getAuthenticationMethod());
LOG.info(" Superuser name: {}", superUser.getUserName());
LOG.info(" Superuser using keytab: {}", superUser.isFromKeytab());
} catch (IOException e) {
LOG.error("Unexpected error: unknown superuser impersonating proxy.",
e);
return false;
}