added hybrid client and server services, addresses #387
parent
93a0492e97
commit
6e8ab7736e
|
@ -23,7 +23,6 @@ import java.util.concurrent.ExecutionException;
|
|||
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
import org.mitre.oauth2.model.RegisteredClient;
|
||||
import org.mitre.openid.connect.ClientDetailsEntityJsonProcessor;
|
||||
import org.mitre.openid.connect.client.service.ClientConfigurationService;
|
||||
|
@ -37,7 +36,6 @@ import org.springframework.http.HttpMethod;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
@ -45,7 +43,6 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
|
@ -117,7 +114,6 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
|||
public class DynamicClientRegistrationLoader extends CacheLoader<ServerConfiguration, RegisteredClient> {
|
||||
private HttpClient httpClient = new DefaultHttpClient();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private JsonParser parser = new JsonParser();
|
||||
|
||||
@Override
|
||||
public RegisteredClient load(ServerConfiguration serverConfig) throws Exception {
|
||||
|
@ -155,6 +151,7 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
|||
HttpEntity<String> entity = new HttpEntity<String>(headers);
|
||||
|
||||
String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
|
||||
// TODO: handle HTTP errors
|
||||
|
||||
RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.mitre.openid.connect.client.service.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mitre.oauth2.model.RegisteredClient;
|
||||
import org.mitre.openid.connect.client.service.ClientConfigurationService;
|
||||
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||
|
||||
/**
|
||||
* Houses both a static client configuration and a dynamic client configuration
|
||||
* service in one object. Checks the static service first, then falls through to
|
||||
* the dynamic service.
|
||||
*
|
||||
* Provides configuration passthrough for the template and the static
|
||||
* client map.
|
||||
*
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
public class HybridClientConfigurationService implements ClientConfigurationService {
|
||||
|
||||
private StaticClientConfigurationService staticClientService = new StaticClientConfigurationService();
|
||||
|
||||
private DynamicRegistrationClientConfigurationService dynamicClientService = new DynamicRegistrationClientConfigurationService();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.openid.connect.client.service.ClientConfigurationService#getClientConfiguration(org.mitre.openid.connect.config.ServerConfiguration)
|
||||
*/
|
||||
@Override
|
||||
public RegisteredClient getClientConfiguration(ServerConfiguration issuer) {
|
||||
|
||||
RegisteredClient client = staticClientService.getClientConfiguration(issuer);
|
||||
if (client != null) {
|
||||
return client;
|
||||
} else {
|
||||
return dynamicClientService.getClientConfiguration(issuer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService#getClients()
|
||||
*/
|
||||
public Map<String, RegisteredClient> getClients() {
|
||||
return staticClientService.getClients();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clients
|
||||
* @see org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService#setClients(java.util.Map)
|
||||
*/
|
||||
public void setClients(Map<String, RegisteredClient> clients) {
|
||||
staticClientService.setClients(clients);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#getTemplate()
|
||||
*/
|
||||
public RegisteredClient getTemplate() {
|
||||
return dynamicClientService.getTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param template
|
||||
* @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#setTemplate(org.mitre.oauth2.model.RegisteredClient)
|
||||
*/
|
||||
public void setTemplate(RegisteredClient template) {
|
||||
dynamicClientService.setTemplate(template);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.mitre.openid.connect.client.service.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mitre.openid.connect.client.service.ServerConfigurationService;
|
||||
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||
|
||||
/**
|
||||
* Houses both a static server configuration and a dynamic server configuration
|
||||
* service in one object. Checks the static service first, then falls through to
|
||||
* the dynamic service.
|
||||
*
|
||||
* Provides configuration passthrough for the template and the static
|
||||
* client map.
|
||||
*
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
public class HybridServerConfigurationService implements ServerConfigurationService {
|
||||
|
||||
private StaticServerConfigurationService staticServerService;
|
||||
|
||||
private DynamicServerConfigurationService dynamicServerService;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.openid.connect.client.service.ServerConfigurationService#getServerConfiguration(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ServerConfiguration getServerConfiguration(String issuer) {
|
||||
ServerConfiguration server = staticServerService.getServerConfiguration(issuer);
|
||||
if (server != null) {
|
||||
return server;
|
||||
} else {
|
||||
return dynamicServerService.getServerConfiguration(issuer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService#getServers()
|
||||
*/
|
||||
public Map<String, ServerConfiguration> getServers() {
|
||||
return staticServerService.getServers();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param servers
|
||||
* @see org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService#setServers(java.util.Map)
|
||||
*/
|
||||
public void setServers(Map<String, ServerConfiguration> servers) {
|
||||
staticServerService.setServers(servers);
|
||||
}
|
||||
|
||||
}
|
|
@ -21,12 +21,10 @@ package org.mitre.openid.connect.client.service.impl;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mitre.oauth2.model.ClientDetailsEntity;
|
||||
import org.mitre.oauth2.model.RegisteredClient;
|
||||
import org.mitre.openid.connect.client.service.ClientConfigurationService;
|
||||
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
|
||||
/**
|
||||
* Client configuration service that holds a static map from issuer URL to a ClientDetails object to use at that issuer.
|
||||
|
|
Loading…
Reference in New Issue