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