/** * Constructs a new {@link ImpersonationAuthenticator}. */ public ImpersonationAuthenticator() { mImpersonationGroups = new HashMap<>(); mImpersonationUsers = new HashMap<>(); for (PropertyKey key : Configuration.keySet()) { String value = Configuration.getOrDefault(key, null); // Process impersonation groups Matcher matcher = PropertyKey.Template.MASTER_IMPERSONATION_GROUPS_OPTION.match(key.getName()); if (matcher.matches()) { String connectionUser = matcher.group(1); if (connectionUser != null) { mImpersonationGroups.put(connectionUser, Sets.newHashSet(SPLITTER.split(value))); } } // Process impersonation users matcher = PropertyKey.Template.MASTER_IMPERSONATION_USERS_OPTION.match(key.getName()); if (matcher.matches()) { String connectionUser = matcher.group(1); if (connectionUser != null) { mImpersonationUsers.put(connectionUser, Sets.newHashSet(SPLITTER.split(value))); } } } }
/** * Checks that tiered locality configuration is consistent. * * @throws IllegalStateException if invalid tiered locality configuration is encountered */ private void checkTieredLocality() { // Check that any custom tiers set by alluxio.locality.{custom_tier}=value are also defined in // the tier ordering defined by alluxio.locality.order. Set<String> tiers = Sets.newHashSet(getList(PropertyKey.LOCALITY_ORDER, ",")); Set<PropertyKey> predefinedKeys = new HashSet<>(PropertyKey.defaultKeys()); for (PropertyKey key : mProperties.keySet()) { if (predefinedKeys.contains(key)) { // Skip non-templated keys. continue; } Matcher matcher = Template.LOCALITY_TIER.match(key.toString()); if (matcher.matches() && matcher.group(1) != null) { String tierName = matcher.group(1); if (!tiers.contains(tierName)) { throw new IllegalStateException( String.format("Tier %s is configured by %s, but does not exist in the tier list %s " + "configured by %s", tierName, key, tiers, PropertyKey.LOCALITY_ORDER)); } } } } }
/** * Gets the property key if the property name matches the template. * * @param propertyName name of the property * @return the property key, or null if the property name does not match the template */ @Nullable private PropertyKey getPropertyKey(String propertyName) { Matcher matcher = match(propertyName); if (!matcher.matches()) { return null; } // if the template can extract a nested property, build the new property from the nested one String nestedKeyName = null; try { nestedKeyName = matcher.group(NESTED_GROUP); } catch (IllegalArgumentException e) { // ignore if group is not found } PropertyKey nestedProperty = null; if (nestedKeyName != null && isValid(nestedKeyName)) { nestedProperty = fromString(nestedKeyName); } return mPropertyCreator.apply(propertyName, nestedProperty); } }