Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Last active August 21, 2018 14:18
Show Gist options
  • Save artem-smotrakov/f245889521b6ee786ae011f7a39b9ef4 to your computer and use it in GitHub Desktop.
Save artem-smotrakov/f245889521b6ee786ae011f7a39b9ef4 to your computer and use it in GitHub Desktop.
An example of SecurityConfiguration for an application based on Spring framework
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final String readScope = "#oauth2.isOAuth() && #oauth2.hasScope('read')";
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
public void configure(final HttpSecurity http) throws Exception {
http.anonymous().disable();
http.httpBasic().disable();
http.logout().disable();
http.loginForm().disable();
http.headers().httpStrictTransportSecurity();
http.authorizeRequests()
.antMatchers("/**").access(read)
.anyRequest().authenticated();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment