001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wass/wss/configuration/WSSConfigurationDocument.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044:
045: package org.deegree.ogcwebservices.wass.wss.configuration;
046:
047: import java.io.IOException;
048: import java.net.URL;
049:
050: import org.deegree.framework.log.ILogger;
051: import org.deegree.framework.log.LoggerFactory;
052: import org.deegree.framework.xml.InvalidConfigurationException;
053: import org.deegree.framework.xml.XMLParsingException;
054: import org.deegree.framework.xml.XMLTools;
055: import org.deegree.i18n.Messages;
056: import org.deegree.io.IODocument;
057: import org.deegree.io.JDBCConnection;
058: import org.deegree.model.metadata.iso19115.OnlineResource;
059: import org.deegree.ogcbase.CommonNamespaces;
060: import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
061: import org.deegree.ogcwebservices.wass.common.Operation_1_0;
062: import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilities;
063: import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilitiesDocument;
064: import org.w3c.dom.Element;
065: import org.w3c.dom.Node;
066: import org.xml.sax.SAXException;
067:
068: /**
069: * This class is called from the WSServiceFactory to read a configuration xml file. This file
070: * consains all the capabilities this Web Security Service is able to. The standard calling
071: * procedure is new WSSConfigurationDocument().getConfiguration( url_to_file ). This method returns
072: * the "bean" in form of a WSSConfiguration class, which can be queried for it's values.
073: *
074: * @see WSSConfiguration
075: *
076: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
077: * @author last edited by: $Author: apoth $
078: *
079: * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
080: *
081: * @since 2.0
082: */
083:
084: public class WSSConfigurationDocument extends WSSCapabilitiesDocument {
085: /**
086: *
087: */
088: private static final long serialVersionUID = 4612405238432274887L;
089:
090: /**
091: * The logger enhances the quality and simplicity of Debugging within the deegree2 framework
092: */
093: private static final ILogger LOG = LoggerFactory
094: .getLogger(WSSConfigurationDocument.class);
095:
096: private static final String DBPRE = CommonNamespaces.DGJDBC_PREFIX
097: + ":";
098:
099: /**
100: * Loads the configuration file located at the given urls location.
101: *
102: * @param serviceConfigurationUrl
103: * the url to the configuration file
104: * @return a WSSConfiguration which is a "bean" representation of the configuration xml document
105: * @throws InvalidConfigurationException
106: * if an error occrur either with opening or parsing the xml configuration file.
107: * @throws InvalidCapabilitiesException
108: */
109: public WSSConfiguration parseConfiguration(
110: URL serviceConfigurationUrl)
111: throws InvalidConfigurationException,
112: InvalidCapabilitiesException {
113:
114: WSSConfiguration result = null;
115: try {
116: load(serviceConfigurationUrl);
117: WSSCapabilities capabilities = (WSSCapabilities) parseCapabilities();
118: boolean doService = false;
119: for (Operation_1_0 operation : capabilities
120: .getOperationsMetadata().getAllOperations()) {
121: if ("DoService".equals(operation.getName())) {
122: doService = true;
123: break;
124: }
125: }
126:
127: if (!doService)
128: throw new InvalidCapabilitiesException(
129: Messages
130: .getMessage(
131: "WASS_ERROR_CAPABILITIES_MISSING_REQUIRED_OPERATION",
132: "DoService"));
133:
134: WSSDeegreeParams deegreeParams = parseDeegreeParams();
135: result = new WSSConfiguration(capabilities, deegreeParams);
136: } catch (IOException e) {
137: LOG.logError(e.getLocalizedMessage(), e);
138: throw new InvalidConfigurationException(Messages
139: .getMessage("WASS_ERROR_CONFIGURATION_NOT_READ",
140: "WSS"), e);
141: } catch (SAXException e) {
142: LOG.logError(e.getLocalizedMessage(), e);
143: throw new InvalidConfigurationException(Messages
144: .getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED",
145: "WSS"), e);
146: } catch (XMLParsingException e) {
147: LOG.logError(e.getLocalizedMessage(), e);
148: throw new InvalidConfigurationException(Messages
149: .getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED",
150: "WSS"), e);
151: }
152:
153: return result;
154: }
155:
156: /**
157: * Creates a class representation of the <code>deegreeParams</code>- section which are wss
158: * specific.
159: *
160: * @return the deegree parameter data
161: * @throws XMLParsingException
162: */
163: private WSSDeegreeParams parseDeegreeParams()
164: throws XMLParsingException {
165:
166: WSSDeegreeParams deegreeParams = null;
167:
168: final String preWSS = CommonNamespaces.DEEGREEWSS_PREFIX + ":";
169: Node root = this .getRootElement();
170:
171: Element element = (Element) XMLTools.getRequiredNode(root,
172: preWSS + "deegreeParam", nsContext);
173:
174: OnlineResource defaultOnlineResource = null;
175: defaultOnlineResource = parseOnLineResource((Element) XMLTools
176: .getRequiredNode(element, preWSS
177: + "DefaultOnlineResource", nsContext));
178:
179: // 'deegreecsw:CacheSize'-element (optional, default: 100)
180: int cacheSize = 0;
181: cacheSize = XMLTools.getNodeAsInt(element,
182: preWSS + "CacheSize", nsContext, 100);
183:
184: // 'deegreecsw:RequestTimeLimit'-element (optional, default: 15)
185: int requestTimeLimit = XMLTools.getNodeAsInt(element, preWSS
186: + "RequestTimeLimit", nsContext, 15);
187: requestTimeLimit *= 1000;
188:
189: // 'deegreecsw:Encoding'-element (optional, default: UTF-8)
190: String characterSet = null;
191: characterSet = XMLTools.getNodeAsString(element, preWSS
192: + "Encoding", nsContext, "UTF-8");
193:
194: StringBuffer sb = new StringBuffer().append("/").append(preWSS);
195: sb.append("OnlineResource");
196: StringBuffer sor = new StringBuffer(preWSS).append(
197: "SecuredServiceAddress").append(sb);
198: OnlineResource securedOnlineResource = null;
199: securedOnlineResource = parseOnLineResource((Element) XMLTools
200: .getRequiredNode(element, sor.toString(), nsContext));
201:
202: StringBuffer aor = new StringBuffer(preWSS);
203: aor.append("AuthenticationServiceAddress").append(sb);
204: OnlineResource authOnlineResource = null;
205: authOnlineResource = parseOnLineResource((Element) XMLTools
206: .getRequiredNode(element, aor.toString(), nsContext));
207:
208: int sessionLifetime = XMLTools.getNodeAsInt(element, preWSS
209: + "SessionLifetime", nsContext, 1200);
210: sessionLifetime *= 1000;
211:
212: // parse database connection
213: Element database = (Element) XMLTools.getNode(element, DBPRE
214: + "JDBCConnection", nsContext);
215: JDBCConnection dbConnection = null;
216: if (database != null) {
217: IODocument io = new IODocument(database);
218: dbConnection = io.parseJDBCConnection();
219: }
220:
221: deegreeParams = new WSSDeegreeParams(defaultOnlineResource,
222: cacheSize, requestTimeLimit, characterSet,
223: securedOnlineResource, authOnlineResource,
224: sessionLifetime, dbConnection);
225:
226: return deegreeParams;
227: }
228: }
|