Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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 如何从数据输入字段获取密码?_Java_Postgresql - Fatal编程技术网

Java 如何从数据输入字段获取密码?

Java 如何从数据输入字段获取密码?,java,postgresql,Java,Postgresql,网站安全配置类 public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userSevice; @Autowired private PasswordEncoder passwordEncoder; @Bean public PasswordEn

网站安全配置

    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Autowired
        private UserService userSevice;

        @Autowired
        private PasswordEncoder passwordEncoder;

        @Bean
        public PasswordEncoder getPasswordEncoder() {
            return new BCryptPasswordEncoder(8);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests()
                    .antMatchers("/", "/registration", "/static/**", "/about").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .permitAll()
                    .and()
                    .logout()
                    .permitAll();
        }

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userSevice)
                    .passwordEncoder(passwordEncoder);


        }

    }
    public class UserService implements UserDetailsService  {
        @Autowired
        private UserRepo userRepo;

        @Override
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            User user = userRepo.findByUsername(username);
            System.out.println(username);

            if (user == null) {
                throw new UsernameNotFoundException("User not found");
            }

            return user;
        }
 }
用户服务

    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Autowired
        private UserService userSevice;

        @Autowired
        private PasswordEncoder passwordEncoder;

        @Bean
        public PasswordEncoder getPasswordEncoder() {
            return new BCryptPasswordEncoder(8);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests()
                    .antMatchers("/", "/registration", "/static/**", "/about").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .permitAll()
                    .and()
                    .logout()
                    .permitAll();
        }

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userSevice)
                    .passwordEncoder(passwordEncoder);


        }

    }
    public class UserService implements UserDetailsService  {
        @Autowired
        private UserRepo userRepo;

        @Override
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            User user = userRepo.findByUsername(username);
            System.out.println(username);

            if (user == null) {
                throw new UsernameNotFoundException("User not found");
            }

            return user;
        }
 }

UserDetailsService
只显示用户名,但我希望它能让我看到输入的密码,我输入了
system.out.printl(username)
进行验证,它会显示出来,我不知道如何输出密码。它们来自数据库。提前谢谢。对不起,我的英语很差,所以,本质上,您需要的是通过客户端从AuthenticationManagerBuilder的auth对象发送的密码。如果是,这将不可能,因为密码存储在不可逆散列中
如果要从DB获取密码,可以调用
user.getPassword()