Hi I am using below maven dependency in my Spring boot application.
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.16</version>
</dependency>
I am using below command to encrypt my DB password.
encrypt input="test" password=test algorithm=PBEWithMD5AndDES
In my application.properties, i have below properties,
spring.datasource.url=jdbc:sqlserver://localhost:1234;database=TEST_DB
spring.datasource.username=test
spring.datasource.password=ENC(OPdJ9jOw7tbJR+MlptpCHg==)
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.poolName=SpringBootHikariCP
spring.datasource.maximumPoolSize=50
spring.datasource.minimumIdle=30
spring.datasource.maxLifetime=2000000
spring.datasource.connectionTimeout=30000
spring.datasource.idleTimeout=30000
spring.datasource.pool-prepared-statements=true
spring.datasource.max-open-prepared-statements=250
In my application code, i am able to get decrypted value of spring.datasource.password property. But when i use JDBCTemplate
, i am getting below exception.
Edit :
Mistakenly added wrong stacktrace. Below is correct one. Due to 3 unsuccessful attempts, the password got expired.
[ERROR] 2018-09-03 04:50:45.578 [https-jsse-nio-8092-exec-9] util - LOG : Class :Controller|| Method :process || org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'test'. ClientConnectionId:ba0abe4d-014a-42d3-b39e-ec1efc0e7131
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:394)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:494)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:500)
at com.test.dao.AppDaoImpl.generateQuery(AppDaoImpl.java:77)
at com.test.dao.AppDaoImpl$$FastClassBySpringCGLIB$$5d4e5540.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.test.dao.AppDaoImpl$$EnhancerBySpringCGLIB$$eb86c18b.generateQuery(<generated>)
It is not able to login to database. Below is my AppDaoImpl.java
@Repository
public class AppDaoImpl implements AppDao {
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public Integer generateQuery(String id) throws ImpsException {
return jdbcTemplate.update(QueryConst.SQL_INSERT_QUERY, id);
}
}
Before jasypt, i was just autowiring my JDBCTemplate and everything was working fine. Now it is not able to login.
PS: I am running my application with
-Djasypt.encryptor.password=test -Djasypt.encryptor.algorithm=PBEWithMD5AndDES
From the message
Reason: The password of the account has expired.
its clear that password has expired.Log in to SQL server as a system administrator. Change the password to something else. Make sure enforce password policy is off and then change the password back to the original password.
OR
Right click 'Username' and go to Properties
You can find 'Enforce password expiration' on login properties window, which needs to be unchecked.