001/*******************************************************************************
002 * Copyright 2017 The MIT Internet Trust Consortium
003 *
004 * Portions copyright 2011-2013 The MITRE Corporation
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *******************************************************************************/
018/**
019 *
020 */
021package org.mitre.openid.connect.client.service.impl;
022
023import java.util.Map;
024import java.util.Set;
025
026import org.mitre.oauth2.model.RegisteredClient;
027import org.mitre.openid.connect.client.service.ClientConfigurationService;
028import org.mitre.openid.connect.client.service.RegisteredClientService;
029import org.mitre.openid.connect.config.ServerConfiguration;
030
031/**
032 * Houses both a static client configuration and a dynamic client configuration
033 * service in one object. Checks the static service first, then falls through to
034 * the dynamic service.
035 *
036 * Provides configuration passthrough for the template, registered client service, whitelist,
037 * and blacklist for the dynamic service, and to the static service's client map.
038 *
039 * @author jricher
040 *
041 */
042public class HybridClientConfigurationService implements ClientConfigurationService {
043
044        private StaticClientConfigurationService staticClientService = new StaticClientConfigurationService();
045
046        private DynamicRegistrationClientConfigurationService dynamicClientService = new DynamicRegistrationClientConfigurationService();
047
048        /* (non-Javadoc)
049         * @see org.mitre.openid.connect.client.service.ClientConfigurationService#getClientConfiguration(org.mitre.openid.connect.config.ServerConfiguration)
050         */
051        @Override
052        public RegisteredClient getClientConfiguration(ServerConfiguration issuer) {
053
054                RegisteredClient client = staticClientService.getClientConfiguration(issuer);
055                if (client != null) {
056                        return client;
057                } else {
058                        return dynamicClientService.getClientConfiguration(issuer);
059                }
060
061        }
062
063        /**
064         * @return
065         * @see org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService#getClients()
066         */
067        public Map<String, RegisteredClient> getClients() {
068                return staticClientService.getClients();
069        }
070
071        /**
072         * @param clients
073         * @see org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService#setClients(java.util.Map)
074         */
075        public void setClients(Map<String, RegisteredClient> clients) {
076                staticClientService.setClients(clients);
077        }
078
079        /**
080         * @return
081         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#getTemplate()
082         */
083        public RegisteredClient getTemplate() {
084                return dynamicClientService.getTemplate();
085        }
086
087        /**
088         * @param template
089         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#setTemplate(org.mitre.oauth2.model.RegisteredClient)
090         */
091        public void setTemplate(RegisteredClient template) {
092                dynamicClientService.setTemplate(template);
093        }
094
095        /**
096         * @return
097         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#getRegisteredClientService()
098         */
099        public RegisteredClientService getRegisteredClientService() {
100                return dynamicClientService.getRegisteredClientService();
101        }
102
103        /**
104         * @param registeredClientService
105         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#setRegisteredClientService(org.mitre.openid.connect.client.service.RegisteredClientService)
106         */
107        public void setRegisteredClientService(RegisteredClientService registeredClientService) {
108                dynamicClientService.setRegisteredClientService(registeredClientService);
109        }
110
111        /**
112         * @return
113         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#getWhitelist()
114         */
115        public Set<String> getWhitelist() {
116                return dynamicClientService.getWhitelist();
117        }
118
119        /**
120         * @param whitelist
121         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#setWhitelist(java.util.Set)
122         */
123        public void setWhitelist(Set<String> whitelist) {
124                dynamicClientService.setWhitelist(whitelist);
125        }
126
127        /**
128         * @return
129         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#getBlacklist()
130         */
131        public Set<String> getBlacklist() {
132                return dynamicClientService.getBlacklist();
133        }
134
135        /**
136         * @param blacklist
137         * @see org.mitre.openid.connect.client.service.impl.DynamicRegistrationClientConfigurationService#setBlacklist(java.util.Set)
138         */
139        public void setBlacklist(Set<String> blacklist) {
140                dynamicClientService.setBlacklist(blacklist);
141        }
142
143}