【发布时间】:2012-02-09 22:40:54
【问题描述】:
Spring Security 3.1 有一个漂亮而方便的方法来在 XML 配置中包含所需的哈希,这就像一个魅力:
<bean id="securityDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/myDataSource"/>
<property name="resourceRef" value="true"/>
</bean>
<bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder" />
<security:authentication-manager>
<security:authentication-provider>
<security:password-encoder ref="encoder" />
<security:jdbc-user-service
data-source-ref="securityDataSource"
authorities-by-username-query="SELECT username, authority FROM user_roles WHERE username = ?"
users-by-username-query="SELECT username, password, enabled FROM users WHERE username = ?"
/>
</security:authentication-provider>
</security:authentication-manager>
我查看了这个 StandardPasswordEncoder 类,它有两个适用的公共方法:encode() 和 matches()。 match() 方法大概是 spring 用来比较输入密码的散列版本和数据库中的散列密码。 encode() 方法似乎用于生成哈希字符串以存储在数据库中。我假设您可以使用它来随意生成或更改密码。
我的问题是:如果有完全正当的理由这样做,用双向加密方法替换这个哈希会有多困难(或者说有可能)?我不想牺牲此 Spring 安全配置提供的所有功能和便利性,但有必要(根据业务用户)随意访问纯文本密码。
【问题讨论】:
标签: spring encryption hash passwords spring-security