Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Java 我能';t在Spring引导身份验证提供程序中持久化数据_Java_Spring Boot_Spring Security_Spring Data Jpa - Fatal编程技术网

Java 我能';t在Spring引导身份验证提供程序中持久化数据

Java 我能';t在Spring引导身份验证提供程序中持久化数据,java,spring-boot,spring-security,spring-data-jpa,Java,Spring Boot,Spring Security,Spring Data Jpa,我无法在AuthenticationProvider中持久保存数据,cashierRepo.save(cashierDAO)正在抛出nullPointerException @Component public class TACoreAuthProvider implements AuthenticationProvider { UsernamePasswordAuthenticationToken userToken; @Autowired CashierDAOSe

我无法在
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);

        });
@组件
公共类TACoreAuthProvider实现AuthenticationProvider{
UsernamePasswordAuthenticationTokenUserToken;
@自动连线
收银员daoserviceimpl收银员repo;
@凌驾
公共身份验证(身份验证)引发AuthenticationException{
字符串username=authentication.getPrincipal().toString();
字符串密码=authentication.getCredentials().toString();
Mono loginResponseDAO=tacoreAuth(用户名、密码);
loginResponseDAO.订阅(响应AO->{
System.out.print(responseDAO.toString());
如果(!responseDAO.getStatus().equalsIgnoreCase(“成功”)){
抛出新的BadCredentialsException(“外部系统身份验证失败”);
}
responseDAO.getData().setUserName(用户名);
CashierDAO CashierDAO=responseDAO.getData();
收银员储蓄(收银员道);
Set grantedAuthories=new HashSet();
grantedAuthories.add(新的SimpleGrantedAuthority(responseDAO.getData().getUser_category());
userToken=新用户名PasswordAuthenticationToken(用户名、密码、授权权限);
});

多亏了大家,我才知道问题出在哪里

@Bean
public static TACoreAuthProvider getAuthProvider(CashierDAOServiceImpl cashierDAOService){
        return new TACoreAuthProvider(cashierDAOService);
    }
由于“TACoreAuthProvider”实例为空,在要实现它的静态类“ApiWebSecurityConfiguration Adapter”外部声明

@EnableWebSecurity
public class SecurityConfig  {
    @Bean
public static TACoreAuthProvider getAuthProvider(CashierDAOServiceImpl cashierDAOService){
        return new TACoreAuthProvider(cashierDAOService);
    }

 @Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends 
    WebSecurityConfigurerAdapter{

    @Bean
    public CustomBasicAuthenticationEntryPoint getBasicAuthEntryPoint(){
        return new CustomBasicAuthenticationEntryPoint();
    }

    @Override
    protected void configure(HttpSecurity http)throws Exception{
        http.csrf().disable()
                //.addFilterAfter(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
                .antMatcher("/api/**")
                .authorizeRequests().anyRequest().authenticated()
                .and()
                .httpBasic().authenticationEntryPoint(getBasicAuthEntryPoint())
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        auth.authenticationProvider(getAuthProvider(cashierDAOService));

    }
}

下面的代码是工作版本

 @EnableWebSecurity
public class SecurityConfig  {

 @Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends 
    WebSecurityConfigurerAdapter{

    @Bean
public static TACoreAuthProvider getAuthProvider(CashierDAOServiceImpl cashierDAOService){
        return new TACoreAuthProvider(cashierDAOService);
    }

    @Bean
    public CustomBasicAuthenticationEntryPoint getBasicAuthEntryPoint(){
        return new CustomBasicAuthenticationEntryPoint();
    }

    @Override
    protected void configure(HttpSecurity http)throws Exception{
        http.csrf().disable()
                //.addFilterAfter(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
                .antMatcher("/api/**")
                .authorizeRequests().anyRequest().authenticated()
                .and()
                .httpBasic().authenticationEntryPoint(getBasicAuthEntryPoint())
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        auth.authenticationProvider(getAuthProvider(cashierDAOService));

    }

}

您能澄清一下什么是
null
?术语
crudepository
未出现在您发布的代码中。