org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurer Java Examples

The following examples show how to use org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
	return new ResourceServerConfigurer() {
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests()
			    .antMatchers(HttpMethod.GET, "/hello").access("#oauth2.hasAnyScope('account', 'message', 'email')");
		}

		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("resource");
		}
		
	};
}
 
Example #2
Source File: ZuulServerApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
    return new ResourceServerConfigurer() {
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                .antMatchers("/api/acct/**").access("#oauth2.hasScope('account')")
                .antMatchers("/api/msg/**").access("#oauth2.hasScope('message')")
                .antMatchers("/api/email/**").access("#oauth2.hasScope('email')");
        }

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.tokenStore(tokenStore());
        }
    };
}
 
Example #3
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
	return new ResourceServerConfigurer() {
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests()
			    .antMatchers(HttpMethod.GET, "/hello").access("#oauth2.hasAnyScope('account', 'message', 'email')");
		}

		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("resource");
		}
		
	};
}
 
Example #4
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
	return new ResourceServerConfigurer() {
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests()
			    .antMatchers(HttpMethod.GET, "/hello").access("#oauth2.hasAnyScope('account', 'message', 'email')");
		}

		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.tokenStore(tokenStore())
			         .resourceId("resource");
		}
	};
}
 
Example #5
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
	return new ResourceServerConfigurer() {
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests().antMatchers("/hello").access("#oauth2.hasAnyScope('account', 'message', 'email')");
		}

		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("resource");
		}
	};
}
 
Example #6
Source File: EmailApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
    return new ResourceServerConfigurer() {
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                .anyRequest().access("#oauth2.hasScope('email')");
        }

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.tokenStore(tokenStore());
        }
    };
}
 
Example #7
Source File: AcctApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
    return new ResourceServerConfigurer() {
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                .anyRequest().access("#oauth2.hasScope('account')");
        }

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.tokenStore(tokenStore());
        }
    };
}
 
Example #8
Source File: MsgApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
    return new ResourceServerConfigurer() {
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                .anyRequest().access("#oauth2.hasScope('message')");
        }

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.tokenStore(tokenStore());
        }
    };
}
 
Example #9
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ResourceServerConfigurer resourceServerConfigurer() {
	return new ResourceServerConfigurer() {
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.authorizeRequests().antMatchers("/hello").access("#oauth2.hasAnyScope('account', 'message', 'email')");
		}

		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("resource");
		}
	};
}
 
Example #10
Source File: MultipleResourceServerConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Bean
protected ResourceServerConfiguration adminResources() {

	ResourceServerConfiguration resource = new ResourceServerConfiguration() {
		// Switch off the Spring Boot @Autowired configurers
		@Override
		public void setConfigurers(List<ResourceServerConfigurer> configurers) {
			super.setConfigurers(configurers);
		}
	};
	resource.setOrder(3);
	return resource;
}
 
Example #11
Source File: MultipleResourceServerConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Bean
protected ResourceServerConfiguration otherResources() {

	ResourceServerConfiguration resource = new ResourceServerConfiguration() {
		// Switch off the Spring Boot @Autowired configurers
		@Override
		public void setConfigurers(List<ResourceServerConfigurer> configurers) {
			super.setConfigurers(configurers);
		}
	};
	resource.setOrder(4);
	return resource;
}
 
Example #12
Source File: CustomResourceServerConfiguration.java    From spring-microservice-boilerplate with MIT License 5 votes vote down vote up
/**
 * Resource of api
 *
 * @return {@link ResourceServerConfiguration}
 */
@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(Collections.singletonList(new ResourceServerConfigurerAdapter() {

    @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
      resources.resourceId(RESOURCE_ID);
    }

    @Override public void configure(HttpSecurity http) throws Exception {
      http
          .csrf().disable()
          .authorizeRequests()
          .antMatchers(OPEN_URL).permitAll()
          .antMatchers(MANAGEMENT_URL).hasAnyAuthority("root", "management")
          .antMatchers(APP_URL).hasAnyAuthority("root", "management", "app");
    }
  }));

  resource.setOrder(1);

  return resource;
}
 
Example #13
Source File: OAuth2ResourceServerConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(ResourceServerConfigurer.class)
public ResourceServerConfigurer resourceServer() {
	return new ResourceSecurityConfigurer(this.resource);
}