嗨,我正在尝试手动进行身份验证,并希望为 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;
}
}