Search in sources :

Example 1 with EntityType

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());
    }
}
Also used : PolicyDefinitionTemplateBean(io.apiman.manager.api.beans.policies.PolicyDefinitionTemplateBean) EntityType(io.apiman.common.util.crypt.DataEncryptionContext.EntityType) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 2 with EntityType

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);
}
Also used : EntityType(io.apiman.common.util.crypt.DataEncryptionContext.EntityType) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 3 with EntityType

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);
}
Also used : EntityType(io.apiman.common.util.crypt.DataEncryptionContext.EntityType) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PostLoad(javax.persistence.PostLoad) PostUpdate(javax.persistence.PostUpdate) PostPersist(javax.persistence.PostPersist)

Aggregations

DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)3 EntityType (io.apiman.common.util.crypt.DataEncryptionContext.EntityType)3 PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)1 PolicyDefinitionTemplateBean (io.apiman.manager.api.beans.policies.PolicyDefinitionTemplateBean)1 PostLoad (javax.persistence.PostLoad)1 PostPersist (javax.persistence.PostPersist)1 PostUpdate (javax.persistence.PostUpdate)1 PrePersist (javax.persistence.PrePersist)1 PreUpdate (javax.persistence.PreUpdate)1 CompiledTemplate (org.mvel2.templates.CompiledTemplate)1