001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/security/owsrequestvalidator/csw/DescribeRecordRequestValidator.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.datatypes.QualifiedName;
039    import org.deegree.datatypes.Types;
040    import org.deegree.model.feature.Feature;
041    import org.deegree.model.feature.FeatureFactory;
042    import org.deegree.model.feature.FeatureProperty;
043    import org.deegree.model.feature.schema.FeatureType;
044    import org.deegree.model.feature.schema.PropertyType;
045    import org.deegree.ogcwebservices.InvalidParameterValueException;
046    import org.deegree.ogcwebservices.OGCWebServiceRequest;
047    import org.deegree.ogcwebservices.csw.discovery.DescribeRecord;
048    import org.deegree.portal.standard.security.control.ClientHelper;
049    import org.deegree.security.UnauthorizedException;
050    import org.deegree.security.drm.model.RightType;
051    import org.deegree.security.drm.model.User;
052    import org.deegree.security.owsproxy.Condition;
053    import org.deegree.security.owsproxy.Request;
054    import org.deegree.security.owsrequestvalidator.Policy;
055    
056    /**
057     *
058     *
059     *
060     * @version $Revision: 18195 $
061     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
062     * @author last edited by: $Author: mschneider $
063     *
064     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
065     *
066     * @since 2.0
067     */
068    class DescribeRecordRequestValidator extends AbstractCSWRequestValidator {
069    
070        private static FeatureType drtFT = null;
071    
072        static {
073            if ( drtFT == null ) {
074                drtFT = DescribeRecordRequestValidator.createFeatureType();
075            }
076        }
077    
078        /**
079         * @param policy
080         */
081        public DescribeRecordRequestValidator( Policy policy ) {
082            super( policy );
083        }
084    
085        /*
086         * (non-Javadoc)
087         *
088         * @see org.deegree_impl.security.RequestValidator#validateRequest(org.deegree.services.OGCWebServiceRequest,
089         *      java.lang.String)
090         */
091        @Override
092        public void validateRequest( OGCWebServiceRequest request, User user )
093                                throws InvalidParameterValueException, UnauthorizedException {
094            userCoupled = false;
095            Request req = policy.getRequest( "CSW", "DescribeRecord" );
096            // request is valid because no restrictions are made
097            if ( req.isAny() || req.getPreConditions().isAny() ) {
098                return;
099            }
100            Condition condition = req.getPreConditions();
101    
102            DescribeRecord cswreq = (DescribeRecord) request;
103    
104            validateVersion( condition, cswreq.getVersion() );
105    
106            if ( userCoupled ) {
107                validateAgainstRightsDB( cswreq, user );
108            }
109        }
110    
111        /**
112         * validates the passed WMS GetMap request against a User- and Rights-Management DB.
113         *
114         * @param wmsreq
115         * @param user
116         * @throws InvalidParameterValueException
117         */
118        private void validateAgainstRightsDB( DescribeRecord wfsreq, User user )
119                                throws InvalidParameterValueException, UnauthorizedException {
120    
121            if ( user == null ) {
122                throw new UnauthorizedException( "no access to anonymous user" );
123            }
124    
125            // create feature that describes the map request
126            FeatureProperty[] fps = new FeatureProperty[2];
127            fps[0] = FeatureFactory.createFeatureProperty( new QualifiedName( "version" ), wfsreq.getVersion() );
128            fps[1] = FeatureFactory.createFeatureProperty( new QualifiedName( "outputformat" ), wfsreq.getOutputFormat() );
129    
130            Feature feature = FeatureFactory.createFeature( "id", drtFT, fps );
131            handleUserCoupledRules( user, feature, "", ClientHelper.TYPE_METADATASCHEMA, RightType.DESCRIBERECORDTYPE );
132    
133        }
134    
135        /**
136         * creates a feature type that matches the parameters of a GetLagendGraphic request
137         *
138         * @return created <tt>FeatureType</tt>
139         */
140        private static FeatureType createFeatureType() {
141            PropertyType[] ftps = new PropertyType[2];
142            ftps[0] = FeatureFactory.createSimplePropertyType( new QualifiedName( "version" ), Types.VARCHAR, false );
143            ftps[1] = FeatureFactory.createSimplePropertyType( new QualifiedName( "outputformat" ), Types.VARCHAR, false );
144    
145            return FeatureFactory.createFeatureType( "DescribeRecord", false, ftps );
146        }
147    
148    }