|
@@ -93,18 +93,30 @@ public class UserGroupInformation {
|
|
|
|
|
|
@Override
|
|
|
public boolean commit() throws LoginException {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("hadoop login commit");
|
|
|
+ }
|
|
|
// if we already have a user, we are done.
|
|
|
if (!subject.getPrincipals(User.class).isEmpty()) {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("using existing subject:"+subject.getPrincipals());
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
Principal user = null;
|
|
|
// if we are using kerberos, try it out
|
|
|
if (useKerberos) {
|
|
|
user = getCanonicalUser(KerberosPrincipal.class);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("using kerberos user:"+user);
|
|
|
+ }
|
|
|
}
|
|
|
// if we don't have a kerberos user, use the OS user
|
|
|
if (user == null) {
|
|
|
user = getCanonicalUser(OS_PRINCIPAL_CLASS);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("using local user:"+user);
|
|
|
+ }
|
|
|
}
|
|
|
// if we found the user, add our principal
|
|
|
if (user != null) {
|
|
@@ -123,11 +135,17 @@ public class UserGroupInformation {
|
|
|
|
|
|
@Override
|
|
|
public boolean login() throws LoginException {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("hadoop login");
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean logout() throws LoginException {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("hadoop logout");
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -179,11 +197,6 @@ public class UserGroupInformation {
|
|
|
if (!(groups instanceof TestingGroups)) {
|
|
|
groups = Groups.getUserToGroupsMappingService(conf);
|
|
|
}
|
|
|
- // Set the configuration for JAAS to be the Hadoop configuration.
|
|
|
- // This is done here rather than a static initializer to avoid a
|
|
|
- // circular dependence.
|
|
|
- javax.security.auth.login.Configuration.setConfiguration
|
|
|
- (new HadoopConfiguration());
|
|
|
// give the configuration on how to translate Kerberos names
|
|
|
try {
|
|
|
KerberosName.setConfiguration(conf);
|
|
@@ -356,6 +369,11 @@ public class UserGroupInformation {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static LoginContext
|
|
|
+ newLoginContext(String appName, Subject subject) throws LoginException {
|
|
|
+ return new LoginContext(appName, subject, null, new HadoopConfiguration());
|
|
|
+ }
|
|
|
+
|
|
|
private LoginContext getLogin() {
|
|
|
return user.getLogin();
|
|
|
}
|
|
@@ -407,9 +425,9 @@ public class UserGroupInformation {
|
|
|
Subject subject = new Subject();
|
|
|
LoginContext login;
|
|
|
if (isSecurityEnabled()) {
|
|
|
- login = new LoginContext(HadoopConfiguration.USER_KERBEROS_CONFIG_NAME, subject);
|
|
|
+ login = newLoginContext(HadoopConfiguration.USER_KERBEROS_CONFIG_NAME, subject);
|
|
|
} else {
|
|
|
- login = new LoginContext(HadoopConfiguration.SIMPLE_CONFIG_NAME, subject);
|
|
|
+ login = newLoginContext(HadoopConfiguration.SIMPLE_CONFIG_NAME, subject);
|
|
|
}
|
|
|
login.login();
|
|
|
loginUser = new UserGroupInformation(subject);
|
|
@@ -432,6 +450,9 @@ public class UserGroupInformation {
|
|
|
} catch (LoginException le) {
|
|
|
throw new IOException("failure to login", le);
|
|
|
}
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("UGI loginUser:"+loginUser);
|
|
|
+ }
|
|
|
}
|
|
|
return loginUser;
|
|
|
}
|
|
@@ -556,7 +577,7 @@ public class UserGroupInformation {
|
|
|
}
|
|
|
try {
|
|
|
login =
|
|
|
- new LoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject);
|
|
|
+ newLoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject);
|
|
|
start = System.currentTimeMillis();
|
|
|
login.login();
|
|
|
metrics.addLoginSuccess(System.currentTimeMillis() - start);
|
|
@@ -602,7 +623,7 @@ public class UserGroupInformation {
|
|
|
//login and also update the subject field of this instance to
|
|
|
//have the new credentials (pass it to the LoginContext constructor)
|
|
|
login =
|
|
|
- new LoginContext(HadoopConfiguration.USER_KERBEROS_CONFIG_NAME,
|
|
|
+ newLoginContext(HadoopConfiguration.USER_KERBEROS_CONFIG_NAME,
|
|
|
getSubject());
|
|
|
LOG.info("Initiating re-login for " + getUserName());
|
|
|
login.login();
|
|
@@ -639,7 +660,7 @@ public class UserGroupInformation {
|
|
|
Subject subject = new Subject();
|
|
|
|
|
|
LoginContext login =
|
|
|
- new LoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject);
|
|
|
+ newLoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject);
|
|
|
|
|
|
start = System.currentTimeMillis();
|
|
|
login.login();
|
|
@@ -713,7 +734,7 @@ public class UserGroupInformation {
|
|
|
//login and also update the subject field of this instance to
|
|
|
//have the new credentials (pass it to the LoginContext constructor)
|
|
|
login =
|
|
|
- new LoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME,
|
|
|
+ newLoginContext(HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME,
|
|
|
getSubject());
|
|
|
LOG.info("Initiating re-login for " + keytabPrincipal);
|
|
|
start = System.currentTimeMillis();
|
|
@@ -976,11 +997,10 @@ public class UserGroupInformation {
|
|
|
*/
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- if (getRealUser() != null) {
|
|
|
- return getUserName() + " via " + getRealUser().toString();
|
|
|
- } else {
|
|
|
- return getUserName();
|
|
|
- }
|
|
|
+ String me = (getRealUser() != null)
|
|
|
+ ? getUserName() + " via " + getRealUser().toString()
|
|
|
+ : getUserName();
|
|
|
+ return me + " (auth:"+getAuthenticationMethod()+")";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1039,6 +1059,7 @@ public class UserGroupInformation {
|
|
|
* @return the value from the run method
|
|
|
*/
|
|
|
public <T> T doAs(PrivilegedAction<T> action) {
|
|
|
+ logPriviledgedAction(subject, action);
|
|
|
return Subject.doAs(subject, action);
|
|
|
}
|
|
|
|
|
@@ -1056,9 +1077,11 @@ public class UserGroupInformation {
|
|
|
public <T> T doAs(PrivilegedExceptionAction<T> action
|
|
|
) throws IOException, InterruptedException {
|
|
|
try {
|
|
|
+ logPriviledgedAction(subject, action);
|
|
|
return Subject.doAs(subject, action);
|
|
|
} catch (PrivilegedActionException pae) {
|
|
|
Throwable cause = pae.getCause();
|
|
|
+ LOG.error("PriviledgedActionException as:"+this+" cause:"+cause);
|
|
|
if (cause instanceof IOException) {
|
|
|
throw (IOException) cause;
|
|
|
} else if (cause instanceof Error) {
|
|
@@ -1073,6 +1096,14 @@ public class UserGroupInformation {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void logPriviledgedAction(Subject subject, Object action) {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ // would be nice if action included a descriptive toString()
|
|
|
+ String where = new Throwable().getStackTrace()[2].toString();
|
|
|
+ LOG.debug("PriviledgedAction as:"+this+" from:"+where);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void print() throws IOException {
|
|
|
System.out.println("User: " + getUserName());
|
|
|
System.out.print("Group Ids: ");
|