Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring security如何验证密码(凭据)?_Spring_Spring Security - Fatal编程技术网

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;
    }

}