Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableResourceServer
- @EnableGlobalMethodSecurity(prePostEnabled = true)
- @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER-1)
- public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
- public static final String RESOURCE_ID = "resources";
- @Override
- public void configure(final ResourceServerSecurityConfigurer resources) {
- resources
- .resourceId(RESOURCE_ID);
- }
- @Override
- public void configure(final HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')")
- .antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
- .antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
- .antMatchers(HttpMethod.PATCH, "/**").access("#oauth2.hasScope('write')")
- .antMatchers(HttpMethod.DELETE, "/**").access("#oauth2.hasScope('write')")
- .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
- .antMatchers(HttpMethod.GET, "/health").permitAll();
- }
- }
- @Configuration
- @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- private UserDetailsService userDetailsService;
- @Override
- public void configure(final AuthenticationManagerBuilder auth) throws Exception {
- auth
- .userDetailsService(userDetailsService)
- .passwordEncoder(new BCryptPasswordEncoder());
- }
- @Override
- protected void configure(final HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .anyRequest().authenticated()
- .and().httpBasic().realmName("OAuth Server");
- }
- }
- protected void configure(HttpSecurity http) throws Exception {
- ...
- .authorizeRequests()
- .antMatchers("/actuator/**").permitAll()
- }
Add Comment
Please, Sign In to add comment