Created
October 13, 2015 14:22
-
-
Save gigenthomas/9a93cb8928ece65eaa94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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