@Subscribe
  public void componentRemoved(ServiceComponentUninstalledEvent event) throws KerberosMissingAdminCredentialsException {
    try {
      Cluster cluster = clusters.getCluster(event.getClusterId());

      if (cluster.getSecurityType() == SecurityType.KERBEROS) {
        if (null != cluster.getUpgradeInProgress()) {
          LOG.info("Skipping removal of identities for {} since there is an upgrade in progress",
              event.getComponentName());

          return;
        }

        LOG.info("Removing identities after {}", event);
        RemovableIdentities
            .ofComponent(clusters.getCluster(event.getClusterId()), event, kerberosHelper)
            .remove(kerberosHelper);
      }
    } catch (Exception e) {
      LOG.error("Error while deleting kerberos identity after an event: " + event, e);
    }
  }
Removes kerberos identities (principals and keytabs) after a component was uninstalled.
Keeps the identity if either the principal or the keytab is used by an other service
ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/KerberosIdentityCleaner.java