2 * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.aaa.federation;
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.Dictionary;
14 import java.util.Enumeration;
15 import java.util.Hashtable;
16 import java.util.List;
19 import java.util.TreeSet;
20 import java.util.concurrent.ConcurrentHashMap;
21 import org.osgi.service.cm.ConfigurationException;
22 import org.osgi.service.cm.ManagedService;
25 * AAA federation configurations in OSGi.
30 public class FederationConfiguration implements ManagedService {
31 private static final String FEDERATION_CONFIG_ERR = "Error saving federation configuration";
33 static final String HTTP_HEADERS = "httpHeaders";
34 static final String HTTP_ATTRIBUTES = "httpAttributes";
35 static final String SECURE_PROXY_PORTS = "secureProxyPorts";
37 static FederationConfiguration instance = new FederationConfiguration();
39 static final Hashtable<String, String> defaults = new Hashtable<>();
41 defaults.put(HTTP_HEADERS, "");
42 defaults.put(HTTP_ATTRIBUTES, "");
44 private static Map<String, String> configs = new ConcurrentHashMap<>();
47 private FederationConfiguration() {
50 public static FederationConfiguration instance() {
55 public void updated(Dictionary<String, ?> props) throws ConfigurationException {
58 configs.putAll(defaults);
61 Enumeration<String> keys = props.keys();
62 while (keys.hasMoreElements()) {
63 String key = keys.nextElement();
64 configs.put(key, (String) props.get(key));
66 } catch (Throwable t) {
67 throw new ConfigurationException(null, FEDERATION_CONFIG_ERR, t);
72 public List<String> httpHeaders() {
73 String headers = configs.get(HTTP_HEADERS);
74 return (headers == null) ? new ArrayList<String>() : Arrays.asList(headers.split(" "));
77 public List<String> httpAttributes() {
78 String attributes = configs.get(HTTP_ATTRIBUTES);
79 return (attributes == null) ? new ArrayList<String>() : Arrays
80 .asList(attributes.split(" "));
83 public Set<Integer> secureProxyPorts() {
84 String ports = configs.get(SECURE_PROXY_PORTS);
85 Set<Integer> secureProxyPorts = new TreeSet<Integer>();
87 if (ports != null && !ports.isEmpty()) {
88 for (String port : ports.split(" ")) {
89 secureProxyPorts.add(Integer.parseInt(port));
92 return secureProxyPorts;