public static DeconstructedPrincipal valueOf(String principal, @Nullable String defaultRealm) {
    if (principal == null) {
      throw new IllegalArgumentException("The principal may not be null");
    }

    Matcher matcher = PATTERN_PRINCIPAL.matcher(principal);

    if (matcher.matches()) {
      String primary = matcher.group(1);
      String instance = matcher.group(2);
      String realm = matcher.group(3);

      if ((realm == null) || realm.isEmpty()) {
        realm = defaultRealm;
      }

      return new DeconstructedPrincipal(primary, instance, realm);
    } else {
      throw new IllegalArgumentException(String.format("Invalid principal value: %s", principal));
    }
  }
Given a principal and a default realm, creates a new DeconstructedPrincipal
<p/>
If the supplied principal does not have a realm component, the default realm (supplied) will be
used.

@param principal    a String containing the principal to deconstruct
@param defaultRealm a String containing the default realm
@return a new DeconstructedPrincipal
ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DeconstructedPrincipal.java