use of io.apiman.common.util.crypt.DataEncryptionContext.EntityType 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());
}
}
use of io.apiman.common.util.crypt.DataEncryptionContext.EntityType in project apiman by apiman.
the class PolicyBean method encryptData.
@PrePersist
@PreUpdate
protected void encryptData() {
// Encrypt the endpoint properties.
EntityType entityType = EntityType.Api;
if (type == PolicyType.Client) {
entityType = EntityType.ClientApp;
} else if (type == PolicyType.Plan) {
entityType = EntityType.Plan;
}
DataEncryptionContext ctx = new DataEncryptionContext(organizationId, entityId, entityVersion, entityType);
configuration = CurrentDataEncrypter.instance.encrypt(configuration, ctx);
}
use of io.apiman.common.util.crypt.DataEncryptionContext.EntityType in project apiman by apiman.
the class PolicyBean method decryptData.
@PostPersist
@PostUpdate
@PostLoad
protected void decryptData() {
// Decrypt the endpoint properties.
EntityType entityType = EntityType.Api;
if (type == PolicyType.Client) {
entityType = EntityType.ClientApp;
} else if (type == PolicyType.Plan) {
entityType = EntityType.Plan;
}
DataEncryptionContext ctx = new DataEncryptionContext(organizationId, entityId, entityVersion, entityType);
configuration = CurrentDataEncrypter.instance.decrypt(configuration, ctx);
}
Aggregations