private Rule createHostAgnosticRule(Principal principal, String localUser) {
    List<String> principalComponents = principal.getComponents();
    int componentCount = principalComponents.size();
    return new Rule(
      MatchingRule.ignoreHostWhenComponentCountIs(componentCount),
      new Principal(principal.getComponent(1) + "@" + principal.getRealm()),
      new Substitution(".*", localUser, "", false));
  }
Create a rule that expects 2 components in the principal and ignores hostname in the comparison.

@param principal principal
@param localUser local user
@return a new rule that ignores hostname in the comparison
ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java