try {
KeyStoreAdmin keyAdmin = new KeyStoreAdmin(IdentityTenantUtil.getRegistry(null, null));
KeyStoreData[] keystores = keyAdmin.getKeyStores();
if (keystores.length == 0 || keystores.length > 1) {
throw new IdentityException("There should be only one keystore");
}
KeyStoreManager keyMan = KeyStoreManager.getInstance(null);
KeyStore store = keyMan.getKeyStore(keystores[0].getKeyStoreName());
Certificate[] certChain = store.getCertificateChain(alias);
X509Certificate[] certs = new X509Certificate[certChain.length];
for (int i = 0; i < certs.length; i++) {
certs[i] = (X509Certificate) certChain[i];
}
return certs;
} catch (Exception e) {
log.error("Error while retreiving certificate for alias", e);
throw new IdentityException("Error while retreiving certificate for alias", e);
}
}