Set thread cap to a reasonable default.
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / idp / IdPConfig.java
1 /*
2  * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package edu.internet2.middleware.shibboleth.idp;
18
19 import java.net.MalformedURLException;
20 import java.net.URI;
21 import java.net.URISyntaxException;
22 import java.net.URL;
23
24 import org.apache.log4j.Logger;
25 import org.w3c.dom.Element;
26
27 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
28
29 /**
30  * @author Walter Hoehn
31  */
32 public class IdPConfig {
33
34         private String defaultRelyingPartyName;
35         private String providerId;
36         public static final String configNameSpace = "urn:mace:shibboleth:idp:config:1.0";
37         private String resolverConfig = "/conf/resolver.xml";
38         private boolean passThruErrors = false;
39         private int maxThreads = 30;
40         private String authHeaderName = "REMOTE_USER";
41         private URI defaultAuthMethod;
42         private URL AAUrl;
43
44         private static Logger log = Logger.getLogger(IdPConfig.class.getName());
45
46         public IdPConfig(Element config) throws ShibbolethConfigurationException {
47
48                 if (!config.getTagName().equals("IdPConfig")) { throw new ShibbolethConfigurationException(
49                                 "Unexpected configuration data.  <IdPConfig/> is needed."); }
50
51                 log.debug("Loading global configuration properties.");
52
53                 // Global providerId
54                 providerId = ((Element) config).getAttribute("providerId");
55                 if (providerId == null || providerId.equals("")) {
56                         log.error("Global providerId not set.  Add a (providerId) attribute to <IdPConfig/>.");
57                         throw new ShibbolethConfigurationException("Required configuration not specified.");
58                 }
59
60                 // Default Relying Party
61                 defaultRelyingPartyName = ((Element) config).getAttribute("defaultRelyingParty");
62                 if (defaultRelyingPartyName == null || defaultRelyingPartyName.equals("")) {
63                         log.error("Default Relying Party not set.  Add a (defaultRelyingParty) attribute to <IdPConfig/>.");
64                         throw new ShibbolethConfigurationException("Required configuration not specified.");
65                 }
66
67                 // Attribute resolver config file location
68                 String rawResolverConfig = ((Element) config).getAttribute("resolverConfig");
69                 if (rawResolverConfig != null && !rawResolverConfig.equals("")) {
70                         resolverConfig = rawResolverConfig;
71                 }
72
73                 // Global Pass thru error setting
74                 String attribute = ((Element) config).getAttribute("passThruErrors");
75                 if (attribute != null && !attribute.equals("")) {
76                         passThruErrors = Boolean.valueOf(attribute).booleanValue();
77                 }
78
79                 attribute = ((Element) config).getAttribute("AAUrl");
80                 if (attribute == null || attribute.equals("")) {
81                         log.error("Global Attribute Authority URL not set.  Add an (AAUrl) attribute to <IdPConfig/>.");
82                         throw new ShibbolethConfigurationException("Required configuration not specified.");
83                 }
84                 try {
85                         AAUrl = new URL(attribute);
86                 } catch (MalformedURLException e) {
87                         log.error("(AAUrl) attribute to is not a valid URL.");
88                         throw new ShibbolethConfigurationException("Required configuration is invalid.");
89                 }
90
91                 attribute = ((Element) config).getAttribute("defaultAuthMethod");
92                 if (attribute == null || attribute.equals("")) {
93                         try {
94                                 defaultAuthMethod = new URI("urn:oasis:names:tc:SAML:1.0:am:unspecified");
95                         } catch (URISyntaxException e1) {
96                                 // Shouldn't happen
97                                 throw new ShibbolethConfigurationException("Default Auth Method URI could not be constructed.");
98                         }
99                 } else {
100                         try {
101                                 defaultAuthMethod = new URI(attribute);
102                         } catch (URISyntaxException e1) {
103                                 log.error("(defaultAuthMethod) attribute to is not a valid URI.");
104                                 throw new ShibbolethConfigurationException("Required configuration is invalid.");
105                         }
106                 }
107
108                 attribute = ((Element) config).getAttribute("maxSigningThreads");
109                 if (attribute != null && !attribute.equals("")) {
110                         try {
111                                 maxThreads = Integer.parseInt(attribute);
112                         } catch (NumberFormatException e) {
113                                 log.error("(maxSigningThreads) attribute to is not a valid integer.");
114                                 throw new ShibbolethConfigurationException("Configuration is invalid.");
115                         }
116                 }
117
118                 attribute = ((Element) config).getAttribute("authHeaderName");
119                 if (attribute != null && !attribute.equals("")) {
120                         authHeaderName = attribute;
121                 }
122
123                 log.debug("Global IdP config: (AAUrl) = (" + getAAUrl() + ").");
124                 log.debug("Global IdP config: (defaultAuthMethod) = (" + getDefaultAuthMethod() + ").");
125                 log.debug("Global IdP config: (maxSigningThreads) = (" + getMaxThreads() + ").");
126                 log.debug("Global IdP config: (authHeaderName) = (" + getAuthHeaderName() + ").");
127
128                 log.debug("Global IdP config: (resolverConfig) = (" + getResolverConfigLocation() + ").");
129                 log.debug("Global IdP config: (passThruErrors) = (" + passThruErrors() + ").");
130                 log.debug("Global IdP config: Default Relying Party: (" + getDefaultRelyingPartyName() + ").");
131         }
132
133         public String getProviderId() {
134
135                 return providerId;
136         }
137
138         public String getDefaultRelyingPartyName() {
139
140                 return defaultRelyingPartyName;
141         }
142
143         public String getResolverConfigLocation() {
144
145                 return resolverConfig;
146         }
147
148         public boolean passThruErrors() {
149
150                 return passThruErrors;
151         }
152
153         public int getMaxThreads() {
154
155                 return maxThreads;
156         }
157
158         public String getAuthHeaderName() {
159
160                 return authHeaderName;
161         }
162
163         public URI getDefaultAuthMethod() {
164
165                 return defaultAuthMethod;
166         }
167
168         public URL getAAUrl() {
169
170                 return AAUrl;
171         }
172 }