diff --git a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/DynamicRegistrationClientConfigurationService.java b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/DynamicRegistrationClientConfigurationService.java index ae7a34113..79de205b6 100644 --- a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/DynamicRegistrationClientConfigurationService.java +++ b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/DynamicRegistrationClientConfigurationService.java @@ -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 { 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 entity = new HttpEntity(headers); String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody(); + // TODO: handle HTTP errors RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered); diff --git a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridClientConfigurationService.java b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridClientConfigurationService.java new file mode 100644 index 000000000..a76e00ee3 --- /dev/null +++ b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridClientConfigurationService.java @@ -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 getClients() { + return staticClientService.getClients(); + } + + /** + * @param clients + * @see org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService#setClients(java.util.Map) + */ + public void setClients(Map 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); + } + +} diff --git a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridServerConfigurationService.java b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridServerConfigurationService.java new file mode 100644 index 000000000..881372a01 --- /dev/null +++ b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/HybridServerConfigurationService.java @@ -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 getServers() { + return staticServerService.getServers(); + } + + + /** + * @param servers + * @see org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService#setServers(java.util.Map) + */ + public void setServers(Map servers) { + staticServerService.setServers(servers); + } + +} diff --git a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/StaticClientConfigurationService.java b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/StaticClientConfigurationService.java index 85462b6d2..f32454a1a 100644 --- a/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/StaticClientConfigurationService.java +++ b/openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/impl/StaticClientConfigurationService.java @@ -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.