Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.
This repository was archived by the owner on May 31, 2022. It is now read-only.

Multiple resource servers with multiple remote token services #1018

Open
@IbrahimAl-Zreqat

Description

@IbrahimAl-Zreqat

Can I implement more than one RemoteTokenServices in the the resource server, so every resource has it's own client_id and client_secret, I implemented two RemoteTokenServices but the List of ResourceServerConfigurer shows the last RemoteTokenServices added which means there is only one object of the RemoteTokenServices and that means only one client_id and client_secret in the system.
is that right?

here is my ResourceServerConfig:

`

    @Configuration
    @EnableWebSecurity
    public class ResourceServerConfig {

    @Bean
protected ResourceServerConfiguration firstResources() {
	ResourceServerConfiguration resources = new ResourceServerConfiguration(){
		@Override
		public void setConfigurers(List<ResourceServerConfigurer> configurers) {
			super.setConfigurers(configurers);
		}
		
		
	};
	resources.setOrder(4);
	resources.setConfigurers(Arrays.asList(getFirstConfigrers()));
	return resources;
}

@Bean
protected ResourceServerConfiguration secondResources() {
	ResourceServerConfiguration resources = new ResourceServerConfiguration(){
		@Override
		public void setConfigurers(List<ResourceServerConfigurer> configurers) {
			super.setConfigurers(configurers);
		}
		
	};
	resources.setOrder(5);
	resources.setConfigurers(Arrays.asList(getSecondConfigrers()));
	return resources;
}

private ResourceServerConfigurer getFirstConfigrers(){
	ResourceServerConfigurer integration = new ResourceServerConfigurerAdapter() {
		
		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("test1").tokenServices(firstTokenServices());
		}
		
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.anonymous().disable()
			.authorizeRequests().antMatchers("/Test1/**").hasAuthority("ADMIN");
		}
		
	};

	return integration;
}

private ResourceServerConfigurer getSecondConfigrers(){
	ResourceServerConfigurer validation = new ResourceServerConfigurerAdapter() {
		
		@Override
		public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
			resources.resourceId("test2").tokenServices(secondTokenServices());
		}
		
		@Override
		public void configure(HttpSecurity http) throws Exception {
			http.anonymous().disable()
			.authorizeRequests().antMatchers("/Test2/**").hasAuthority("ADMIN");
		}
		
	};

	return validation;
}

@Bean()
@Primary
protected RemoteTokenServices firstTokenServices(){
	RemoteTokenServices remoteTokenServices = new RemoteTokenServices();
	remoteTokenServices.setCheckTokenEndpointUrl("http://localhost:8080/oauth-server/oauth/check_token");
	remoteTokenServices.setClientId("first");
	remoteTokenServices.setClientSecret("secret");
	return remoteTokenServices;
}

    @Bean()
protected RemoteTokenServices secondTokenServices(){
	RemoteTokenServices remoteTokenServices = new RemoteTokenServices();
	remoteTokenServices.setCheckTokenEndpointUrl("http://localhost:8080/oauth-server/oauth/check_token");
	remoteTokenServices.setClientId("second");
	remoteTokenServices.setClientSecret("secret");
	return remoteTokenServices;
}}

`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions