私のアプリケーションにユーザーのログイン確認機能を追加したいと思います。私のウェブサイトは複雑なハッシュを使って本物のパスワードを正規に変換し、それをデータベースに保存する別のものに基づいています。定期的には、塩を作成し、このように、ユーザテーブルに保存します。今Spring SecurityのJdbcAuthenticationのデータベースからユーザのデータを取得するには?
User user = dao.find(username);
password = HashKit.sha256(user.getSalt() + password);
if (password.equels(user.getPassword())){ Login Success! }
しかし、ユーザがログインすると、元のアプリケーションは、このようなデータベースからの塩を取得します
String salt = HashKit.generateSaltForSha256();
password = HashKit.sha256(salt + password);
user.setPassword(password).setSalt(salt).save();
私はPasswordEncoder
でデータベースからユーザーデータを取得できますか
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DruidPlugin druidPlugin;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(druidPlugin.getDataSource())
.usersByUsernameQuery(
"select userName username, password, true from account where userName=?"
)
.authoritiesByUsernameQuery(
"select userName username, 'ROLE_USER' from account where userName=?"
)
.passwordEncoder(new PasswordEncoder() {
@Override
public String encode(CharSequence password) {
String salt = HashKit.generateSaltForSha256();
password = HashKit.sha256(salt + password);
return password.toString();
}
@Override
public boolean matches(CharSequence charSequence, String s) {
return false;
}
});
}
}
:私は、そのアプリケーションを書き換えて、このようなログインを検証するために春のセキュリティを使用するように春のブートを使用するようにしたいですか?