Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gigenthomas/9a93cb8928ece65eaa94 to your computer and use it in GitHub Desktop.
Save gigenthomas/9a93cb8928ece65eaa94 to your computer and use it in GitHub Desktop.
@EnableWebMvcSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.antMatchers("/","/index", "/home").permitAll()
.antMatchers("/index.html").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
/*
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
*/
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username,password,enabled from users where username = ?")
.authoritiesByUsernameQuery("select username,authority from authorities where username = ?");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment