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.openid.connect.client.service.ServerConfigurationService;
028import org.mitre.openid.connect.config.ServerConfiguration;
029
030/**
031 * Statically configured server configuration service that maps issuer URLs to server configurations to use at that issuer.
032 *
033 * @author jricher
034 *
035 */
036public class StaticServerConfigurationService implements ServerConfigurationService {
037
038        // map of issuer url -> server configuration information
039        private Map<String, ServerConfiguration> servers;
040
041        /**
042         * @return the servers
043         */
044        public Map<String, ServerConfiguration> getServers() {
045                return servers;
046        }
047
048        /**
049         * @param servers the servers to set
050         */
051        public void setServers(Map<String, ServerConfiguration> servers) {
052                this.servers = servers;
053        }
054
055        /* (non-Javadoc)
056         * @see org.mitre.openid.connect.client.service.ServerConfigurationService#getServerConfiguration(java.lang.String)
057         */
058        @Override
059        public ServerConfiguration getServerConfiguration(String issuer) {
060                return servers.get(issuer);
061        }
062
063        @PostConstruct
064        public void afterPropertiesSet() {
065                if (servers == null || servers.isEmpty()) {
066                        throw new IllegalArgumentException("Servers map cannot be null or empty.");
067                }
068
069        }
070
071}