public AuthToLocalBuilder addRule(String principal, String localUsername) {
    if (!StringUtils.isEmpty(principal) && !StringUtils.isEmpty(localUsername)) {
      Principal p = new Principal(principal);
      if (p.getRealm() == null) {
        throw new IllegalArgumentException(
            "Attempted to add a rule for a principal with no realm: " + principal);
      }

      Rule rule = createHostAgnosticRule(p, localUsername);
      setRules.add(rule);
    }
    return this;
  }
Adds a rule for the given principal and local user.
The principal must contain a realm component.
<p/>
The supplied principal is parsed to determine if it is qualified or unqualified and stored
accordingly so that when the mapping rules are generated the appropriate rule is generated.
<p/>
If a principal is added that yields a duplicate primary principal value (relative to the set of
qualified or unqualified rules), that later entry will overwrite the older entry, allowing for
only one mapping rule.
<p/>
If the principal does not match one of the two expected patterns, it will be ignored.

@param principal     a string containing the full principal
@param localUsername a string declaring that local username to map the principal to
@throws IllegalArgumentException if the provided principal doesn't contain a realm element
ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java