|
@@ -18,15 +18,20 @@
|
|
package org.apache.hadoop.security;
|
|
package org.apache.hadoop.security;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
|
|
+import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.Time;
|
|
import org.apache.hadoop.util.Time;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
@@ -49,6 +54,8 @@ public class Groups {
|
|
|
|
|
|
private final Map<String, CachedGroups> userToGroupsMap =
|
|
private final Map<String, CachedGroups> userToGroupsMap =
|
|
new ConcurrentHashMap<String, CachedGroups>();
|
|
new ConcurrentHashMap<String, CachedGroups>();
|
|
|
|
+ private final Map<String, List<String>> staticUserToGroupsMap =
|
|
|
|
+ new HashMap<String, List<String>>();
|
|
private final long cacheTimeout;
|
|
private final long cacheTimeout;
|
|
private final long warningDeltaMs;
|
|
private final long warningDeltaMs;
|
|
|
|
|
|
@@ -66,12 +73,43 @@ public class Groups {
|
|
warningDeltaMs =
|
|
warningDeltaMs =
|
|
conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS,
|
|
conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS,
|
|
CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS_DEFAULT);
|
|
CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS_DEFAULT);
|
|
-
|
|
|
|
|
|
+ parseStaticMapping(conf);
|
|
|
|
+
|
|
if(LOG.isDebugEnabled())
|
|
if(LOG.isDebugEnabled())
|
|
LOG.debug("Group mapping impl=" + impl.getClass().getName() +
|
|
LOG.debug("Group mapping impl=" + impl.getClass().getName() +
|
|
"; cacheTimeout=" + cacheTimeout + "; warningDeltaMs=" +
|
|
"; cacheTimeout=" + cacheTimeout + "; warningDeltaMs=" +
|
|
warningDeltaMs);
|
|
warningDeltaMs);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Parse the hadoop.user.group.static.mapping.overrides configuration to
|
|
|
|
+ * staticUserToGroupsMap
|
|
|
|
+ */
|
|
|
|
+ private void parseStaticMapping(Configuration conf) {
|
|
|
|
+ String staticMapping = conf.get(
|
|
|
|
+ CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES,
|
|
|
|
+ CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES_DEFAULT);
|
|
|
|
+ Collection<String> mappings = StringUtils.getStringCollection(
|
|
|
|
+ staticMapping, ";");
|
|
|
|
+ for (String users : mappings) {
|
|
|
|
+ Collection<String> userToGroups = StringUtils.getStringCollection(users,
|
|
|
|
+ "=");
|
|
|
|
+ if (userToGroups.size() < 1 || userToGroups.size() > 2) {
|
|
|
|
+ throw new HadoopIllegalArgumentException("Configuration "
|
|
|
|
+ + CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES
|
|
|
|
+ + " is invalid");
|
|
|
|
+ }
|
|
|
|
+ String[] userToGroupsArray = userToGroups.toArray(new String[userToGroups
|
|
|
|
+ .size()]);
|
|
|
|
+ String user = userToGroupsArray[0];
|
|
|
|
+ List<String> groups = Collections.emptyList();
|
|
|
|
+ if (userToGroupsArray.length == 2) {
|
|
|
|
+ groups = (List<String>) StringUtils
|
|
|
|
+ .getStringCollection(userToGroupsArray[1]);
|
|
|
|
+ }
|
|
|
|
+ staticUserToGroupsMap.put(user, groups);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Get the group memberships of a given user.
|
|
* Get the group memberships of a given user.
|
|
@@ -80,6 +118,11 @@ public class Groups {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
public List<String> getGroups(String user) throws IOException {
|
|
public List<String> getGroups(String user) throws IOException {
|
|
|
|
+ // No need to lookup for groups of static users
|
|
|
|
+ List<String> staticMapping = staticUserToGroupsMap.get(user);
|
|
|
|
+ if (staticMapping != null) {
|
|
|
|
+ return staticMapping;
|
|
|
|
+ }
|
|
// Return cached value if available
|
|
// Return cached value if available
|
|
CachedGroups groups = userToGroupsMap.get(user);
|
|
CachedGroups groups = userToGroupsMap.get(user);
|
|
long startMs = Time.monotonicNow();
|
|
long startMs = Time.monotonicNow();
|