spring security如何验证密码(凭据)?
我完成了这项工作,但不太了解其背后的过程:spring security如何验证密码(凭据)?,spring,spring-security,Spring,Spring Security,我完成了这项工作,但不太了解其背后的过程: <!-- Authentication Manager --> <sec:authentication-manager alias="authenticationManager"> <sec:authentication-provider user-service-ref="customUserDetailsService"> <sec:password-encoder ref="enc
<!-- Authentication Manager -->
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider user-service-ref="customUserDetailsService">
<sec:password-encoder ref="encoder"/>
</sec:authentication-provider>
</sec:authentication-manager>
<bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder">
用户服务基本上只是使用用户的姓名验证用户,而不验证其密码。但是密码编码器
确实验证了密码,那么Spring如何将编码器与用户
实体的密码列相关联呢?验证用户密码的过程在哪里
问题2
如何自定义密码验证过程以截获解密的密码?您的
用户
类应该已经实现了方法getPassword()
。由于它是一个Spring接口,他们在需要时调用此方法。接受的答案对我不起作用,我必须创建一个自定义的org.springframework.security.authentication.AuthenticationProvider实现。
您在哪里定义了编码器bean?将其发布为well@dhamibirendra谢谢张贴。但这有关系吗?是否有任何方法可以拦截用户输入到应用程序的解密密码?请尝试以下操作:SecurityContextHolder.getContext().getAuthentication().getCredentials()
。它将返回,即密码。
@Component("customUserDetailsService")
public class CustomUserDetailsService implements UserDetailsService {
............
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
User user = userService.findByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("User '"+username+"' not found !");
}
return user;
}
}