Last active
December 18, 2017 01:25
-
-
Save diegosilva13/4d0df7f51ef456720bfe2ca1b873ec45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.coderef.delivery.security; | |
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.http.HttpMethod; | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | |
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | |
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; | |
@Configuration | |
@EnableResourceServer | |
public class SecurityConfiguration extends ResourceServerConfigurerAdapter { | |
private final static String resourceId = "resources"; | |
@Override | |
public void configure(HttpSecurity http) throws Exception { | |
http.requestMatchers() | |
.antMatchers("/**") | |
.and() | |
.authorizeRequests() | |
.anyRequest() | |
.authenticated() | |
.antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')") | |
.antMatchers(HttpMethod.OPTIONS, "/**").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')"); | |
} | |
@Override | |
public void configure(ResourceServerSecurityConfigurer resources){ | |
resources.resourceId(resourceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment