Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Last active October 10, 2018 13:59
Show Gist options
  • Save artem-smotrakov/97afa6d0d0797a00891fdcbbe1e41d61 to your computer and use it in GitHub Desktop.
Save artem-smotrakov/97afa6d0d0797a00891fdcbbe1e41d61 to your computer and use it in GitHub Desktop.
Example of security config for a Spring-based RESTful application, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.rememberMe().disable();
http.authorizeRequests()
.antMatchers("/api/foo").hasRole("bar")
.antMatchers("/api/bat").hasRole("foo")
.anyRequest().authenticated()
.anyRequest().denyAll();
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment