code: private String gainPrincipalFromAlias(String alias, KeyStore keystore) throws Exception {
          if (keystore == null) {
              return null;
          }
          if (!keystore.containsAlias(alias)) {
              return null;
          }
  
          Certificate certificate = keystore.getCertificate(alias);
          if (certificate == null || !(certificate instanceof X509Certificate)) {
              return null;
          }
  
          X509Certificate x509Certificate = (X509Certificate) certificate;
          X500Principal principal = new X500Principal(x509Certificate.getSubjectX500Principal().toString());
          return principal.getName();
      }
docs: Private method for gaining X500Principal from keystore according its alias.
  
  @param alias alias of principal
  @param keystore KeyStore which is used by this policy file
  @return name of gained X500Principal
  @throws Exception when there was any problem during gaining Principal