1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package dk.sosi.seal.pki.impl;
30
31 import dk.sosi.seal.SOSIFactory;
32 import dk.sosi.seal.model.ModelException;
33 import dk.sosi.seal.pki.AuditEventHandler;
34 import dk.sosi.seal.pki.SOSIConfiguration;
35
36 import java.util.Properties;
37
38
39
40
41 public class PropertiesSOSIConfiguration implements SOSIConfiguration {
42 private final Properties properties;
43 private final Properties defaultValues;
44
45 public static SOSIConfiguration createWithDefaultOcesProperties(Properties properties) {
46 final Properties defaults = new Properties();
47 defaults.put(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_HOST_OCES1, "dir.certifikat.dk");
48 defaults.put(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_PORT_OCES1, "389");
49 return new PropertiesSOSIConfiguration(properties, defaults);
50 }
51
52 public static SOSIConfiguration createWithDefaultOcesTestProperties(Properties properties) {
53 final Properties defaults = new Properties();
54 defaults.put(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_HOST_OCES1, "fenris.certifikat.dk");
55 defaults.put(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_PORT_OCES1, "389");
56 return new PropertiesSOSIConfiguration(properties, defaults);
57 }
58
59 public PropertiesSOSIConfiguration(Properties props) {
60 this(props, new Properties());
61 }
62
63 public PropertiesSOSIConfiguration(Properties props, Properties defaults) {
64 this.properties = props;
65 this.defaultValues = defaults;
66 }
67
68 public void verify() {
69 if (getProperty("sosi:certificate.checker") != null) {
70 throw new RuntimeException("sosi:certificate.checker - no longer supported");
71 }
72 }
73
74 public String getLdapCertificateHostOCES1() {
75 String value = getProperty(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_HOST_OCES1);
76 if (value == null) {
77 throw new IllegalArgumentException("Property '" + SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_HOST_OCES1 + "' is not defined.");
78 }
79 return value;
80 }
81
82 public int getLdapCertificatePortOCES1() {
83 String value = getProperty(SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_PORT_OCES1);
84 if (value == null) {
85 throw new IllegalArgumentException("Property '" + SOSIFactory.PROPERTYNAME_SOSI_LDAP_CERTIFICATE_PORT_OCES1 + "' is not defined.");
86 }
87 return Integer.valueOf(value);
88 }
89
90 public AuditEventHandler getAuditEventHandler() {
91 String className = properties.getProperty(
92 SOSIFactory.PROPERTYNAME_SOSI_FEDERATION_AUDITHANDLER,
93 SOSIFactory.SOSI_DEFAULT_AUDIT_EVENT_HANDLER);
94 if(className == null) {
95 return null;
96 }
97 try {
98 return (AuditEventHandler) Class.forName(className).newInstance();
99 } catch (SecurityException e) {
100 throw new ModelException("Failed to construct audit handler", e);
101 } catch (ClassNotFoundException e) {
102 throw new ModelException("Failed to construct audit handler", e);
103 } catch (IllegalArgumentException e) {
104 throw new ModelException("Failed to construct audit handler", e);
105 } catch (InstantiationException e) {
106 throw new ModelException("Failed to construct audit handler", e);
107 } catch (IllegalAccessException e) {
108 throw new ModelException("Failed to construct audit handler", e);
109 }
110 }
111
112 public String getProperty(String name) {
113 if (properties.containsKey(name)) {
114 return properties.getProperty(name);
115 } else {
116 return defaultValues.getProperty(name);
117 }
118 }
119 }