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