|
@@ -19,6 +19,10 @@
|
|
|
package org.apache.hadoop.yarn.server.router.webapp;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
|
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* Extends the RequestInterceptor class and provides common functionality which
|
|
@@ -29,6 +33,7 @@ public abstract class AbstractRESTRequestInterceptor
|
|
|
|
|
|
private Configuration conf;
|
|
|
private RESTRequestInterceptor nextInterceptor;
|
|
|
+ private UserGroupInformation user = null;
|
|
|
|
|
|
/**
|
|
|
* Sets the {@link RESTRequestInterceptor} in the chain.
|
|
@@ -62,9 +67,10 @@ public abstract class AbstractRESTRequestInterceptor
|
|
|
* Initializes the {@link RESTRequestInterceptor}.
|
|
|
*/
|
|
|
@Override
|
|
|
- public void init(String user) {
|
|
|
+ public void init(String userName) {
|
|
|
+ setupUser(userName);
|
|
|
if (this.nextInterceptor != null) {
|
|
|
- this.nextInterceptor.init(user);
|
|
|
+ this.nextInterceptor.init(userName);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -86,4 +92,35 @@ public abstract class AbstractRESTRequestInterceptor
|
|
|
return this.nextInterceptor;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set User information.
|
|
|
+ *
|
|
|
+ * If the username is empty, we will use the Yarn Router user directly.
|
|
|
+ * Do not create a proxy user if user name matches the user name on current UGI.
|
|
|
+ * @param userName userName.
|
|
|
+ */
|
|
|
+ private void setupUser(final String userName) {
|
|
|
+ try {
|
|
|
+ if (userName == null || userName.isEmpty()) {
|
|
|
+ user = UserGroupInformation.getCurrentUser();
|
|
|
+ } else if (UserGroupInformation.isSecurityEnabled()) {
|
|
|
+ user = UserGroupInformation.createProxyUser(userName, UserGroupInformation.getLoginUser());
|
|
|
+ } else if (userName.equalsIgnoreCase(UserGroupInformation.getCurrentUser().getUserName())) {
|
|
|
+ user = UserGroupInformation.getCurrentUser();
|
|
|
+ } else {
|
|
|
+ user = UserGroupInformation.createProxyUser(userName,
|
|
|
+ UserGroupInformation.getCurrentUser());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ String message = "Error while creating Router RMAdmin Service for user:";
|
|
|
+ if (user != null) {
|
|
|
+ message += ", user: " + user;
|
|
|
+ }
|
|
|
+ throw new YarnRuntimeException(message, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserGroupInformation getUser() {
|
|
|
+ return user;
|
|
|
+ }
|
|
|
}
|