001    //$HeadURL: http://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/security/owsrequestvalidator/Policy.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;
037    
038    import java.util.HashMap;
039    import java.util.List;
040    import java.util.Map;
041    
042    import org.deegree.security.owsproxy.Condition;
043    import org.deegree.security.owsproxy.Request;
044    import org.deegree.security.owsproxy.SecurityConfig;
045    
046    /**
047     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
048     * @author last edited by: $Author: aschmitz $
049     * 
050     * @version $Revision: 31356 $, $Date: 2011-07-26 09:19:13 +0200 (Di, 26 Jul 2011) $
051     */
052    
053    public class Policy {
054    
055        private SecurityConfig securityConfig;
056    
057        private Map<String, Request> requests;
058    
059        private Condition generalCondition;
060    
061        private List<String> whitelist;
062    
063        /**
064         * @param securityConfig
065         *            configuration for accessing user based security/right informations
066         * @param requests
067         *            description of constraints for several OWS requests
068         * @param generalCondition
069         *            general security/right constraints
070         */
071        public Policy( SecurityConfig securityConfig, Condition generalCondition, Request[] requests ) {
072            this.requests = new HashMap<String, Request>();
073            this.securityConfig = securityConfig;
074            this.generalCondition = generalCondition;
075            setRequests( requests );
076        }
077    
078        public Policy( SecurityConfig securityConfig, Condition generalCondition, Request[] requests, List<String> whitelist ) {
079            this( securityConfig, generalCondition, requests );
080            this.whitelist = whitelist;
081        }
082    
083        /**
084         * returns the requests/condintions described by a <tt>Policy</tt>. A request objects contains conditions for each
085         * parameter and maybe for combinations of two or more parameters.
086         * 
087         * @return the requests/condintions described by a <tt>Policy</tt>.
088         * 
089         */
090        public Request[] getRequests() {
091            Request[] req = new Request[requests.size()];
092            return requests.values().toArray( req );
093        }
094    
095        /**
096         * returns one request/condintionset from the <tt>Policy</tt> matching the passed service and request name. If no
097         * request for the passed combination of service and request name is 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 request name. If no
103         *         request for the passed combination of service and request name is registered <tt>null</tt> will be
104         *         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        public List<String> getWhitelist() {
166            return whitelist;
167        }
168    
169    }