Skip to content

Instantly share code, notes, and snippets.

@robhinds
Created February 17, 2014 15:10
Show Gist options
  • Select an option

  • Save robhinds/9052337 to your computer and use it in GitHub Desktop.

Select an option

Save robhinds/9052337 to your computer and use it in GitHub Desktop.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired private UserDetailsServiceImpl userDetailsServiceImpl;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.antMatchers("/dashboard").permitAll()
.antMatchers("/sign-up").permitAll()
.antMatchers("/api/contacts/**").authenticated()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/")
.loginProcessingUrl("/loginprocess")
.failureUrl("/?loginFailure=true")
.permitAll();
}
@Override
protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsServiceImpl)
.passwordEncoder(bCryptPasswordEncoder());
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder(){
return new BCryptPasswordEncoder();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment