我有一个基于Seam框架构建的webapp,我目前正在使用基于Spring的新webapp替换它。我们用户的登录信息存储在数据库中,并使用盐渍哈希进行加密。这些是当前在Seam应用程序中生成的:
PasswordHash.instance().generateSaltedHash(plainTextPassword, saltPhrase, "SHA")
我遇到的问题是新的Spring应用程序必须使用相同的登录,而且我无法复制密码散列。我目前有这个SecurityConfig类:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDAO userDAO;
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
for (AdminUser u : userDAO.getAdminUsers()) {
System.out.println("Granting access to login: " + u.getLogin()
+ " password: " + u.getPassword());
auth.inMemoryAuthentication().withUser(u.getLogin())
.password(u.getPassword()).roles("USER");
}
}
}
任何帮助将不胜感激。如果您需要查看任何额外的代码,请添加评论。
答案 0 :(得分:0)
配置spring security以从给定表中读取用户的方法是DaoAuthenticationProvider
,请参见official docs。
支持定义如何进行散列和salting,下面是XML的样子:
<bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="inMemoryDaoImpl"/>
<property name="saltSource" ref="saltSource"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>
在Java配置中,在configure方法中,可以实例化DaoAuthenticationProvider
,配置它并使用API AuthenticationManagerBuilder
将其传递给auth.authenticationProvider(...)
。