001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/security/owsrequestvalidator/wms/AbstractWMSRequestValidator.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 53115 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.wms;
044
045 import java.util.List;
046
047 import org.deegree.ogcwebservices.InvalidParameterValueException;
048 import org.deegree.security.owsproxy.Condition;
049 import org.deegree.security.owsproxy.OperationParameter;
050 import org.deegree.security.owsrequestvalidator.Messages;
051 import org.deegree.security.owsrequestvalidator.Policy;
052 import org.deegree.security.owsrequestvalidator.RequestValidator;
053
054 /**
055 *
056 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
057 * @author last edited by: $Author: apoth $
058 *
059 * @version $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
060 */
061 abstract class AbstractWMSRequestValidator extends RequestValidator {
062
063 // known condition parameter
064 private static final String FORMAT = "format";
065
066 private static final String MAXWIDTH = "maxWidth";
067
068 private static final String MAXHEIGHT = "maxHeight";
069
070 private static final String INVALIDFORMAT = Messages.getString( "AbstractWMSRequestValidator.INVALIDFORMAT" );
071
072 private static final String INVALIDWIDTH1 = Messages.getString( "AbstractWMSRequestValidator.INVALIDWIDTH1" );
073
074 private static final String INVALIDWIDTH2 = Messages.getString( "AbstractWMSRequestValidator.INVALIDWIDTH2" );
075
076 private static final String INVALIDHEIGHT1 = Messages.getString( "AbstractWMSRequestValidator.INVALIDHEIGHT1" );
077
078 private static final String INVALIDHEIGHT2 = Messages.getString( "AbstractWMSRequestValidator.INVALIDHEIGHT2" );
079
080 /**
081 * @param policy
082 */
083 public AbstractWMSRequestValidator( Policy policy ) {
084 super( policy );
085 }
086
087 /**
088 * checks if the passed format is valid against the formats defined in the policy. If
089 * <tt>user</ff> != <tt>null</tt> the valid
090 * formats will be read from the user/rights repository
091 * @param condition condition containing the definition of the valid format
092 * @param format
093 * @throws InvalidParameterValueException
094 */
095 protected void validateFormat( Condition condition, String format )
096 throws InvalidParameterValueException {
097
098 OperationParameter op = condition.getOperationParameter( FORMAT );
099
100 // version is valid because no restrictions are made
101 if ( op.isAny() ) {
102 return;
103 }
104
105 List list = op.getValues();
106
107 if ( !list.contains( format ) ) {
108 if ( !op.isUserCoupled() ) {
109 throw new InvalidParameterValueException( INVALIDFORMAT + format );
110 }
111 userCoupled = true;
112 }
113
114 }
115
116 /**
117 * checks if the passed width is > 0 and if it's valid against the maxWidth defined in the
118 * policy. If <tt>user</ff> != <tt>null</tt> the valid
119 * width will be read from the user/rights repository
120 * @param condition condition containing the definition of the valid width
121 * @param width
122 * @throws InvalidParameterValueException
123 */
124 protected void validateMaxWidth( Condition condition, int width )
125 throws InvalidParameterValueException {
126
127 if ( width < 1 ) {
128 throw new InvalidParameterValueException( INVALIDWIDTH1 + width );
129 }
130
131 OperationParameter op = condition.getOperationParameter( MAXWIDTH );
132
133 // version is valid because no restrictions are made
134 if ( op.isAny() ) {
135 return;
136 }
137
138 if ( width > op.getFirstAsInt() ) {
139 if ( !op.isUserCoupled() ) {
140 throw new InvalidParameterValueException( INVALIDWIDTH2 + width );
141 }
142 userCoupled = true;
143 }
144
145 }
146
147 /**
148 * checks if the passed height is > 0 and if it's valid against the maxHeight defined in the
149 * policy. If <tt>user</ff> != <tt>null</tt> the valid
150 * height will be read from the user/rights repository
151 * @param condition condition containing the definition of the valid height
152 * @param height
153 * @throws InvalidParameterValueException
154 */
155 protected void validateMaxHeight( Condition condition, int height )
156 throws InvalidParameterValueException {
157
158 if ( height < 1 ) {
159 throw new InvalidParameterValueException( INVALIDHEIGHT1 + height );
160 }
161
162 OperationParameter op = condition.getOperationParameter( MAXHEIGHT );
163
164 // version is valid because no restrictions are made
165 if ( op.isAny() ) {
166 return;
167 }
168
169 if ( height > op.getFirstAsInt() ) {
170 if ( !op.isUserCoupled() ) {
171 throw new InvalidParameterValueException( INVALIDHEIGHT2 + height );
172 }
173 userCoupled = true;
174 }
175 }
176 }