Có đơn giản webapp Xuân An với mã hóa mật khẩu:Authentication trong Xuân An whith mật khẩu được mã hóa
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="personService">
<security:password-encoder hash="md5" ref="passwordEncoder">
<!-- <security:salt-source user-property="username"/> -->
</security:password-encoder>
</security:authentication-provider>
</security:authentication-manager>
Encoding cũng đơn giản:
person.setPassword(encoder.encodePassword(person.getPassword(), null));
Vì vậy, trong DataBase tất cả mật khẩu sẽ được mã hóa. Bây giờ tôi muốn thực hiện xác thực của một số người dùng với tên người dùng nhất định trong apllication. Trước (khi passswords là trong bản rõ) nó là như thế này:
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
username, password);
Authentication authentication = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
Nhưng bây giờ tôi nhận được mã hóa mật khẩu từ DB và không thể làm thẩm định như trước đây.
Sự cố. rằng Spring không biết rằng mật khẩu cames từ UsernamePasswordAuthenticationToken đã được mã hóa. Và anh ta mã hóa nó lần thứ hai. Ai có thể giúp đỡ?
Sửa
Vì vậy, tôi thấy hai giải pháp ở đây:
- thực hiện DaoAuthenticationProvider tùy chỉnh nơi thêm séc nếu cả hai mật khẩu đã băm
- thực hiện xác thực tùy chỉnh và đặt nó trong bối cảnh an ninh bằng tay.
Mọi người khác? Cai gi la tot nhat?
Bao gồm một số SpringSecurity trong [chi tiết ở đây] (http://techastute.blogspot.com /2013/01/spring-security-in-detail.html), có thể hữu ích cho một số. – raksja