HI , I have encryptyed the database password using jasypt and followed the steps mentioned in the jasypt doc. I see the password being decrypted in the logs and am able to get the connection to retrieve other hibernate objects however in the QuartzDataSource configuration when I inject the same sessionFactory it cannot get the connection to the database and throws this error.
java.sql.SQLException: Can't allocate JDBC connection QuartzDataSource.getConnection(QuartzDataSource.java:101) at org.quartz.utils.DBConnectionManager.getConnection(DBConnectionManager.java:111) at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:553) at org.quartz.impl.jdbcjobstore.JobStoreTX.acquireNextTrigger(JobStoreTX.java:1169) at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:233)
Here is my configuration: db-cfg.xml <hibernate-configuration> <session-factory name="hibernateSessionFactory"> <property name="connection.provider_class"> org.jasypt.hibernate.connectionprovider.EncryptedPasswordDriverManagerConnectionProvider </property> <property name="connection.encryptor_registered_name">myHibernateEncryptor</property> <property name="hibernate.connection.username">admin</property> <property name="hibernate.connection.password">ENC(M8ieDrGgEWj8x7a6X00baA==)</property> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1/cemdb</property> </session-factory> </hibernate-configuration>
data-objects.xml <bean id="hibernateStringEncryptor" class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor"> <property name="registeredName"> <value>myHibernateEncryptor</value> </property> <property name="algorithm"> <value>PBEWithMD5AndDES</value> </property> <property name="password"> <value>pwdkey</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocations"> <list> <value>classpath:hibernate.cfg.xml</value> </list> </property> </bean>
jsayptHibernateTypes.hbm.xml <hibernate-mapping>
<!-- VARCHAR, CLOB, TEXT based types --> <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType"> <param name="encryptorRegisteredName">myHibernateEncryptor</param> </typedef> </hibernate-mapping>
mapping in hibernate.cfg.xml
<mapping resource="jasyptHibernateTypes.hbm.xml "/>
NOTE: When I remove the encryption quartz is able to obtain a connection to the database.
Here is the snippet of the code that gets the connection. Remember that sessionFactory is injected in here....
public Connection getConnection() throws SQLException { Connection conn = null;
synchronized (sessions) { if (stopping) throw new SQLException("Tess terminating");
// clean up sessions with closed connections cleanupSessions();
// allocate a new session/connection for (int i = 0; i < sessions.length; ++i) { if (sessions[i] == null) { if (sessionFactory != null) { sessions[i] = (SessionImpl) sessionFactory.openSession(); conn = sessions[i].getJDBCContext().getConnectionManager().getConnection(); } break; } } }
Any ideas/suggestions as to whats going on .
Thanks in advance. Noel.
|