001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/security/owsrequestvalidator/wms/WMSValidator.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.wms;
037    
038    import org.deegree.ogcwebservices.InvalidParameterValueException;
039    import org.deegree.ogcwebservices.OGCWebServiceRequest;
040    import org.deegree.ogcwebservices.getcapabilities.GetCapabilities;
041    import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
042    import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic;
043    import org.deegree.ogcwebservices.wms.operation.GetMap;
044    import org.deegree.security.UnauthorizedException;
045    import org.deegree.security.drm.model.User;
046    import org.deegree.security.owsrequestvalidator.Messages;
047    import org.deegree.security.owsrequestvalidator.OWSValidator;
048    import org.deegree.security.owsrequestvalidator.Policy;
049    
050    /**
051     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
052     * @author last edited by: $Author: mschneider $
053     *
054     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
055     */
056    
057    public class WMSValidator extends OWSValidator {
058    
059        // message strings
060        private static final String MS_INVALIDREQUEST = Messages.getString( "WMSValidator.WMS_INVALIDREQUEST" );
061    
062        private GetMapRequestValidator getMapValidator;
063    
064        private GetMapResponseValidator getMapValidatorR;
065    
066        private GetFeatureInfoRequestValidator getFeatureInfoValidator;
067    
068        private GetFeatureInfoResponseValidator getFeatureInfoValidatorR;
069    
070        private GetLegendGraphicRequestValidator getLegendGraphicValidator;
071    
072        private GetLegendGraphicResponseValidator getLegendGraphicValidatorR;
073    
074        /**
075         * @param policy
076         * @param proxyURL
077         */
078        public WMSValidator( Policy policy, String proxyURL ) {
079            super( policy, proxyURL );
080    
081            getMapValidator = new GetMapRequestValidator( policy );
082            getMapValidatorR = new GetMapResponseValidator( policy );
083            getFeatureInfoValidator = new GetFeatureInfoRequestValidator( policy );
084            getFeatureInfoValidatorR = new GetFeatureInfoResponseValidator( policy );
085            getLegendGraphicValidator = new GetLegendGraphicRequestValidator( policy );
086            getLegendGraphicValidatorR = new GetLegendGraphicResponseValidator( policy );
087        }
088    
089        /**
090         * validates the passed <tt>OGCWebServiceRequest</tt> if it is valid against the defined
091         * conditions for WMS requests
092         *
093         * @param request
094         * @param user
095         * @throws InvalidParameterValueException
096         * @throws UnauthorizedException
097         */
098        @Override
099        public void validateRequest( OGCWebServiceRequest request, User user )
100                                throws InvalidParameterValueException, UnauthorizedException {
101            if ( request instanceof GetCapabilities ) {
102                getCapabilitiesValidator.validateRequest( request, user );
103            } else if ( request instanceof GetMap ) {
104                getMapValidator.validateRequest( request, user );
105            } else if ( request instanceof GetFeatureInfo ) {
106                getFeatureInfoValidator.validateRequest( request, user );
107            } else if ( request instanceof GetLegendGraphic ) {
108                getLegendGraphicValidator.validateRequest( request, user );
109            } else {
110                throw new InvalidParameterValueException( MS_INVALIDREQUEST
111                                                          + request.getClass().getName() );
112            }
113        }
114    
115        /**
116         * @param request
117         * @param response
118         * @param mime
119         * @param user
120         * @return the byte array containing the response.
121         * @throws InvalidParameterValueException
122         * @throws UnauthorizedException
123         */
124        @Override
125        public byte[] validateResponse( OGCWebServiceRequest request, byte[] response, String mime,
126                                        User user )
127                                throws InvalidParameterValueException, UnauthorizedException {
128            if ( request instanceof GetCapabilities ) {
129                response = getCapabilitiesValidatorR.validateResponse( "WMS", response, mime, user );
130            } else if ( request instanceof GetMap ) {
131                response = getMapValidatorR.validateResponse( "WMS", response, mime, user );
132            } else if ( request instanceof GetFeatureInfo ) {
133                response = getFeatureInfoValidatorR.validateResponse( "WMS", response, mime, user );
134            } else if ( request instanceof GetLegendGraphic ) {
135                response = getLegendGraphicValidatorR.validateResponse( "WMS", response, mime, user );
136            } else {
137                throw new InvalidParameterValueException( MS_INVALIDREQUEST
138                                                          + request.getClass().getName() );
139            }
140            return response;
141        }
142    }