001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/security/owsrequestvalidator/wms/GetFeatureInfoResponseValidator.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     53177 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.framework.util.MimeTypeMapper;
046    import org.deegree.ogcwebservices.InvalidParameterValueException;
047    import org.deegree.ogcwebservices.OGCWebServiceRequest;
048    import org.deegree.security.drm.model.User;
049    import org.deegree.security.owsproxy.Request;
050    import org.deegree.security.owsrequestvalidator.Policy;
051    import org.deegree.security.owsrequestvalidator.ResponseValidator;
052    
053    /**
054     * 
055     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
056     * @author last edited by: $Author: apoth $
057     * 
058     * @version $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
059     */
060    class GetFeatureInfoResponseValidator extends ResponseValidator {
061    
062        /**
063         * @param policy
064         */
065        public GetFeatureInfoResponseValidator( Policy policy ) {
066            super( policy );
067        }
068    
069        /**
070         * validates the passed object as a response to a OWS request. The validity of the response may
071         * is assigned to specific user rights. If the passed user is <>null this will be evaluated.
072         * <br>
073         * the reponse may contain three valid kinds of objects:
074         * <ul>
075         * <li>a xml encoded exception
076         * <li>a GML document
077         * <li>a XML document
078         * <li>any other kind of document that is valid against the formats defined for GetFeatureInfo
079         * in the capabilities
080         * </ul>
081         * Each of these types can be identified by the mime-type of the response that is also passed to
082         * the method. <br>
083         * If something basic went wrong it is possible that not further specified kind of object is
084         * passed as response. In this case the method will throw an
085         * <tt>InvalidParameterValueException</tt> to avoid sending bad responses to the client.
086         * 
087         * @param service
088         *            service which produced the response (WMS, WFS ...)
089         * @param response
090         * @param mime
091         *            mime-type of the response
092         * @param user
093         * @return
094         * @throws InvalidParameterValueException
095         * @see GetMapRequestValidator#validateRequest(OGCWebServiceRequest, User)
096         */
097        public byte[] validateResponse( String service, byte[] response, String mime, User user )
098                                throws InvalidParameterValueException {
099    
100            Request req = policy.getRequest( service, "GetFeatureInfo" );
101            // request is valid because no restrictions are made
102            if ( req.isAny() )
103                return response;
104    
105            // Condition condition = req.getPostConditions();
106    
107            if ( MimeTypeMapper.isKnownImageType( mime ) ) {
108                response = validateImage( response, mime, user );
109            } else if ( MimeTypeMapper.isKnownOGCType( mime ) ) {
110                // if the mime-type isn't an image type but a known
111                // OGC mime-type it must be an XML document.
112                // probably it is an exception but it also could be
113                // a GML document
114                response = validateXML( response, mime, user );
115            } else if ( mime.equals( "text/xml" ) ) {
116                // if the mime-type isn't an image type but 'text/xml'
117                // it could be an exception
118                response = validateXML( response, mime, user );
119            } else if ( mime.equals( "text/html" ) ) {
120                response = validateHTML( response, mime, user );
121            } else {
122                throw new InvalidParameterValueException( UNKNOWNMIMETYPE + mime );
123            }
124    
125            return response;
126        }
127    
128        /**
129         * validates the passed image to be valid against the policy
130         * 
131         * @param image
132         * @param mime
133         * @param user
134         * @throws InvalidParameterValueException
135         */
136        private byte[] validateImage( byte[] image, String mime, User user )
137                                throws InvalidParameterValueException {
138            // TODO
139            // define useful post-validation for images
140            // at the moment everything is valid
141            return image;
142        }
143    
144        /**
145         * validates the passed xml to be valid against the policy
146         * 
147         * @param xml
148         * @param mime
149         * @param user
150         * @throws InvalidParameterValueException
151         */
152        private byte[] validateXML( byte[] xml, String mime, User user )
153                                throws InvalidParameterValueException {
154            // TODO
155            // define useful post-validation for xml-documents
156            // at the moment everything is valid
157            return xml;
158        }
159    
160        /**
161         * validates the passed html to be valid against the policy
162         * 
163         * @param xml
164         * @param mime
165         * @param user
166         * @throws InvalidParameterValueException
167         */
168        private byte[] validateHTML( byte[] xml, String mime, User user )
169                                throws InvalidParameterValueException {
170            // TODO
171            // define useful post-validation for xml-documents
172            // at the moment everything is valid
173            return xml;
174        }
175    }