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