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;
024
025import javax.annotation.PostConstruct;
026
027import org.mitre.oauth2.model.RegisteredClient;
028import org.mitre.openid.connect.client.service.ClientConfigurationService;
029import org.mitre.openid.connect.config.ServerConfiguration;
030
031/**
032 * Client configuration service that holds a static map from issuer URL to a ClientDetails object to use at that issuer.
033 *
034 * Designed to be configured as a bean.
035 *
036 * @author jricher
037 *
038 */
039public class StaticClientConfigurationService implements ClientConfigurationService {
040
041        // Map of issuer URL -> client configuration information
042        private Map<String, RegisteredClient> clients;
043
044        /**
045         * @return the clients
046         */
047        public Map<String, RegisteredClient> getClients() {
048                return clients;
049        }
050
051        /**
052         * @param clients the clients to set
053         */
054        public void setClients(Map<String, RegisteredClient> clients) {
055                this.clients = clients;
056        }
057
058        /**
059         * Get the client configured for this issuer
060         *
061         * @see org.mitre.openid.connect.client.service.ClientConfigurationService#getClientConfiguration(java.lang.String)
062         */
063        @Override
064        public RegisteredClient getClientConfiguration(ServerConfiguration issuer) {
065
066                return clients.get(issuer.getIssuer());
067        }
068
069        @PostConstruct
070        public void afterPropertiesSet() {
071                if (clients == null || clients.isEmpty()) {
072                        throw new IllegalArgumentException("Clients map cannot be null or empty");
073                }
074
075        }
076
077}