Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.connection.provider_class">mypack.EncryptedPasswordC3P0ConnectionProvider</property>
- <property name="hibernate.connection.encryptor_registered_name">strongHibernateStringEncryptor</property>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=utf-8</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">ENC(Sq/CFOKQudnXQ8SjuS4t+Q==)</property>
- <property name="c3p0.min_size">5</property>
- <property name="c3p0.max_size">20</property>
- <property name="c3p0.timeout">1800</property>
- <property name="c3p0.max_statements">50</property>
- <mapping resource="user.hbm.xml" />
- </session-factory>
- </hibernate-configuration>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd">
- <context:component-scan base-package="mypack">
- <context:exclude-filter type="annotation"
- expression="org.springframework.stereotype.Controller"/>
- </context:component-scan>
- <context:property-placeholder /><!--enable accessing system environment
- variables-->
- <tx:annotation-driven transaction-manager="transactionManager"/>
- <!--
- This is the key to link Spring's injection to Hibernate event-based
- validation.
- Notice the first constructor argument, this is our Spring ValidatorFactory
- instance.
- -->
- <bean id="customInitialize" class="mypack.CustomInitialize">
- <property name="encryptorPasswordVariable"
- value="MAIL_SERVICE_3DES_PASSWORD"/>
- </bean>
- <bean id="hibernateStringEncryptor"
- class="org.jasypt.hibernate4.encryptor.HibernatePBEStringEncryptor">
- <property name="registeredName" value="strongHibernateStringEncryptor"/>
- <property name="algorithm" value="PBEWithMD5AndTripleDES"/>
- <property name="password" value="${MAIL_SERVICE_3DES_PASSWORD}"/>
- </bean>
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <bean id="sessionFactory" depends-on="hibernateStringEncryptor"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <property name="configLocation" value="hibernate.cfg.xml"/>
- <property name="packagesToScan" value="mypack"/>
- <property name="hibernateProperties"
- value="org.hibernate.dialect.MySQLDialect">
- <props>
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <prop
- key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <prop key="hibernate.connection.CharSet">utf8</prop>
- <prop key="hibernate.connection.characterEncoding">utf8</prop>
- <prop key="hibernate.connection.useUnicode">true</prop>
- <prop key="hibernate.show_sql">true</prop>
- <prop key="hibernate.format_sql">true</prop>
- <prop key="hibernate.cache.use_second_level_cache">true</prop>
- <prop key="hibernate.cache.use_query_cache">true</prop>
- <prop key="hibernate.generate_statistics">false</prop>
- <prop key="javax.persistence.validation.mode">none</prop>
- </props>
- </property>
- </bean>
- package mypack;
- import java.util.Properties;
- import org.hibernate.c3p0.internal.C3P0ConnectionProvider;
- import org.hibernate.cfg.AvailableSettings;
- import org.jasypt.encryption.pbe.PBEStringEncryptor;
- import org.jasypt.exceptions.EncryptionInitializationException;
- import org.jasypt.hibernate4.connectionprovider.ParameterNaming;
- import org.jasypt.hibernate4.encryptor.HibernatePBEEncryptorRegistry;
- import org.jasypt.properties.PropertyValueEncryptionUtils;
- public class EncryptedPasswordC3P0ConnectionProvider extends
- C3P0ConnectionProvider {
- private static final long serialVersionUID = 5273353009914873806L;
- public EncryptedPasswordC3P0ConnectionProvider() {
- super();
- }
- public void configure(final Properties props) {
- final String encryptorRegisteredName =
- (String)props.get(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 + """);
- }
- final String driver = (String) props.get(AvailableSettings.DRIVER);
- final String url = (String) props.get(AvailableSettings.URL);
- final String user = (String) props.get(AvailableSettings.USER);
- final String password = (String) props.get(AvailableSettings.PASS);
- if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
- props.put(AvailableSettings.DRIVER,
- PropertyValueEncryptionUtils.decrypt(driver, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
- props.put(AvailableSettings.URL,
- PropertyValueEncryptionUtils.decrypt(url, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
- props.put(AvailableSettings.USER,
- PropertyValueEncryptionUtils.decrypt(user, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
- props.put(AvailableSettings.PASS,
- PropertyValueEncryptionUtils.decrypt(password, encryptor));
- }
- super.configure(props);
- }
- }
- package mypack;
- import org.springframework.beans.factory.InitializingBean;
- import org.springframework.stereotype.Component;
- @Component
- public class CustomInitialize implements InitializingBean {
- private String encryptorPasswordVariable;
- public void afterPropertiesSet() throws Exception {
- if (encryptorPasswordVariable != null) {
- Runtime runtime = Runtime.getRuntime();
- runtime.exec("setx " + encryptorPasswordVariable+ " "" /M");
- }
- }
- public String getEncryptorPasswordVariable() {
- return encryptorPasswordVariable;
- }
- public void setEncryptorPasswordVariable(String encryptorPassword) {
- this.encryptorPasswordVariable= encryptorPassword;
- }
- }
Add Comment
Please, Sign In to add comment