Search in sources :

Example 1 with RestGatewayConfigBean

use of io.apiman.manager.api.beans.gateways.RestGatewayConfigBean 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 2 with RestGatewayConfigBean

use of io.apiman.manager.api.beans.gateways.RestGatewayConfigBean in project apiman by apiman.

the class GatewayResourceImpl method decryptPasswords.

/**
 * @param gateway
 */
private void decryptPasswords(GatewayBean gateway) {
    if (gateway.getConfiguration() == null) {
        return;
    }
    try {
        if (gateway.getType() == GatewayType.REST) {
            // TODO(msavy): how was this ever working?
            String workingConf = gateway.getConfiguration();
            if (gateway.getConfiguration().startsWith("$CRYPT::")) {
                workingConf = encrypter.decrypt(gateway.getConfiguration(), new DataEncryptionContext());
            }
            RestGatewayConfigBean config = MAPPER.readValue(workingConf, RestGatewayConfigBean.class);
            config.setPassword(encrypter.decrypt(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)

Aggregations

DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)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