JDBC-basedUser Store Example

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Example

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    private DataSource dataSource;

    public SecurityConfiguration(@Autowired DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.
          jdbcAuthentication().
           dataSource(dataSource).
           passwordEncoder(NoOpPasswordEncoder.getInstance()); // apparently it needs a password encoder otherwise it throws 
                                                               // java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id
                                                                     
    }
}