JDBC-basedUser Store Example

From NovaOrdis Knowledge Base
Revision as of 03:12, 26 October 2018 by Ovidiu (talk | contribs) (→‎Example)
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
                                                                     
    }
}