Skip to content

Instantly share code, notes, and snippets.

@robhinds
Created March 25, 2014 15:41
Show Gist options
  • Select an option

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

Select an option

Save robhinds/9764515 to your computer and use it in GitHub Desktop.
@Configuration
@EnableWebSecurity
@Order(2)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired private UserDetailsServiceImpl userDetailsServiceImpl;
@Autowired private CustomTokenBasedRememberMeService tokenBasedRememberMeService;
@Autowired private RememberMeAuthenticationProvider rememberMeAuthenticationProvider;
@Override protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.antMatchers("/sign-up").permitAll()
.antMatchers("/sign-in").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/")
.loginProcessingUrl("/loginprocess")
.failureUrl("/mobile/app/sign-in?loginFailure=true")
.permitAll().and()
.rememberMe().rememberMeServices(tokenBasedRememberMeService);
}
@Override protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsServiceImpl)
.passwordEncoder(bCryptPasswordEncoder());
auth.authenticationProvider(rememberMeAuthenticationProvider);
}
@Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@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