001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/security/owsrequestvalidator/wfs/WFSValidator.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.wfs;
037
038 import org.deegree.ogcwebservices.InvalidParameterValueException;
039 import org.deegree.ogcwebservices.OGCWebServiceRequest;
040 import org.deegree.ogcwebservices.getcapabilities.GetCapabilities;
041 import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureType;
042 import org.deegree.ogcwebservices.wfs.operation.GetFeature;
043 import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock;
044 import org.deegree.ogcwebservices.wfs.operation.LockFeature;
045 import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction;
046 import org.deegree.security.UnauthorizedException;
047 import org.deegree.security.drm.model.User;
048 import org.deegree.security.owsrequestvalidator.Messages;
049 import org.deegree.security.owsrequestvalidator.OWSValidator;
050 import org.deegree.security.owsrequestvalidator.Policy;
051
052 /**
053 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
054 * @author last edited by: $Author: mschneider $
055 *
056 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
057 */
058 public class WFSValidator extends OWSValidator {
059
060 private static final String MS_INVALIDREQUEST = Messages.getString( "WFSValidator.WFS_INVALIDREQUEST" );
061
062 private GetFeatureRequestValidator getFeatureValidator;
063
064 private GetFeatureResponseValidator getFeatureRespValidator;
065
066 private DescribeFeatureTypeRequestValidator describeFeatureTypeValidator;
067
068 private TransactionValidator transactionValidator;
069
070 /**
071 * @param policy
072 * @param proxyURL
073 */
074 public WFSValidator( Policy policy, String proxyURL ) {
075 super( policy, proxyURL );
076 getFeatureValidator = new GetFeatureRequestValidator( policy );
077 getFeatureRespValidator = new GetFeatureResponseValidator( policy );
078 describeFeatureTypeValidator = new DescribeFeatureTypeRequestValidator( policy );
079 transactionValidator = new TransactionValidator( policy );
080 }
081
082 /**
083 * validates the passed <tt>OGCWebServiceRequest</tt> if it is valid against the defined
084 * conditions for WFS requests
085 *
086 * @param request
087 * @param user
088 * @throws InvalidParameterValueException
089 * @throws UnauthorizedException
090 */
091 @Override
092 public void validateRequest( OGCWebServiceRequest request, User user )
093 throws InvalidParameterValueException, UnauthorizedException {
094
095 if ( request instanceof GetCapabilities ) {
096 getCapabilitiesValidator.validateRequest( request, user );
097 } else if ( request instanceof GetFeature ) {
098 getFeatureValidator.validateRequest( request, user );
099 } else if ( request instanceof GetFeatureWithLock ) {
100 throw new UnauthorizedException( "GetFeatureWithLock on the WFS are not allowed!" );
101 } else if ( request instanceof LockFeature ) {
102 throw new UnauthorizedException( "Lock on the WFS are not allowed!" );
103 } else if ( request instanceof DescribeFeatureType ) {
104 describeFeatureTypeValidator.validateRequest( request, user );
105 } else if ( request instanceof Transaction ) {
106 transactionValidator.validateRequest( request, user );
107 } else {
108 throw new InvalidParameterValueException( MS_INVALIDREQUEST
109 + request.getClass().getName() );
110 }
111 }
112
113 /**
114 * @param request
115 * @param response
116 * @param mime
117 * @param user
118 * @return the new response
119 * @throws InvalidParameterValueException
120 * @throws UnauthorizedException
121 */
122 @Override
123 public byte[] validateResponse( OGCWebServiceRequest request, byte[] response, String mime,
124 User user )
125 throws InvalidParameterValueException, UnauthorizedException {
126
127 if ( request instanceof GetCapabilities ) {
128 response = getCapabilitiesValidatorR.validateResponse( "WFS", response, mime, user );
129 } else if ( request instanceof GetFeature ) {
130 response = getFeatureRespValidator.validateResponse( "WFS", response, mime, user );
131 }
132 // TODO responses to other requests
133 return response;
134 }
135 }