001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/security/owsrequestvalidator/csw/AbstractCSWRequestValidator.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.csw;
044
045 import java.io.IOException;
046 import java.io.StringReader;
047 import java.util.List;
048
049 import org.deegree.framework.xml.XMLFragment;
050 import org.deegree.model.filterencoding.AbstractFilter;
051 import org.deegree.model.filterencoding.ComplexFilter;
052 import org.deegree.model.filterencoding.FilterConstructionException;
053 import org.deegree.model.filterencoding.Literal;
054 import org.deegree.model.filterencoding.LogicalOperation;
055 import org.deegree.model.filterencoding.Operation;
056 import org.deegree.model.filterencoding.OperationDefines;
057 import org.deegree.model.filterencoding.PropertyIsCOMPOperation;
058 import org.deegree.model.filterencoding.PropertyName;
059 import org.deegree.ogcwebservices.InvalidParameterValueException;
060 import org.deegree.security.UnauthorizedException;
061 import org.deegree.security.owsproxy.Condition;
062 import org.deegree.security.owsrequestvalidator.Policy;
063 import org.deegree.security.owsrequestvalidator.RequestValidator;
064 import org.xml.sax.SAXException;
065
066 /**
067 * Abstract super class for validating catalogue requests.
068 *
069 * @version $Revision: 9346 $
070 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
071 * @author last edited by: $Author: apoth $
072 *
073 * @version 1.0. $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
074 *
075 * @since 2.0
076 */
077 public abstract class AbstractCSWRequestValidator extends RequestValidator {
078
079 private static final String PROPERTY_INSTANCEFILTER = "instanceFilter";
080
081 /**
082 * initializes the AbstractCSWRequestValidator by passing an instance of the policy to be used by each concrete
083 * implementation
084 *
085 * @param policy
086 */
087 public AbstractCSWRequestValidator( Policy policy ) {
088 super( policy );
089 }
090
091 /**
092 * validates the requested record type / outputTypeRec. If the current user is not allowed to request a record type
093 * (e.g. ISO 19115) an UnauthorizedException will be thrown.
094 *
095 * @param condition
096 * @param typeNames
097 * @throws InvalidParameterValueException
098 * @throws UnauthorizedException
099 */
100 public void validateRecordTypes( Condition condition, String[] typeNames ) {
101 throw new UnsupportedOperationException( "validateRecordTypes is not implemented yet" );
102 }
103
104 /**
105 *
106 * @param operation
107 * @return
108 * @throws IOException
109 * @throws SAXException
110 * @throws FilterConstructionException
111 */
112 protected ComplexFilter extractInstanceFilter( Operation operation, List<ComplexFilter> foundFilters )
113 throws SAXException, IOException, FilterConstructionException {
114 ComplexFilter filter = null;
115 if ( operation.getOperatorId() == OperationDefines.AND || operation.getOperatorId() == OperationDefines.OR ) {
116 List<Operation> arguments = ( (LogicalOperation) operation ).getArguments();
117 for ( int i = 0; i < arguments.size(); i++ ) {
118 Operation op = arguments.get( i );
119 filter = extractInstanceFilter( op, foundFilters );
120 if ( filter != null ) {
121 // foundFilters.add( filter );
122 }
123 /*
124 * if ( op.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) { PropertyName pn = (PropertyName) (
125 * (PropertyIsCOMPOperation) op ).getFirstExpression(); if ( PROPERTY_INSTANCEFILTER.equals(
126 * pn.getValue().getAsString() ) ) { Literal literal = (Literal) ( (PropertyIsCOMPOperation) op
127 * ).getSecondExpression(); StringReader sr = new StringReader( literal.getValue() ); XMLFragment xml =
128 * new XMLFragment( sr, XMLFragment.DEFAULT_URL ); filter = (ComplexFilter) AbstractFilter.buildFromDOM(
129 * xml.getRootElement() ); } }
130 */
131 }
132 } else {
133 if ( operation.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) {
134 PropertyName pn = (PropertyName) ( (PropertyIsCOMPOperation) operation ).getFirstExpression();
135 if ( PROPERTY_INSTANCEFILTER.equals( pn.getValue().getAsString() ) ) {
136 Literal literal = (Literal) ( (PropertyIsCOMPOperation) operation ).getSecondExpression();
137 StringReader sr = new StringReader( literal.getValue() );
138 XMLFragment xml = new XMLFragment( sr, XMLFragment.DEFAULT_URL );
139 filter = (ComplexFilter) AbstractFilter.buildFromDOM( xml.getRootElement() );
140 if ( filter != null ) {
141 foundFilters.add( filter );
142 }
143 }
144 }
145 }
146 return filter;
147 }
148
149 }