Search in sources :

Example 1 with DataEncryptionContext

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

Example 2 with DataEncryptionContext

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

Example 3 with DataEncryptionContext

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);
    }
}
Also used : DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) RestGatewayConfigBean(io.apiman.manager.api.beans.gateways.RestGatewayConfigBean) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) GatewayAlreadyExistsException(io.apiman.manager.api.rest.exceptions.GatewayAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException)

Example 4 with DataEncryptionContext

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));
        }
    }
}
Also used : Policy(io.apiman.gateway.engine.beans.Policy) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext)

Example 5 with DataEncryptionContext

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());
    }
}
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)

Aggregations

DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)11 EntityType (io.apiman.common.util.crypt.DataEncryptionContext.EntityType)3 Policy (io.apiman.gateway.engine.beans.Policy)2 RestGatewayConfigBean (io.apiman.manager.api.beans.gateways.RestGatewayConfigBean)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)2 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)2 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)2 GatewayAlreadyExistsException (io.apiman.manager.api.rest.exceptions.GatewayAlreadyExistsException)2 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)2 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)2 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)2 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