List of usage examples for org.hibernate.cfg AvailableSettings PASS
String PASS
To view the source code for org.hibernate.cfg AvailableSettings PASS.
Click Source Link
From source file:com.github.carlomicieli.config.ApplicationConfig.java
License:Apache License
/** * Return the data source bean.//w ww. j a v a2 s .c om * @return the data source bean. */ public @Bean DataSource dataSource() { log.info(Arrays.asList(env.getActiveProfiles()).toString()); ComboPooledDataSource ds = new ComboPooledDataSource(); try { ds.setDriverClass(env.getProperty(AvailableSettings.DRIVER)); } catch (Exception e) { throw new RuntimeException(e); } ds.setJdbcUrl(env.getProperty(AvailableSettings.URL)); ds.setUser(env.getProperty(AvailableSettings.USER)); ds.setPassword(env.getProperty(AvailableSettings.PASS)); return ds; }
From source file:com.vmware.photon.controller.apife.db.MigrationTest.java
License:Open Source License
@Test public void testMigrations() throws SQLException, LiquibaseException { try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:migrations", "sa", "")) { Liquibase liquibase = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection)); liquibase.update(""); Configuration configuration = new Configuration(); Reflections reflections = new Reflections("com.vmware.photon.controller.apife.entities"); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class); Reflections commonReflections = new Reflections("com.vmware.photon.controller.api.common"); classes.addAll(commonReflections.getTypesAnnotatedWith(Entity.class)); for (final Class<?> clazz : classes) { configuration.addAnnotatedClass(clazz); }//ww w.j a v a 2s . c o m configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "thread"); configuration.setProperty(AvailableSettings.DIALECT, "org.hibernate.dialect.H2Dialect"); configuration.setProperty(AvailableSettings.DRIVER, "org.h2.Driver"); configuration.setProperty(AvailableSettings.URL, "jdbc:h2:mem:migrations"); configuration.setProperty(AvailableSettings.USER, "sa"); configuration.setProperty(AvailableSettings.PASS, ""); configuration.setProperty(AvailableSettings.HBM2DDL_AUTO, "validate"); configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory factory = configuration.buildSessionFactory(serviceRegistry); factory.close(); } }
From source file:com.zaxxer.hikari.hibernate.HikariConfigurationUtil.java
License:Apache License
/** * Create/load a HikariConfig from Hibernate properties. * * @param props a map of Hibernate properties * @return a HikariConfig// w ww .j a v a 2 s . c o m */ @SuppressWarnings("rawtypes") public static HikariConfig loadConfiguration(Map props) { Properties hikariProps = new Properties(); copyProperty(AvailableSettings.ISOLATION, props, "transactionIsolation", hikariProps); copyProperty(AvailableSettings.AUTOCOMMIT, props, "autoCommit", hikariProps); copyProperty(AvailableSettings.DRIVER, props, "driverClassName", hikariProps); copyProperty(AvailableSettings.URL, props, "jdbcUrl", hikariProps); copyProperty(AvailableSettings.USER, props, "username", hikariProps); copyProperty(AvailableSettings.PASS, props, "password", hikariProps); for (Object keyo : props.keySet()) { String key = (String) keyo; if (key.startsWith(CONFIG_PREFIX)) { hikariProps.setProperty(key.substring(CONFIG_PREFIX.length()), (String) props.get(key)); } } return new HikariConfig(hikariProps); }
From source file:name.livitski.tools.persista.StorageBootstrap.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateSchema() throws ApplicationBeanException { try {//from w w w . ja v a 2 s . c om String user = readSetting(UpdaterUserNameSetting.class); String password; if (null != user) password = readSetting(UpdaterPasswordSetting.class); else { user = readSetting(UserNameSetting.class); password = readSetting(PasswordSetting.class); } org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration(); cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "update"); cfg.setProperty(AvailableSettings.DIALECT, readSetting(HibernateSQLDialectSetting.class).getName()); cfg.setProperty(AvailableSettings.DRIVER, getJDBCDriverClass().getName()); cfg.setProperty(AvailableSettings.URL, db.getMetaData().getURL()); cfg.setProperty(AvailableSettings.USER, user); cfg.setProperty(AvailableSettings.PASS, password); for (Class<?> clazz : getEntityClasses()) cfg.addAnnotatedClass(clazz); SchemaUpdate worker = new SchemaUpdate(cfg); worker.setDelimiter(";"); worker.setHaltOnError(true); if (null != ddlDumpFile) worker.setOutputFile(ddlDumpFile.getAbsolutePath()); worker.execute(true, true); List<Throwable> errs = (List<Throwable>) worker.getExceptions(); if (null != errs && !errs.isEmpty()) for (Iterator<Throwable> erri = errs.iterator();;) { Throwable err = erri.next(); if (erri.hasNext()) log().error("", err); else throw new SchemaUpdateException(this, "Error(s) occured during the schema update, the last error is shown.", err); } } catch (ConfigurationException badConfig) { throw new StorageConfigurationException(this, badConfig); } catch (SQLException e) { throw new DatabaseException(this, e); } }
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.// w w w . j a v a2 s.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:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedDriverManagerConnectionProviderImplTest.java
License:Apache License
/** * Verifies requirement for configuration of name encryptor is registered * with is enforced.//ww w . j a v a2 s. c om */ @Test(expected = EncryptionInitializationException.class) public final void testEncryptorRegisteredNameReqd() { // Initialize config values without encryptor registered name. Map<String, String> testConfigValues = new HashMap<String, String>(); testConfigValues.put(AvailableSettings.DRIVER, testEncryptedCfgDriver); testConfigValues.put(AvailableSettings.URL, testEncryptedCfgUrl); testConfigValues.put(AvailableSettings.USER, testEncryptedCfgUser); testConfigValues.put(AvailableSettings.PASS, testEncryptedCfgPass); // Initialize test instance and invoke target method which should // fail with the expected exception. testCPImpl = new EncryptedDriverManagerConnectionProviderImpl(); testCPImpl.configure(testConfigValues); }
From source file:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedDriverManagerConnectionProviderImplTest.java
License:Apache License
/** * Verifies decryption of encrypted configuration values for supported * configuration parameters and confirms there are no other side effects. *//* ww w .jav a2 s . c o m*/ @Test public final void testConfigureDecryption() { // Set mock expectations to be auto-validated. final Sequence decryptSequence = context.sequence("decryptSequence"); context.checking(new Expectations() { { oneOf(mockEncryptor).decrypt(testEncryptedDriverText); inSequence(decryptSequence); will(returnValue(testDriver)); oneOf(mockEncryptor).decrypt(testEncryptedUrlText); inSequence(decryptSequence); will(returnValue(testUrl)); oneOf(mockEncryptor).decrypt(testEncryptedUserText); inSequence(decryptSequence); will(returnValue(testUser)); oneOf(mockEncryptor).decrypt(testEncryptedPassText); inSequence(decryptSequence); will(returnValue(testPassword)); } }); // Setup test configuration. Map<String, String> testConfigValues = new HashMap<String, String>(); testConfigValues.put(ParameterNaming.ENCRYPTOR_REGISTERED_NAME, testEncryptorCfgName); testConfigValues.put(AvailableSettings.DRIVER, testEncryptedCfgDriver); testConfigValues.put(AvailableSettings.URL, testEncryptedCfgUrl); testConfigValues.put(AvailableSettings.USER, testEncryptedCfgUser); testConfigValues.put(AvailableSettings.PASS, testEncryptedCfgPass); // Track values to be asserted later in the test. int cfgsCt = testConfigValues.size(); // Initialize the test instance and invoke target method to trigger mock expectation assertion. testCPImpl = new EncryptedDriverManagerConnectionProviderImpl(); testCPImpl.configure(testConfigValues); // Mock expectations should have already verified decryption, now proceed // with manual assertions. // First, verify that the decrypted values were set in the cfg values map // since it gets passed to super to complete actual configuration. assertEquals("Cfg values map not updated with decrypted driver!", testDriver, testConfigValues.get(AvailableSettings.DRIVER)); assertEquals("Cfg values map not updated with decrypted url!", testUrl, testConfigValues.get(AvailableSettings.URL)); assertEquals("Cfg values map not updated with decrypted user!", testUser, testConfigValues.get(AvailableSettings.USER)); assertEquals("Cfg values map not updated with decrypted password!", testPassword, testConfigValues.get(AvailableSettings.PASS)); // Now verify there were no other modifications to config values. assertEquals("Unexpected no. of config values!", cfgsCt, testConfigValues.size()); assertEquals("Config value other than encryptable set modified!", testEncryptorCfgName, testConfigValues.get(ParameterNaming.ENCRYPTOR_REGISTERED_NAME)); }
From source file:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedDriverManagerConnectionProviderImplTest.java
License:Apache License
/** * Verifies that unencrypted values for supported configuration parameters * are passed through unchanged. /*w ww .j a va 2 s .c o m*/ */ @Test public final void testConfigurePassThrough() { // Setup test configuration. Map<String, String> testConfigValues = new HashMap<String, String>(); testConfigValues.put(ParameterNaming.ENCRYPTOR_REGISTERED_NAME, testEncryptorCfgName); testConfigValues.put(AvailableSettings.DRIVER, testDriver); testConfigValues.put(AvailableSettings.URL, testUrl); testConfigValues.put(AvailableSettings.USER, testUser); testConfigValues.put(AvailableSettings.PASS, testPassword); // Track values to be asserted later in the test. int cfgsCt = testConfigValues.size(); // Initialize the test instance and invoke target method. Mock // expectations aren't set since encryptor should never be invoked // in this case. testCPImpl = new EncryptedDriverManagerConnectionProviderImpl(); testCPImpl.configure(testConfigValues); // Verify that the specified values are unchanged. assertEquals("Cfg values map for driver modified!", testDriver, testConfigValues.get(AvailableSettings.DRIVER)); assertEquals("Cfg values map for url modified!", testUrl, testConfigValues.get(AvailableSettings.URL)); assertEquals("Cfg values map for user modified!", testUser, testConfigValues.get(AvailableSettings.USER)); assertEquals("Cfg values map for password modified!", testPassword, testConfigValues.get(AvailableSettings.PASS)); // Now verify there were no other modifications to config values. assertEquals("Unexpected no. of config values!", cfgsCt, testConfigValues.size()); assertEquals("Config value other than encryptable set modified!", testEncryptorCfgName, testConfigValues.get(ParameterNaming.ENCRYPTOR_REGISTERED_NAME)); }
From source file:org.jasypt.hibernate4.connectionprovider.EncryptedPasswordC3P0ConnectionProvider.java
License:Apache License
public void configure(final Properties props) { final String encryptorRegisteredName = props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME); 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 + "\""); }//from ww w . ja v a2 s . c om // Get the original values, which may be encrypted final String driver = props.getProperty(AvailableSettings.DRIVER); final String url = props.getProperty(AvailableSettings.URL); final String user = props.getProperty(AvailableSettings.USER); final String password = props.getProperty(AvailableSettings.PASS); // Perform decryption operations as needed and store the new values if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) { props.setProperty(AvailableSettings.DRIVER, PropertyValueEncryptionUtils.decrypt(driver, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(url)) { props.setProperty(AvailableSettings.URL, PropertyValueEncryptionUtils.decrypt(url, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(user)) { props.setProperty(AvailableSettings.USER, PropertyValueEncryptionUtils.decrypt(user, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(password)) { props.setProperty(AvailableSettings.PASS, PropertyValueEncryptionUtils.decrypt(password, encryptor)); } // Let Hibernate do the rest super.configure(props); }
From source file:org.jasypt.hibernate4.connectionprovider.EncryptedPasswordDriverManagerConnectionProvider.java
License:Apache License
public void configure(final Properties props) { final String encryptorRegisteredName = props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME); 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 + "\""); }/* www . j a va 2 s . c om*/ // Get the original values, which may be encrypted final String driver = props.getProperty(AvailableSettings.DRIVER); final String url = props.getProperty(AvailableSettings.URL); final String user = props.getProperty(AvailableSettings.USER); final String password = props.getProperty(AvailableSettings.PASS); // Perform decryption operations as needed and store the new values if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) { props.setProperty(AvailableSettings.DRIVER, PropertyValueEncryptionUtils.decrypt(driver, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(url)) { props.setProperty(AvailableSettings.URL, PropertyValueEncryptionUtils.decrypt(url, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(user)) { props.setProperty(AvailableSettings.USER, PropertyValueEncryptionUtils.decrypt(user, encryptor)); } if (PropertyValueEncryptionUtils.isEncryptedValue(password)) { props.setProperty(AvailableSettings.PASS, PropertyValueEncryptionUtils.decrypt(password, encryptor)); } // Let Hibernate process super.configure(props); }