Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created November 30, 2016 04:46
Show Gist options
  • Select an option

  • Save monkey-codes/534167e67d17e985f15b8d4f8deea7da to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/534167e67d17e985f15b8d4f8deea7da to your computer and use it in GitHub Desktop.
Configuring Spring Web Security with OAuth
@Configuration
@Order(-20)
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
@Bean
AuthenticationManager authenticationManagerBean() throws Exception {
super.authenticationManagerBean()
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin().loginPage('/login').permitAll()
.and().httpBasic().and()
.requestMatchers()
//specify urls handled
.antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
.antMatchers("/fonts/**", "/js/**", "/css/**")
.and()
.authorizeRequests()
.antMatchers("/fonts/**", "/js/**", "/css/**").permitAll()
.anyRequest().authenticated()
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser('reader')
.password('reader')
.authorities('ROLE_READER')
.and()
.withUser('guest')
.password('guest')
.authorities('ROLE_GUEST')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment