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