use of org.wso2.carbon.identity.core.CertificateRetrievingException in project carbon-identity-framework by wso2.
the class KeyStoreCertificateRetriever method getCertificate.
/**
* @param certificateId Alias of the certificate to be retrieved.
* @param tenant The tenant where the key store file should be loaded from.
* If the tenant is the super tenant, the primary key store will be used.
* @return The certificate for the given alias
*/
@Override
public X509Certificate getCertificate(String certificateId, Tenant tenant) throws CertificateRetrievingException {
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenant.getId());
KeyStore keyStore;
try {
if (tenant.getId() != MultitenantConstants.SUPER_TENANT_ID) {
// This is a tenant. So load the tenant key store.
keyStore = keyStoreManager.getKeyStore(getKeyStoreName(tenant.getDomain()));
} else {
// This is the super tenant. So load the primary key store.
keyStore = keyStoreManager.getPrimaryKeyStore();
}
X509Certificate certificate = (X509Certificate) keyStore.getCertificate(certificateId);
return certificate;
} catch (Exception e) {
String errorMsg = String.format("Error occurred while retrieving the certificate for the alias '%s' " + "of the tenant domain '%s'." + certificateId, tenant.getDomain());
throw new CertificateRetrievingException(errorMsg, e);
}
}
Aggregations