Example usage for org.hibernate.internal.util.config ConfigurationHelper getString

List of usage examples for org.hibernate.internal.util.config ConfigurationHelper getString

Introduction

In this page you can find the example usage for org.hibernate.internal.util.config ConfigurationHelper getString.

Prototype

public static String getString(String name, Map values) 

Source Link

Document

Get the config value as a String

Usage

From source file:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedC3P0ConnectionProvider.java

License:Apache License

/**
 * Overrides parent method to scan and replace encrypted configuration values
 * with their corresponding decrypted values before invoking the parent with
 * them.//from ww w  . j  a va2s  .  com
 * <p>
 * Looks in the configuration for the name with which the PBE encryptor has been
 * registered with {@link HibernatePBEEncryptorRegistry} using the key 
 * {@link ParameterNaming#ENCRYPTOR_REGISTERED_NAME}.
 * Scans the configuration for supported connection configuration values, checks
 * to see if they are encrypted and replaces them with the decrypted values if
 * they are.
 * </p>
 * @throws EncryptionInitializationException If the PBE encryptor registered name
 * configuration cannot be found or if lookup by the registered name does not return
 * a valid encryptor.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void configure(Map configurationValues) {
    final String methodName = "configure : ";

    // Find encryptor registered for config.
    final String encryptorRegisteredName = ConfigurationHelper
            .getString(ParameterNaming.ENCRYPTOR_REGISTERED_NAME, configurationValues);
    if (encryptorRegisteredName == null) {
        throw new EncryptionInitializationException(
                "No encryptor registered in configuration! Encryptor must be registered with property name: "
                        + ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
    }
    LOGGER.info("{} Using Encryptor registered with name: {}", methodName, encryptorRegisteredName);

    final HibernatePBEEncryptorRegistry encryptorRegistry = HibernatePBEEncryptorRegistry.getInstance();
    final PBEStringEncryptor encryptor = encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);

    if (encryptor == null) {
        throw new EncryptionInitializationException(
                "No string encryptor registered for hibernate " + "with name: " + encryptorRegisteredName);
    }
    LOGGER.info("{} Found registered Encryptor, checking connection properties ..", methodName);

    configurationValues.put(AvailableSettings.DRIVER, decryptIfEncrypted(encryptor, AvailableSettings.DRIVER,
            ConfigurationHelper.getString(AvailableSettings.DRIVER, configurationValues)));
    configurationValues.put(AvailableSettings.URL, decryptIfEncrypted(encryptor, AvailableSettings.URL,
            ConfigurationHelper.getString(AvailableSettings.URL, configurationValues)));
    configurationValues.put(AvailableSettings.USER, decryptIfEncrypted(encryptor, AvailableSettings.USER,
            ConfigurationHelper.getString(AvailableSettings.USER, configurationValues)));
    configurationValues.put(AvailableSettings.PASS, decryptIfEncrypted(encryptor, AvailableSettings.PASS,
            ConfigurationHelper.getString(AvailableSettings.PASS, configurationValues)));
    // Let Hibernate do the rest.
    super.configure(configurationValues);
}

From source file:org.redisson.hibernate.JndiRedissonRegionFactory.java

License:Apache License

@Override
protected RedissonClient createRedissonClient(Map properties) {
    String jndiName = ConfigurationHelper.getString(JNDI_NAME, properties);
    if (jndiName == null) {
        throw new CacheException(JNDI_NAME + " property not set");
    }//  w  ww . jav  a  2s  .  c  o  m

    Properties jndiProperties = JndiServiceImpl.extractJndiProperties(properties);
    InitialContext context = null;
    try {
        context = new InitialContext(jndiProperties);
        return (RedissonClient) context.lookup(jndiName);
    } catch (NamingException e) {
        throw new CacheException("Unable to locate Redisson instance by name: " + jndiName, e);
    } finally {
        if (context != null) {
            try {
                context.close();
            } catch (NamingException e) {
                throw new CacheException("Unable to close JNDI context", e);
            }
        }
    }
}

From source file:org.redisson.hibernate.RedissonRegionFactory.java

License:Apache License

protected RedissonClient createRedissonClient(Map properties) {
    Config config = null;// ww  w  .ja v a  2s.com
    if (!properties.containsKey(REDISSON_CONFIG_PATH)) {
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.json");
        if (config == null) {
            config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.yaml");
        }
    } else {
        String configPath = ConfigurationHelper.getString(REDISSON_CONFIG_PATH, properties);
        config = loadConfig(RedissonRegionFactory.class.getClassLoader(), configPath);
        if (config == null) {
            config = loadConfig(configPath);
        }
    }

    if (config == null) {
        throw new CacheException("Unable to locate Redisson configuration");
    }

    return Redisson.create(config);
}