Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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 如何在spring boot中为jdbcAuthentication passwordEncoder配置jasypt_Java_Spring_Spring Boot_Spring Security - Fatal编程技术网

Java 如何在spring boot中为jdbcAuthentication passwordEncoder配置jasypt

Java 如何在spring boot中为jdbcAuthentication passwordEncoder配置jasypt,java,spring,spring-boot,spring-security,Java,Spring,Spring Boot,Spring Security,我需要将PasswordEncoder配置为接受jasypt StandardPBEEncoder类型,而不是BCryptPasswordEncoder。 以下是我引用的代码: @Configuration @EnableWebSecurity public class DemoSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private DataSource dataSource; @Autowired p

我需要将PasswordEncoder配置为接受jasypt StandardPBEEncoder类型,而不是BCryptPasswordEncoder。
以下是我引用的代码:

@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource dataSource;

@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;

@Autowired
private StandardPBEStringEncryptor pbeEncryptor;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {

 auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(bCryptPasswordEncoder)
     .usersByUsernameQuery("select USERNAME,USERPASS PASSWORD,USER_BLOCK ENABLED from TABLE_LOGIN_MASTER where USERNAME=?")
     .authoritiesByUsernameQuery("select USERNAME, 'ROLE_'||ROLE_VALUE AUTHORITY from TAB_LOGIN_ROLE where USERNAME=?");

}
我需要使用pbeencyptor而不是bCryptPasswordEncoder作为密码编码器。
有可能吗?

所以我终于解决了这个问题。我在同一个类中为PasswordEncoder创建了一个bean,如下所示:

@Bean
public PasswordEncoder passwordEncoder() {
    return new PasswordEncoder() {

        ManagePassword mp = new ManagePassword();

        @Override
        public boolean matches(CharSequence rawpasswd, String encodedPassword) {
            // TODO Auto-generated method stub

            return mp.decrypt(encodedPassword).equals(rawpasswd.toString());
        }

        @Override
        public String encode(CharSequence rawpasswd) {
            // TODO Auto-generated method stub
            return mp.encrypt(rawpasswd.toString());
        }
    };

}
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {

auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder())
    .usersByUsernameQuery("select USERNAME,USERPASS PASSWORD,USER_BLOCK ENABLED from TABLE_LOGIN_MASTER where USERNAME=?")
    .authoritiesByUsernameQuery("select USERNAME, 'ROLE_'||ROLE_VALUE AUTHORITY from TAB_LOGIN_ROLE where USERNAME=?");

}

@Bean
public PasswordEncoder passwordEncoder() {
    return new PasswordEncoder() {

        ManagePassword mp = new ManagePassword();

        @Override
        public boolean matches(CharSequence rawpasswd, String encodedPassword) {
            // TODO Auto-generated method stub

            return mp.decrypt(encodedPassword).equals(rawpasswd.toString());
        }

        @Override
        public String encode(CharSequence rawpasswd) {
            // TODO Auto-generated method stub
            return mp.encrypt(rawpasswd.toString());
        }
    };

}
完成代码如下:

@Bean
public PasswordEncoder passwordEncoder() {
    return new PasswordEncoder() {

        ManagePassword mp = new ManagePassword();

        @Override
        public boolean matches(CharSequence rawpasswd, String encodedPassword) {
            // TODO Auto-generated method stub

            return mp.decrypt(encodedPassword).equals(rawpasswd.toString());
        }

        @Override
        public String encode(CharSequence rawpasswd) {
            // TODO Auto-generated method stub
            return mp.encrypt(rawpasswd.toString());
        }
    };

}
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {

auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder())
    .usersByUsernameQuery("select USERNAME,USERPASS PASSWORD,USER_BLOCK ENABLED from TABLE_LOGIN_MASTER where USERNAME=?")
    .authoritiesByUsernameQuery("select USERNAME, 'ROLE_'||ROLE_VALUE AUTHORITY from TAB_LOGIN_ROLE where USERNAME=?");

}

@Bean
public PasswordEncoder passwordEncoder() {
    return new PasswordEncoder() {

        ManagePassword mp = new ManagePassword();

        @Override
        public boolean matches(CharSequence rawpasswd, String encodedPassword) {
            // TODO Auto-generated method stub

            return mp.decrypt(encodedPassword).equals(rawpasswd.toString());
        }

        @Override
        public String encode(CharSequence rawpasswd) {
            // TODO Auto-generated method stub
            return mp.encrypt(rawpasswd.toString());
        }
    };

}
ManagePassword类包含初始化StandardPBEStringEncryptor的代码