use of org.wso2.carbon.apimgt.core.impl.FileEncryptionUtility in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method resolveToken.
/**
* Get the token after decrypting using {@link FileEncryptionUtility#readFromEncryptedFile(java.lang.String)}
*
* @return service account token
* @throws ServiceDiscoveryException if an error occurs while resolving the token
*/
private String resolveToken(String encryptedTokenFileName) throws ServiceDiscoveryException {
String token;
try {
String externalSATokenFilePath = System.getProperty(FileEncryptionUtility.CARBON_HOME) + FileEncryptionUtility.SECURITY_DIR + File.separator + encryptedTokenFileName;
token = FileEncryptionUtility.getInstance().readFromEncryptedFile(externalSATokenFilePath);
} catch (APIManagementException e) {
String msg = "Error occurred while resolving externally stored token";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
}
return StringUtils.replace(token, "\n", "");
}
use of org.wso2.carbon.apimgt.core.impl.FileEncryptionUtility in project carbon-apimgt by wso2.
the class BundleActivator method start.
@Activate
protected void start(BundleContext bundleContext) {
try {
// Set default timestamp to UTC
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("Etc/UTC"));
Context ctx = jndiContextManager.newInitialContext();
DataSource dataSourceAMDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMDB"));
DAOUtil.initialize(dataSourceAMDB);
boolean isAnalyticsEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getAnalyticsConfigurations().isEnabled();
if (isAnalyticsEnabled) {
DataSource dataSourceStatDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMSTATSDB"));
DAOUtil.initializeAnalyticsDataSource(dataSourceStatDB);
}
WorkflowExtensionsConfigBuilder.build(configProvider);
ServiceDiscoveryConfigBuilder.build(configProvider);
ContainerBasedGatewayConfigBuilder.build(configProvider);
BrokerManager.start();
Broker broker = new BrokerImpl();
BrokerUtil.initialize(broker);
} catch (NamingException e) {
log.error("Error occurred while jndi lookup", e);
}
// deploying default policies
try {
ThrottlerUtil.addDefaultAdvancedThrottlePolicies();
if (log.isDebugEnabled()) {
log.debug("Checked default throttle policies successfully");
}
} catch (APIManagementException e) {
log.error("Error occurred while deploying default policies", e);
}
// securing files
try {
boolean fileEncryptionEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getFileEncryptionConfigurations().isEnabled();
if (fileEncryptionEnabled) {
FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
fileEncryptionUtility.init();
fileEncryptionUtility.encryptFiles();
}
} catch (APIManagementException e) {
log.error("Error occurred while encrypting files", e);
}
}
use of org.wso2.carbon.apimgt.core.impl.FileEncryptionUtility in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method resolveToken.
/**
* Get the token after decrypting using {@link FileEncryptionUtility#readFromEncryptedFile(java.lang.String)}
*
* @return service account token
* @throws ContainerBasedGatewayException if an error occurs while resolving the token
*/
private String resolveToken(String encryptedTokenFileName) throws ContainerBasedGatewayException {
String token;
try {
String externalSATokenFilePath = System.getProperty(FileEncryptionUtility.CARBON_HOME) + FileEncryptionUtility.SECURITY_DIR + File.separator + encryptedTokenFileName;
token = FileEncryptionUtility.getInstance().readFromEncryptedFile(externalSATokenFilePath);
} catch (APIManagementException e) {
String msg = "Error occurred while resolving externally stored token";
throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
return StringUtils.replace(token, "\n", "");
}
use of org.wso2.carbon.apimgt.core.impl.FileEncryptionUtility in project carbon-apimgt by wso2.
the class FileEncryptionUtilityTestCase method testEncryptFiles.
@Test(priority = 2, description = "Test complete flow of encrypting files")
public void testEncryptFiles() throws Exception {
FileEncryptionConfigurations config = new FileEncryptionConfigurations();
List<String> filesToEncrypt = new ArrayList<>();
filesToEncrypt.add(testFileToEncrypt);
config.setFilesToEncrypt(filesToEncrypt);
SecureVault secureVault = Mockito.mock(SecureVault.class);
FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
fileEncryptionUtility.setConfig(config);
fileEncryptionUtility.setAesKeyFileLocation();
fileEncryptionUtility.setSecureVault(secureVault);
Answer nonEncryptedAesKey = invocation -> {
Object[] args = invocation.getArguments();
return args[0];
};
Mockito.when(secureVault.encrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
Mockito.when(secureVault.decrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
fileEncryptionUtility.createAndStoreAESKey();
fileEncryptionUtility.encryptFiles();
Assert.assertTrue(Files.notExists(Paths.get(originalFilePath)));
Assert.assertEquals(fileEncryptionUtility.readFromEncryptedFile(encryptedFilePath), someText);
}
Aggregations