try {
tenantID = realmService.getTenantManager().getTenantId(domainName);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String errorMsg = "Error getting the TenantID for the domain name";
log.error(errorMsg, e);
throw new SAML2SSOAuthenticatorException(errorMsg, e);
}
}
KeyStoreManager keyStoreManager = null;
try {
// get an instance of the corresponding Key Store Manager instance
keyStoreManager = KeyStoreManager.getInstance(registryService.getGovernanceSystemRegistry(tenantID));
} catch (RegistryException e) {
String errorMsg = "Error getting a KeyStore Manager instance.";
log.error(errorMsg, e);
throw new SAML2SSOAuthenticatorException(errorMsg, e);
}
X509CredentialImpl credentialImpl = null;
try {
if (tenantID != 0) { // for non zero tenants, load private key from their generated key store
KeyStore keystore = keyStoreManager.getKeyStore(generateKSNameFromDomainName(domainName));
java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) keystore.getCertificate(domainName);
credentialImpl = new X509CredentialImpl(cert);
} else { // for tenant zero, load the default pub. cert using the config. in carbon.xml
java.security.cert.X509Certificate cert = keyStoreManager.getDefaultPrimaryCertificate();
credentialImpl = new X509CredentialImpl(cert);
}
} catch (Exception e) {
String errorMsg = "Error instantiating an X509CredentialImpl object for the public cert.";
log.error(errorMsg, e);
throw new SAML2SSOAuthenticatorException(errorMsg, e);
}
return credentialImpl;
}