use of org.wso2.carbon.base.api.ServerConfigurationService in project carbon-apimgt by wso2.
the class DefaultApiKeyGenerator method getApiKeySignKeyStore.
private KeyStore getApiKeySignKeyStore(KeyStoreManager keyStoreManager) throws Exception {
KeyStore apiKeySignKeyStore;
ServerConfigurationService config = keyStoreManager.getServerConfigService();
String apiKeySignKeyStoreName = APIUtil.getApiKeySignKeyStoreName();
if (config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_KEYSTORE_FILE.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName)) == null) {
return null;
}
String file = new File(config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_KEYSTORE_FILE.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName))).getAbsolutePath();
KeyStore store = KeyStore.getInstance(config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_KEYSTORE_TYPE.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName)));
String password = config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_KEYSTORE_PASSWORD.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName));
try (FileInputStream in = new FileInputStream(file)) {
store.load(in, password.toCharArray());
apiKeySignKeyStore = store;
}
return apiKeySignKeyStore;
}
use of org.wso2.carbon.base.api.ServerConfigurationService in project carbon-apimgt by wso2.
the class DefaultApiKeyGenerator method buildSignature.
protected byte[] buildSignature(String assertion) throws APIManagementException {
PrivateKey privateKey = null;
// get super tenant's key store manager
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
try {
ServerConfigurationService config = tenantKSM.getServerConfigService();
String apiKeySignKeyStoreName = APIUtil.getApiKeySignKeyStoreName();
String keyStorePassword = config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_PRIVATE_KEY_PASSWORD.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName));
String apiKeySignAlias = config.getFirstProperty(APIConstants.KeyStoreManagement.SERVER_APIKEYSIGN_KEYSTORE_KEY_ALIAS.replaceFirst(APIConstants.KeyStoreManagement.KeyStoreName, apiKeySignKeyStoreName));
KeyStore apiKeySignKeyStore = getApiKeySignKeyStore(tenantKSM);
if (apiKeySignKeyStore != null) {
privateKey = (PrivateKey) apiKeySignKeyStore.getKey(apiKeySignAlias, keyStorePassword.toCharArray());
}
} catch (Exception e) {
throw new APIManagementException("Error while signing Api Key", e);
}
return APIUtil.signJwt(assertion, privateKey, "SHA256withRSA");
}
Aggregations