class KerberosServerAction extends AbstractServerAction {

  protected CommandReport processIdentities(Map<String, Object> requestSharedDataContext)
      throws AmbariException {
    CommandReport commandReport = null;
    Map<String, String> commandParameters = getCommandParameters();

    actionLog.writeStdOut("Processing identities...");
    LOG.info("Processing identities...");

    if (commandParameters != null) {
      // Grab the relevant data from this action's command parameters map
      PrincipalKeyCredential administratorCredential = kerberosHelper.getKDCAdministratorCredentials(getClusterName());
      KDCType kdcType = getKDCType(commandParameters);
      String defaultRealm = getDefaultRealm(commandParameters);

      KerberosOperationHandler handler = kerberosOperationHandlerFactory.getKerberosOperationHandler(kdcType);
      Map<String, String> kerberosConfiguration = getConfigurationProperties("kerberos-env");

      try {
        handler.open(administratorCredential, defaultRealm, kerberosConfiguration);
      } catch (KerberosOperationException e) {
        String message = String.format("Failed to process the identities, could not properly open the KDC operation handler: %s",
            e.getMessage());
        actionLog.writeStdErr(message);
        LOG.error(message);
        throw new AmbariException(message, e);
      }

      try {
        Map<String, Collection<String>> serviceComponentFilter = getServiceComponentFilter();
        if (serviceComponentFilter != null && pruneServiceFilter()) {
          kerberosKeytabController.adjustServiceComponentFilter(clusters.getCluster(getClusterName()), true, serviceComponentFilter);
        }
        final Collection<KerberosIdentityDescriptor> serviceIdentities = serviceComponentFilter == null ? null : kerberosKeytabController.getServiceIdentities(getClusterName(), serviceComponentFilter.keySet());
        for (ResolvedKerberosKeytab rkk : kerberosKeytabController.getFilteredKeytabs(serviceIdentities, getHostFilter(),getIdentityFilter())) {
          for (ResolvedKerberosPrincipal principal : rkk.getPrincipals()) {
            commandReport = processIdentity(principal, handler, kerberosConfiguration, isRelevantIdentity(serviceIdentities, principal), requestSharedDataContext);
            // If the principal processor returns a CommandReport, than it is time to stop
            // since an error condition has probably occurred, else all is assumed to be well.
            if (commandReport != null) {
              break;
            }
          }
        }
      } finally {
        // The KerberosOperationHandler needs to be closed, if it fails to close ignore the
        // exception since there is little we can or care to do about it now.
        try {
          handler.close();
        } catch (KerberosOperationException e) {
          // Ignore this...
        }
      }

    }

    actionLog.writeStdOut("Processing identities completed.");
    LOG.info("Processing identities completed.");

    // If commandReport is null, we can assume this operation was a success, so return a successful
    // CommandReport; else return the previously created CommandReport.
    return (commandReport == null)
        ? createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr())
        : commandReport;
  }

}