1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.wss4j.common.saml;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 import org.opensaml.core.config.Configuration;
26 import org.opensaml.core.xml.config.XMLConfigurationException;
27 import org.opensaml.core.xml.config.XMLConfigurator;
28 import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
29
30
31
32
33 public final class OpenSAMLBootstrap {
34
35
36 private static final String[] XML_CONFIGS = {
37 "/default-config.xml",
38 "/schema-config.xml",
39 "/saml1-assertion-config.xml",
40 "/saml1-metadata-config.xml",
41 "/saml1-protocol-config.xml",
42 "/saml2-assertion-config.xml",
43 "/saml2-assertion-delegation-restriction-config.xml",
44 "/saml2-ecp-config.xml",
45 "/saml2-metadata-algorithm-config.xml",
46 "/saml2-metadata-attr-config.xml",
47 "/saml2-metadata-config.xml",
48 "/saml2-metadata-idp-discovery-config.xml",
49 "/saml2-metadata-query-config.xml",
50 "/saml2-metadata-reqinit-config.xml",
51 "/saml2-metadata-ui-config.xml",
52 "/saml2-metadata-rpi-config.xml",
53 "/saml2-protocol-config.xml",
54 "/saml2-protocol-thirdparty-config.xml",
55 "/saml2-protocol-aslo-config.xml",
56 "/saml2-channel-binding-config.xml",
57 "/saml-ec-gss-config.xml",
58 "/signature-config.xml",
59 "/wss4j-signature-config.xml",
60 "/encryption-config.xml",
61 "/xacml20-context-config.xml",
62 "/xacml20-policy-config.xml",
63 "/xacml10-saml2-profile-config.xml",
64 "/xacml11-saml2-profile-config.xml",
65 "/xacml2-saml2-profile-config.xml",
66 "/xacml3-saml2-profile-config.xml",
67 "/saml2-xacml2-profile.xml",
68 };
69
70 private OpenSAMLBootstrap() {
71
72 }
73
74
75
76
77
78
79 public static synchronized void bootstrap() throws XMLConfigurationException {
80 bootstrap(true);
81 }
82
83 public static synchronized void bootstrap(boolean includeXacml) throws XMLConfigurationException {
84 ClassLoader loader = Thread.currentThread().getContextClassLoader();
85 try {
86 XMLConfigurator configurator = new XMLConfigurator();
87
88 Thread.currentThread().setContextClassLoader(XMLObjectProviderRegistrySupport.class.getClassLoader());
89
90 for (String config : XML_CONFIGS) {
91 if (includeXacml || !config.contains("xacml")) {
92
93 InputStream ins = Configuration.class.getResourceAsStream(config);
94 if (ins == null) {
95
96 ins = OpenSAMLBootstrap.class.getResourceAsStream(config);
97 }
98 if (ins != null) {
99 configurator.load(ins);
100 try {
101 ins.close();
102 } catch (IOException ex) {
103
104 }
105 }
106 }
107 }
108 } finally {
109 Thread.currentThread().setContextClassLoader(loader);
110 }
111 }
112
113 }