use of io.apiman.common.util.crypt.DataEncryptionContext in project apiman by apiman.
the class OrganizationResourceImpl method decryptEndpointProperties.
/**
* Decrypt the endpoint properties
*/
private void decryptEndpointProperties(ApiVersionBean versionBean) {
Map<String, String> endpointProperties = versionBean.getEndpointProperties();
if (endpointProperties != null) {
for (Entry<String, String> entry : endpointProperties.entrySet()) {
DataEncryptionContext ctx = new DataEncryptionContext(versionBean.getApi().getOrganization().getId(), versionBean.getApi().getId(), versionBean.getVersion(), EntityType.Api);
entry.setValue(encrypter.decrypt(entry.getValue(), ctx));
}
}
}
use of io.apiman.common.util.crypt.DataEncryptionContext in project apiman by apiman.
the class OrganizationResourceImpl method encryptEndpointProperties.
/**
* Encrypt the endpoint properties
*/
private void encryptEndpointProperties(ApiVersionBean versionBean) {
Map<String, String> endpointProperties = versionBean.getEndpointProperties();
if (endpointProperties != null) {
for (Entry<String, String> entry : endpointProperties.entrySet()) {
DataEncryptionContext ctx = new DataEncryptionContext(versionBean.getApi().getOrganization().getId(), versionBean.getApi().getId(), versionBean.getVersion(), EntityType.Api);
entry.setValue(encrypter.encrypt(entry.getValue(), ctx));
}
}
}
use of io.apiman.common.util.crypt.DataEncryptionContext in project apiman by apiman.
the class GatewayResourceImpl method encryptPasswords.
/**
* @param gateway
*/
private void encryptPasswords(GatewayBean gateway) {
if (gateway.getConfiguration() == null) {
return;
}
try {
if (gateway.getType() == GatewayType.REST) {
RestGatewayConfigBean config = MAPPER.readValue(gateway.getConfiguration(), RestGatewayConfigBean.class);
config.setPassword(encrypter.encrypt(config.getPassword(), new DataEncryptionContext()));
gateway.setConfiguration(MAPPER.writeValueAsString(config));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.apiman.common.util.crypt.DataEncryptionContext in project apiman by apiman.
the class SecureRegistryWrapper method decryptPolicies.
/**
* @param policies
*/
protected void decryptPolicies(String orgId, String entityId, String entityVersion, EntityType entityType, List<Policy> policies) {
if (policies != null) {
DataEncryptionContext ctx = new DataEncryptionContext(orgId, entityId, entityVersion, entityType);
for (Policy policy : policies) {
String encryptedConfig = policy.getPolicyJsonConfig();
policy.setPolicyJsonConfig(encrypter.decrypt(encryptedConfig, ctx));
}
}
}
use of io.apiman.common.util.crypt.DataEncryptionContext in project apiman by apiman.
the class PolicyTemplateUtil method generatePolicyDescription.
/**
* Generates a dynamic description for the given policy and stores the
* result on the policy bean instance. This should be done prior
* to returning the policybean back to the user for a REST call to the
* management API.
* @param policy the policy
* @throws Exception any exception
*/
public static void generatePolicyDescription(PolicyBean policy) throws Exception {
PolicyDefinitionBean def = policy.getDefinition();
PolicyDefinitionTemplateBean templateBean = getTemplateBean(def);
if (templateBean == null) {
return;
}
// $NON-NLS-1$
String cacheKey = def.getId() + "::" + templateBean.getLanguage();
CompiledTemplate template = templateCache.get(cacheKey);
if (template == null) {
template = TemplateCompiler.compileTemplate(templateBean.getTemplate());
templateCache.put(cacheKey, template);
}
try {
// TODO hack to fix broken descriptions - this util should probably not know about encrypted data
String jsonConfig = policy.getConfiguration();
if (CurrentDataEncrypter.instance != null) {
EntityType entityType = EntityType.Api;
if (policy.getType() == PolicyType.Client) {
entityType = EntityType.ClientApp;
} else if (policy.getType() == PolicyType.Plan) {
entityType = EntityType.Plan;
}
DataEncryptionContext ctx = new DataEncryptionContext(policy.getOrganizationId(), policy.getEntityId(), policy.getEntityVersion(), entityType);
jsonConfig = CurrentDataEncrypter.instance.decrypt(jsonConfig, ctx);
}
Map<String, Object> configMap = mapper.readValue(jsonConfig, Map.class);
configMap = new PolicyConfigMap(configMap);
String desc = (String) TemplateRuntime.execute(template, configMap);
policy.setDescription(desc);
} catch (Exception e) {
e.printStackTrace();
// TODO properly log the error
policy.setDescription(templateBean.getTemplate());
}
}
Aggregations