无法使用Jasypt登录数据库 [英] Unable to login DB using jasypt
问题描述
我在Spring引导应用程序中使用了以下Maven依赖项.
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
在我的application.properties中,我具有以下属性,
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
在我的应用程序代码中,我能够获取spring.datasource.password属性的解密值.但是当我使用JDBCTemplate
时,我遇到了异常.
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.
错误地添加了错误的堆栈跟踪.下面是正确的一个.由于3次失败尝试,密码已过期.
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>)
它无法登录数据库.下面是我的AppDaoImpl.java
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);
}
}
在进行jasypt之前,我只是自动装配JDBCTemplate,并且一切正常.现在它无法登录.
Before jasypt, i was just autowiring my JDBCTemplate and everything was working fine. Now it is not able to login.
PS:我正在使用
-Djasypt.encryptor.password=test -Djasypt.encryptor.algorithm=PBEWithMD5AndDES
推荐答案
从消息Reason: The password of the account has expired.
中可以清楚地看到密码已过期.
From the message Reason: The password of the account has expired.
its clear that password has expired.
以系统管理员身份登录到SQL Server.将密码更改为其他密码.确保已禁用强制密码策略,然后将密码更改回原始密码.
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.
这篇关于无法使用Jasypt登录数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!