001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/security/owsrequestvalidator/wms/GetMapResponseValidator.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 GetMapResponseValidator extends ResponseValidator {
054
055 /**
056 * @param policy
057 */
058 public GetMapResponseValidator( 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 serialized image
069 * <li>a xml encoded exception
070 * <li>a svg-encoded vector image
071 * </ul>
072 * Each of these types can be identified by the mime-type of the response that is also passed to
073 * the method. <br>
074 * If something basic went wrong it is possible that not further specified kind of object is
075 * passed as response. In this case the method will throw an
076 * <tt>InvalidParameterValueException</tt> to avoid sending bad responses to the client.
077 *
078 * @param service
079 * service which produced the response (WMS, WFS ...)
080 * @param response
081 * @param mime
082 * mime-type of the response
083 * @param user
084 * @return a byte array containing the response or the given response if isAny is given.
085 * @throws InvalidParameterValueException
086 * @see GetMapRequestValidator#validateRequest(OGCWebServiceRequest, User)
087 */
088 @Override
089 public byte[] validateResponse( String service, byte[] response, String mime, User user )
090 throws InvalidParameterValueException {
091
092 Request req = policy.getRequest( service, "GetMap" );
093 // request is valid because no restrictions are made
094 if ( req.isAny() || req.getPostConditions().isAny() ) {
095 return response;
096 }
097
098 //Condition postCondition = req.getPostConditions();
099
100 if ( MimeTypeMapper.isKnownImageType( mime ) ) {
101 response = validateImage( response, mime, user );
102 } else if ( MimeTypeMapper.isKnownOGCType( mime ) ) {
103 // if the mime-type isn't an image type but a known
104 // OGC mime-type it must be an XML document.
105 // probably it is an exception but it also could be
106 // a GML document
107 response = validateXML( response, mime, user );
108 } else if ( mime.equals( "text/xml" ) ) {
109 // if the mime-type isn't an image type but 'text/xml'
110 // it could be an exception
111 response = validateXML( response, mime, user );
112 } else {
113 throw new InvalidParameterValueException( UNKNOWNMIMETYPE + mime );
114 }
115
116 return response;
117 }
118
119 /**
120 * Does nothing should validate the passed object/image to be valid against the policy
121 *
122 * @param image
123 * @param mime
124 * @param user
125 * @return the image parameter.
126 */
127 private byte[] validateImage( byte[] image, String mime, User user ) {
128 // TODO
129 // define useful post-validation for images
130 // at the moment everything is valid
131
132 return image;
133 }
134
135 /**
136 * Does nothing but should validate the passed object/xml to be valid against the policy
137 *
138 * @param xml
139 * @param mime
140 * @param user
141 * @return the xml parameter.
142 */
143 private byte[] validateXML( byte[] xml, String mime, User user ) {
144 // TODO
145 // define useful post-validation for xml-documents
146 // at the moment everything is valid
147 return xml;
148 }
149 }