我无法在 中保留数据AuthenticationProvider
,cashierRepo.save(cashierDAO)
正在抛出 nullPointerException
.
@Component
public class TACoreAuthProvider implements AuthenticationProvider {
UsernamePasswordAuthenticationToken userToken;
@Autowired
CashierDAOServiceImpl cashierRepo;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getPrincipal().toString();
String password = authentication.getCredentials().toString();
Mono<LoginResponseDAO> loginResponseDAO = tacoreAuth(username, password);
loginResponseDAO.subscribe(responseDAO->{
System.out.print(responseDAO.toString());
if(!responseDAO.getStatus().equalsIgnoreCase("success")){
throw new BadCredentialsException("External system authentication failed");
}
responseDAO.getData().setUserName(username);
CashierDAO cashierDAO = responseDAO.getData();
cashierRepo.save(cashierDAO);
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
grantedAuthorities.add(new SimpleGrantedAuthority(responseDAO.getData().getUser_category()));
userToken = new UsernamePasswordAuthenticationToken(username, password, grantedAuthorities);
});