Search in sources :

Example 6 with CertificateRetrievingException

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);
    }
}
Also used : KeyStoreManager(org.wso2.carbon.core.util.KeyStoreManager) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Aggregations

SQLException (java.sql.SQLException)4 CertificateRetrievingException (org.wso2.carbon.identity.core.CertificateRetrievingException)3 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ServiceProviderProperty (org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)2 KeyStore (java.security.KeyStore)1 CertificateException (java.security.cert.CertificateException)1 KeyStoreManager (org.wso2.carbon.core.util.KeyStoreManager)1 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)1 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)1 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)1 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)1 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)1 CertificateRetriever (org.wso2.carbon.identity.core.CertificateRetriever)1 DatabaseCertificateRetriever (org.wso2.carbon.identity.core.DatabaseCertificateRetriever)1