@Override
  public boolean principalExists(String principal, boolean service)
      throws KerberosOperationException {

    if (!isOpen()) {
      throw new KerberosOperationException("This operation handler has not been opened");
    }

    if (!StringUtils.isEmpty(principal)) {
      DeconstructedPrincipal deconstructedPrincipal = createDeconstructPrincipal(principal);
      String principalName = deconstructedPrincipal.getPrincipalName();

      String[] ipaCommand = new String[]{
          (service) ? "service-show" : "user-show",
          principalName
      };

      ShellCommandUtil.Result result = invokeIpa(ipaCommand);
      if (result.isSuccessful()) {
        return true;
      }
    }

    return false;
  }
Test to see if the specified principal exists in a previously configured IPA KDC
<p/>
This implementation creates a query to send to the ipa shell command and then interrogates
the result from STDOUT to determine if the presence of the specified principal.

@param principal a String containing the principal to test
@param service   a boolean value indicating whether the principal is for a service or not
@return true if the principal exists; false otherwise
@throws KerberosOperationException if an unexpected error occurred
ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/IPAKerberosOperationHandler.java