0

嗨,我正在尝试手动进行身份验证,并希望为 Spring 安全性保存用户详细信息。但是我在下面给出的代码中遇到了这个异常

Authentication auth = authManager.authenticate(authReq);

例外 -

org.springframework.security.authentication.BadCredentialsException: Bad credentials

服务方式——

@Service
public class UserServiceImpl implements UserService {

@Autowired
private AuthenticationManager authManager;

@Override
public Boolean authenticateUser(User user) {
    String password = Utils.generateOtp(6).toString();
    user.setPassword(password);

    UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword());
    Authentication auth = authManager.authenticate(authReq);

    SecurityContextHolder.getContext().setAuthentication(auth);
    return true;
}

}

4

1 回答 1

0

您如何针对 jdbc 或内存对用户进行身份验证?请检查是否有任何密码加密?

于 2018-05-31T10:41:06.240 回答