Search in sources :

Example 1 with ResourceServerConfiguration

use of org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration in project spring-security-oauth by spring-projects.

the class Application method adminResources.

@Bean
protected ResourceServerConfiguration adminResources() {
    ResourceServerConfiguration resource = new ResourceServerConfiguration() {

        // Switch off the Spring Boot @Autowired configurers
        public void setConfigurers(List<ResourceServerConfigurer> configurers) {
            super.setConfigurers(configurers);
        }
    };
    resource.setConfigurers(Arrays.<ResourceServerConfigurer>asList(new ResourceServerConfigurerAdapter() {

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.resourceId("oauth2/admin");
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.antMatcher("/admin/**").authorizeRequests().anyRequest().access("#oauth2.hasScope('read')");
        }
    }));
    resource.setOrder(3);
    return resource;
}
Also used : ResourceServerConfiguration(org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) ResourceServerConfigurerAdapter(org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter) List(java.util.List) ResourceServerSecurityConfigurer(org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 2 with ResourceServerConfiguration

use of org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration in project spring-security-oauth by spring-projects.

the class Application method otherResources.

@Bean
protected ResourceServerConfiguration otherResources() {
    ResourceServerConfiguration resource = new ResourceServerConfiguration() {

        // Switch off the Spring Boot @Autowired configurers
        public void setConfigurers(List<ResourceServerConfigurer> configurers) {
            super.setConfigurers(configurers);
        }
    };
    resource.setConfigurers(Arrays.<ResourceServerConfigurer>asList(new ResourceServerConfigurerAdapter() {

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.resourceId("oauth2/other");
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().access("#oauth2.hasScope('trust')");
        }
    }));
    resource.setOrder(4);
    return resource;
}
Also used : ResourceServerConfiguration(org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) ResourceServerConfigurerAdapter(org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter) List(java.util.List) ResourceServerSecurityConfigurer(org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer) Bean(org.springframework.context.annotation.Bean)

Aggregations

List (java.util.List)2 Bean (org.springframework.context.annotation.Bean)2 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)2 ResourceServerConfiguration (org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration)2 ResourceServerConfigurerAdapter (org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter)2 ResourceServerSecurityConfigurer (org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer)2