【发布时间】:2021-01-26 15:41:01
【问题描述】:
我无法在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);
});
【问题讨论】:
-
你能澄清一下
null到底是什么吗?术语CrudRepository未出现在您发布的代码中。
标签: java spring-boot spring-security spring-data-jpa