2 * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. and others.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse License v1.0 which accompanies this distribution,
7 * 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;
18 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.TreeSet;
22 import org.osgi.service.cm.ConfigurationException;
23 import org.osgi.service.cm.ManagedService;
26 * AAA federation configurations in OSGi.
31 public class FederationConfiguration implements ManagedService {
32 private static final String FEDERATION_CONFIG_ERR = "Error saving federation configuration";
34 static final String HTTP_HEADERS = "httpHeaders";
35 static final String HTTP_ATTRIBUTES = "httpAttributes";
36 static final String SECURE_PROXY_PORTS = "secureProxyPorts";
38 static FederationConfiguration instance = new FederationConfiguration();
40 static final Hashtable<String, String> defaults = new Hashtable<>();
42 defaults.put(HTTP_HEADERS, "");
43 defaults.put(HTTP_ATTRIBUTES, "");
45 private static Map<String, String> configs = new ConcurrentHashMap<>();
48 private FederationConfiguration() {
51 public static FederationConfiguration instance() {
56 public void updated(Dictionary<String, ?> props)
57 throws ConfigurationException {
60 configs.putAll(defaults);
63 Enumeration<String> keys = props.keys();
64 while (keys.hasMoreElements()) {
65 String key = keys.nextElement();
66 configs.put(key, (String) props.get(key));
68 } catch (Throwable t) {
69 throw new ConfigurationException(null, FEDERATION_CONFIG_ERR);
74 public List<String> httpHeaders() {
75 String headers = configs.get(HTTP_HEADERS);
76 return (headers == null) ? new ArrayList<String>() : Arrays
77 .asList(headers.split(" "));
80 public List<String> httpAttributes() {
81 String attributes = configs.get(HTTP_ATTRIBUTES);
82 return (attributes == null) ? new ArrayList<String>() : Arrays
83 .asList(attributes.split(" "));
86 public Set<Integer> secureProxyPorts() {
87 String ports = configs.get(SECURE_PROXY_PORTS);
88 Set<Integer> secureProxyPorts = new TreeSet<Integer>();
90 if (ports != null && !ports.isEmpty()) {
91 for (String port : ports.split(" ")) {
92 secureProxyPorts.add(Integer.parseInt(port));
95 return secureProxyPorts;