001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/security/owsrequestvalidator/GetCapabilitiesRequestValidator.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    package org.deegree.security.owsrequestvalidator;
037    
038    import java.util.List;
039    
040    import org.deegree.i18n.Messages;
041    import org.deegree.ogcwebservices.InvalidParameterValueException;
042    import org.deegree.ogcwebservices.OGCWebServiceRequest;
043    import org.deegree.ogcwebservices.csw.capabilities.CatalogueGetCapabilities;
044    import org.deegree.ogcwebservices.wcs.getcapabilities.WCSGetCapabilities;
045    import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilities;
046    import org.deegree.ogcwebservices.wms.operation.WMSGetCapabilities;
047    import org.deegree.security.drm.model.User;
048    import org.deegree.security.owsproxy.Condition;
049    import org.deegree.security.owsproxy.OperationParameter;
050    import org.deegree.security.owsproxy.Request;
051    
052    /**
053     *
054     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
055     * @author last edited by: $Author: mschneider $
056     *
057     * @version 1.1, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
058     *
059     * @since 1.1
060     */
061    public class GetCapabilitiesRequestValidator extends RequestValidator {
062    
063        // known condition parameter
064        private static final String UPDATESEQUENCE = "updatesequence";
065    
066        /**
067         * @param policy
068         */
069        public GetCapabilitiesRequestValidator( Policy policy ) {
070            super( policy );
071        }
072    
073        /**
074         * validates the incoming GetCapabilities request
075         *
076         * @param request
077         *            request to validate
078         * @param user
079         *            name of the user who likes to perform the request (can be null)
080         */
081        @Override
082        public void validateRequest( OGCWebServiceRequest request, User user )
083                                throws InvalidParameterValueException {
084    
085            String[] version = null;
086            String updateSeq = null;
087            Request req = null;
088    
089            if ( request instanceof WFSGetCapabilities ) {
090                version = ( (WFSGetCapabilities) request ).getAcceptVersions();
091                if ( version == null ) {
092                    version = new String[] { ( (WFSGetCapabilities) request ).getVersion() };
093                }
094                req = policy.getRequest( "WFS", "GetCapabilities" );
095            } else if ( request instanceof WMSGetCapabilities ) {
096                version = new String[1];
097                version[0] = ( (WMSGetCapabilities) request ).getVersion();
098                updateSeq = ( (WMSGetCapabilities) request ).getUpdateSequence();
099                req = policy.getRequest( "WMS", "GetCapabilities" );
100            } else if ( request instanceof WCSGetCapabilities ) {
101                version = new String[1];
102                version[0] = ( (WCSGetCapabilities) request ).getVersion();
103                req = policy.getRequest( "WCS", "GetCapabilities" );
104            } else if ( request instanceof CatalogueGetCapabilities ) {
105                version = new String[1];
106                version[0] = ( (CatalogueGetCapabilities) request ).getVersion();
107                req = policy.getRequest( "CSW", "GetCapabilities" );
108            } else {
109                version = new String[0];
110                req = policy.getRequest( request.getServiceName(), "GetCapabilities" );
111            }
112    
113            // request is valid because no restrictions are made
114            if ( req.isAny() || req.getPreConditions().isAny() ) {
115                return;
116            }
117            for ( int i = 0; i < version.length; i++ ) {
118                validateVersion( req.getPreConditions(), version[i] );
119            }
120            validateUpdateSeq( req.getPreConditions(), updateSeq );
121    
122        }
123    
124        /**
125         *
126         * @param updateSeq
127         * @throws InvalidParameterValueException
128         */
129        private void validateUpdateSeq( Condition condition, String updateSeq )
130                                throws InvalidParameterValueException {
131            OperationParameter op = condition.getOperationParameter( UPDATESEQUENCE );
132            // updatesequence is valid because no restrictions are made
133            if ( op.isAny() ) {
134                return;
135            }
136            List<String> list = op.getValues();
137            if ( !list.contains( updateSeq ) ) {
138                if ( !op.isUserCoupled() ) {
139                    String s = Messages.getMessage( "OWSPROXY_INVALID_UPDATESEQ" );
140                    throw new InvalidParameterValueException( s );
141                }
142                userCoupled = true;
143            }
144        }
145    
146    }