    001    //$HeadURL: svn+ssh://rbezema@wald.intevation.org/deegree/base/trunk/src/org/deegree/security/owsrequestvalidator/csw/GetRecordsResponseValidator.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.csw;
    037
    038    import org.deegree.framework.util.MimeTypeMapper;
    039    import org.deegree.ogcwebservices.InvalidParameterValueException;
    040    import org.deegree.security.drm.model.User;
    041    import org.deegree.security.owsproxy.Request;
    042    import org.deegree.security.owsrequestvalidator.Policy;
    043    import org.deegree.security.owsrequestvalidator.ResponseValidator;
    044
    045    /**
    046     *
    047     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
    048     * @author last edited by: $Author: wanhoff $
    049     *
    050     * @version 1.1, $Revision: 6375 $, $Date: 2007-03-26 14:04:38 +0200 (Mo, 26 Mrz 2007) $
    051     */
    052    class GetRepositoryItemResponseValidator extends ResponseValidator {
    053
    054        /**
    055         * @param policy
    056         */
    057        public GetRepositoryItemResponseValidator( Policy policy ) {
    058            super( policy );
    059        }
    060
    061        /**
    062         * validates the passed object as a response to a OWS request. The validity of the response may
    063         * is assigned to specific user rights. If the passed user is <>null this will be evaluated.
    064         * <br>
    065         * the reponse may contain three valid kinds of objects:
    066         * <ul>
    067         * <li>a xml encoded exception
    068         * <li>a GML document
    069         * <li>a XML document
    070         * <li>any other kind of document that is valid against the formats defined for GetRecord in
    071         * the capabilities
    072         * </ul>
    073         * Each of these types can be identified by the mime-type of the response that is also passed to
    074         * the method. <br>
    075         * If something basic went wrong it is possible that not further specified kind of object is
    076         * passed as response. In this case the method will throw an
    077         * <tt>InvalidParameterValueException</tt> to avoid sending bad responses to the client.
    078         *
    079         * @param service
    080         *            service which produced the response (WMS, WFS ...)
    081         * @param response
    082         * @param mime
    083         *            mime-type of the response
    084         * @param user
    085         * @return the response array
    086         * @throws InvalidParameterValueException
    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, "GetRecord" );
    093            // request is valid because no restrictions are made
    094            if ( req.isAny() || req.getPostConditions().isAny() ) {
    095                return response;
    096            }
    097
    098            // Condition condition = req.getPostConditions();
    099
    100            if ( MimeTypeMapper.isKnownOGCType( mime ) ) {
    101                // if the mime-type isn't an image type but a known
    102                // OGC mime-type it must be an XML document.
    103                // probably it is an exception but it also could be
    104                // a GML document
    105                response = validateXML( response, mime, user );
    106            } else if ( mime.equals( "text/xml" ) ) {
    107                // if the mime-type isn't an image type but 'text/xml'
    108                // it could be an exception
    109                response = validateXML( response, mime, user );
    110            } else {
    111                throw new InvalidParameterValueException( UNKNOWNMIMETYPE + mime );
    112            }
    113
    114            return response;
    115        }
    116
    117        /**
    118         * validates the passed byte array to be valid against the policy
    119         *
    120         * @param xml
    121         * @param mime
    122         * @param user
    123         */
    124        private byte[] validateXML( byte[] xml, String mime, User user ) {
    125            // TODO
    126            // define useful post-validation for xml-documents
    127            // at the moment everything is valid
    128            return xml;
    129        }
    130
    131    }