Announcement Announcement Module
Collapse
No announcement yet.
not able to decrypt password placed in a properties file with spring jasypt need help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • not able to decrypt password placed in a properties file with spring jasypt need help

    Hi There,

    i am using the below code threads to decrypt an encrypted password which is placed in a properties file.

    spring-context.xml

    <bean class="org.jasypt.spring.properties.EncryptablePro pertyPlaceholderConfigurer">
    <property name="location" value="classpath:/test.properties" />
    <constructor-arg ref="encryptor" />
    </bean>


    <bean id="encryptor" class="org.jasypt.encryption.pbe.StandardPBEString Encryptor">
    <property name="config" ref="environmentConfig"/>
    </bean>

    <bean id="environmentConfig" class="org.jasypt.encryption.pbe.config.Environmen tStringPBEConfig">
    <property name="algorithm" value="PBEWithMD5AndDES"/>
    <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD"/>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource"> -->
    <property name="driverClassName" value="${dbDriver}" />
    <property name="url" value="${dbURI}" />
    <property name="username" value="${DB_USER}" />
    <property name="password" value="${DB_PASSWORD}" />
    </bean>

    test.properties

    dbURI=jdbc:sqlserver://<hostname>:<port>;databaseName=test
    dbDriver=com.microsoft.sqlserver.jdbc.SQLServerDri ver
    DB_USER=test
    DB_PASSWORD=ENC(encryptedpasswordhere)

    error trace:

    org.springframework.transaction.CannotCreateTransa ctionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user 'test'.)
    at org.springframework.jdbc.datasource.DataSourceTran sactionManager.doBegin(DataSourceTransactionManage r.java:241)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.getTransaction(AbstractPl atformTransactionManager.java:372)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.createTransactionIfNecessary(Tr ansactionAspectSupport.java:417)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.invokeWithinTransaction(Transac tionAspectSupport.java:255)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:94)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy5.getLastJobExecution(Unknown Source)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:94)
    at com.test.MyJobLauncherJobLauncher.jobLauncher(MyJo bLauncherJobLauncher.java:26)
    at com.test.MyMainClass.main(MyMainClass.java:21)
    Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user 'test'.)
    at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1225)
    at org.apache.commons.dbcp.BasicDataSource.getConnect ion(BasicDataSource.java:880)
    at org.springframework.jdbc.datasource.DataSourceTran sactionManager.doBegin(DataSourceTransactionManage r.java:203)
    ... 10 more
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'test'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.ma keFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF (Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unkno wn Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.s endLogon(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.l ogon(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.a ccess$000(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$L ogonCommand.doExecute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Un known Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.e xecuteCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.c onnectHelper(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.l oginWithoutFailover(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.c onnect(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.conne ct(Unknown Source)
    at org.apache.commons.dbcp.DriverConnectionFactory.cr eateConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory. makeObject(PoolableConnectionFactory.java:294)
    at org.apache.commons.dbcp.BasicDataSource.validateCo nnectionFactory(BasicDataSource.java:1247)
    at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1221)
    ... 12 more

    please advice if anyone has come across this scenario or related.

    Thanks
    Last edited by yes.krishna2; Jul 12th, 2013, 08:18 AM. Reason: eliminate specific tags

  • #2
    i could achieve this with an alternate solution.

    Solution : extend org.springframework.jdbc.datasource.DriverM anagerDataSource and overide the getPassword() method to decrypt the password.

    Comment

    Working...
    X