001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/security/owsrequestvalidator/Policy.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;
044    
045    import java.util.HashMap;
046    import java.util.Map;
047    
048    import org.deegree.security.owsproxy.Condition;
049    import org.deegree.security.owsproxy.Request;
050    import org.deegree.security.owsproxy.SecurityConfig;
051    
052    /**
053     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
054     * @author last edited by: $Author: apoth $
055     * 
056     * @version $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
057     */
058    
059    public class Policy {
060    
061        private SecurityConfig securityConfig;
062    
063        private Map<String,Request> requests;
064    
065        private Condition generalCondition;
066    
067        /**
068         * @param securityConfig
069         *            configuration for accessing user based security/right informations
070         * @param requests
071         *            description of constraints for several OWS requests
072         * @param generalCondition
073         *            general security/right constraints
074         */
075        public Policy( SecurityConfig securityConfig, Condition generalCondition, Request[] requests ) {
076            this.requests = new HashMap<String,Request>();
077            this.securityConfig = securityConfig;
078            this.generalCondition = generalCondition;
079            setRequests( requests );
080        }
081    
082        /**
083         * returns the requests/condintions described by a <tt>Policy</tt>. A request objects
084         * contains conditions for each parameter and maybe for combinations of two or more parameters.
085         * 
086         * @return the requests/condintions described by a <tt>Policy</tt>.
087         * 
088         */
089        public Request[] getRequests() {
090            Request[] req = new Request[requests.size()];
091            return requests.values().toArray( req );
092        }
093    
094        /**
095         * returns one request/condintionset from the <tt>Policy</tt> matching the passed service and
096         * request name. If no request for the passed combination of service and request name is
097         * registered <tt>null</tt> will be returned
098         * 
099         * @see #getRequests()
100         * @param service
101         * @param request
102         * @return one request/condintionset from the <tt>Policy</tt> matching the passed service and
103         *         request name. If no request for the passed combination of service and request name is
104         *         registered <tt>null</tt> will be returned
105         */
106        public Request getRequest( String service, String request ) {
107            return requests.get( service + ':' + request );
108        }
109    
110        /**
111         * sets the requests/condintions described by a <tt>Policy</tt>
112         * 
113         * @see #getRequests()
114         * @param requests
115         */
116        public void setRequests( Request[] requests ) {
117            this.requests.clear();
118            for ( int i = 0; i < requests.length; i++ ) {
119                addRequest( requests[i] );
120            }
121        }
122    
123        /**
124         * adds a request/condintions to the <tt>Policy</tt>
125         * 
126         * @see #getRequests()
127         * @param request
128         */
129        public void addRequest( Request request ) {
130            String key = request.getService() + ':' + request.getName();
131            this.requests.put( key, request );
132        }
133    
134        /**
135         * removes a request/condintions from the Policy
136         * 
137         * @see #getRequests()
138         * @param service
139         * @param name
140         */
141        public void removeRequest( String service, String name ) {
142            requests.remove( service + ':' + name );
143        }
144    
145        /**
146         * sets the configuration for access to the configuration of the security persistence mechanim
147         * 
148         * @return securityConfig
149         * 
150         */
151        public SecurityConfig getSecurityConfig() {
152            return securityConfig;
153        }
154    
155        /**
156         * returns the general conditions that must be fullfilled by a request
157         * 
158         * @return the general conditions that must be fullfilled by a request
159         * 
160         */
161        public Condition getGeneralCondition() {
162            return generalCondition;
163        }
164    
165    }