diff --git a/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/utils/security/KeystoreUtils.java b/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/utils/security/KeystoreUtils.java index 83b6868a65..2c5bdf188d 100644 --- a/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/utils/security/KeystoreUtils.java +++ b/core/org.wso2.carbon.utils/src/main/java/org/wso2/carbon/utils/security/KeystoreUtils.java @@ -41,7 +41,6 @@ public class KeystoreUtils { private static Log LOG = LogFactory.getLog(KeystoreUtils.class); private static final String FALLBACK_TENANTED_KEYSTORE_FILE_TYPE = "JKS"; - private static final String KEY_STORES = "/repository/security/key-stores"; private static final KeyStorePersistenceManager keyStorePersistenceManager = KeyStorePersistenceManagerFactory.getKeyStorePersistenceManager(); @@ -53,7 +52,6 @@ public enum StoreFileType { PKCS12(".p12"); private final String extension; - private static final String defaultFileType = "PKCS12"; StoreFileType(String extension) { @@ -144,23 +142,19 @@ public static String getKeyStoreFileLocation(String tenantDomain) { */ public static String getKeyStoreFileType(String tenantDomain) { - String keystoreType = CarbonUtils.getServerConfiguration().getFirstProperty("Security.KeyStore.Type"); - try { - StoreFileType.validateFileType(keystoreType); - } catch (CarbonException e) { - LOG.error("Unsupported file type for key store file", e); - } - + String keystoreType; if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + keystoreType = CarbonUtils.getServerConfiguration().getFirstProperty("Security.KeyStore.Type"); return keystoreType; + } else { + keystoreType = StoreFileType.defaultFileType(); + String ksName = tenantDomain.trim().replace(".", "-"); + String ksExtension = getExtensionByFileType(keystoreType); + if (StoreFileType.PKCS12.name().equals(keystoreType) && isKeyStoreExists(ksName + ksExtension)) { + return keystoreType; + } + return FALLBACK_TENANTED_KEYSTORE_FILE_TYPE; } - - String ksName = tenantDomain.trim().replace(".", "-"); - if (isKeyStoreExists(ksName + getExtensionByFileType(keystoreType))) { - return keystoreType; - } - - return FALLBACK_TENANTED_KEYSTORE_FILE_TYPE; } /** @@ -226,7 +220,7 @@ private static boolean isKeyStoreExists(String keyStoreName) { */ public static KeyStore getKeystoreInstance(String keyStoreType) throws KeyStoreException, NoSuchProviderException { - if (StoreFileType.defaultFileType.equals(keyStoreType)) { + if (StoreFileType.PKCS12.name().equals(keyStoreType)) { return KeyStore.getInstance(keyStoreType, getJCEProvider()); } else { return KeyStore.getInstance(keyStoreType);