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