Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/accesscontrol.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 #ifndef _ACCESSCONTROL_HH_
00024 #define _ACCESSCONTROL_HH_
00025 
00026 #include <vos/corelibs/vos/vosdefs.hh>
00027 
00028 #include <string>
00029 #include <map>
00030 #include <deque>
00031 
00032 /** @file
00033     Defines VobjectAccessControl, NoAccessControl, ReadOnlyAccessControl and LocalOnlyAccessControl
00034 */
00035 
00036 namespace VOS
00037 {
00038 class VobjectAccessControl;
00039     class LocalVobject;
00040     class Vobject;
00041     class VobjectEvent;
00042     class Site;
00043 
00044 typedef VobjectAccessControl* (*VobjectAccessControlFactory)(const string& type, LocalVobject* lv);
00045 
00046 
00047 /** @class VobjectAccessControl accesscontrol.hh vos/corelibs/vos/accesscontrol.hh
00048  * This is the base class for Vobject access control policies.  A
00049     policy decides whether a particular action on Vobject is
00050     permitted.  This class also stores a mapping of text strings to
00051     control policies, so that a user may request a policy by name
00052     (such as "readonly") rather than having to supply the class
00053     directly.  This capability can also be used to save access control
00054     policies persistantly.
00055  */
00056 class VOS_API VobjectAccessControl
00057 {
00058 private:
00059     struct AssignAC
00060     {
00061         VobjectAccessControl* ac;
00062         VobjectAccessControlFactory fac;
00063     };
00064     static map<string, AssignAC> policies;
00065 
00066 public:
00067     /** Called when a child read is requested by a remote object.
00068         @param e The event to validate
00069         @returns true if allowed, false if denied
00070     */
00071     virtual bool checkReadChildPermission(VobjectEvent& e, string& message) = 0;
00072 
00073     /** Called when a type read is requested by a remote object.
00074         @param e The event to validate
00075         @returns true if allowed, false if denied
00076     */
00077     virtual bool checkReadTypePermission(VobjectEvent& e, string& message) = 0;
00078 
00079     /** Called when a type add is requested by a remote object.
00080         @param e The event to validate
00081         @returns true if allowed, false if denied
00082     */
00083     virtual bool checkAddTypePermission(VobjectEvent& e, string& message) = 0;
00084 
00085     /** Called when a parent read is requested by a remote object
00086         @param e The event to validate
00087         @returns true if allowed, false if denied
00088     */
00089     virtual bool checkReadParentPermission(VobjectEvent& e, string& message) = 0;
00090 
00091     /** Called when a child replace is requested by a remote object.
00092         @param e The event to validate
00093         @returns true if allowed, false if denied
00094     */
00095     virtual bool checkSetChildPermission(VobjectEvent& e, string& message) = 0;
00096 
00097     /** Called when a child insert is requested by a remote object.
00098         @param e The event to validate
00099         @returns true if allowed, false if denied
00100     */
00101     virtual bool checkInsertChildPermission(VobjectEvent& e, string& message) = 0;
00102 
00103     /** Called when a child remove is requested by a remote object.
00104         @param e The event to validate
00105         @returns true if allowed, false if denied
00106     */
00107     virtual bool checkRemoveChildPermission(VobjectEvent& e, string& message) = 0;
00108 
00109     /** Called when a remote object wants to listen to the child list of some
00110         object.
00111         @param e The event to validate
00112         @returns true if allowed, false if denied
00113     */
00114     virtual bool checkChildListenPermission(VobjectEvent& e, string& message) = 0;
00115 
00116     /** Called when a remote object wants to listen to the parent set of some
00117         object.
00118         @param e The event to validate
00119         @returns true if allowed, false if denied
00120     */
00121     virtual bool checkParentListenPermission(VobjectEvent& e, string& message) = 0;
00122 
00123 
00124     /** Get a short string describing this policy. */
00125     virtual const string getPolicyName() = 0;
00126 
00127     /** Add a new access control policy.  This policy will be
00128         available as whatever name is returned by ac->getPolicyName().
00129         @param ac The policy object.
00130     */
00131     static void addPolicy(VobjectAccessControl* ac);
00132 
00133     /** Add a new access control policy.  The difference between this
00134         and the other addPolicy method is that a policy factory
00135         creates a new policy object each time getPolicy() is called,
00136         whereas otherwise the same policy object will be returned each
00137         time.  This is useful if you want to write an access control
00138         policy bound to a specific object that keeps some state about that
00139         object.
00140         @param name The policy name.  This should be the same as the name
00141         returned by getPolicyName() for the factory-created objects.
00142         @param ac The policy factory.
00143     */
00144     static void addPolicyFactory(const string& name, VobjectAccessControlFactory ac);
00145 
00146     /** Get the requested policy given the name and LocalVobject.
00147         @param name The policy name, registered at some point using addPolicy()
00148         @param lv The LocalVobject this policy will be added to
00149         (doesn't actually add it, but a policy factory may want to
00150         know what object it is being added to)
00151         @return the policy object, or NULL if there is no registered policy with that name
00152     */
00153     static VobjectAccessControl* getPolicy(const string& name, LocalVobject* lv);
00154 
00155     /** Remove policy with the given name.
00156         @param name policy name
00157     */
00158     static void removePolicy(const string& name);
00159 };
00160 
00161 /** @class SiteAccessControl accesscontrol.hh vos/corelibs/vos/accesscontrol.hh
00162  * Additional policy interface specificly for Sites.  */
00163 class VOS_API SiteAccessControl : public VobjectAccessControl
00164 {
00165 public:
00166     /** Called when a remote site wishes to create an object on our local site.
00167         @param requester the remote requesting object
00168         @param site our site the object will be created on
00169         @param name the requested site name for this vobject
00170         @param types the requested type set for this vobject
00171         @returns true if allowed, false if denied
00172     */
00173     virtual bool checkCreateVobjectPermission(Vobject& requester, Site& site, const string name,
00174                                               const deque<string> types, string& message) = 0;
00175 };
00176 
00177 /** @class NoAccessControl accesscontrol.hh vos/corelibs/vos/accesscontrol.hh
00178  * Access control policy that always says yes. */
00179 class VOS_API NoAccessControl : public SiteAccessControl
00180 {
00181 public:
00182     static NoAccessControl static_;
00183 
00184     /** @returns true always */
00185     virtual bool checkReadChildPermission(VobjectEvent& e, string& message);
00186     /** @returns true always */
00187     virtual bool checkReadTypePermission(VobjectEvent& e, string& message);
00188     /** @returns true always */
00189     virtual bool checkReadParentPermission(VobjectEvent& e, string& message);
00190     /** @returns true always */
00191     virtual bool checkAddTypePermission(VobjectEvent& e, string& message);
00192     /** @returns true always */
00193     virtual bool checkSetChildPermission(VobjectEvent& e, string& message);
00194     /** @returns true always */
00195     virtual bool checkInsertChildPermission(VobjectEvent& e, string& message);
00196     /** @returns true always */
00197     virtual bool checkRemoveChildPermission(VobjectEvent& e, string& message);
00198     /** @returns true always */
00199     virtual bool checkCreateVobjectPermission(Vobject& requester, Site& site, const string name,
00200                                               const deque<string> types, string& message);
00201     /** @returns true always */
00202     virtual bool checkChildListenPermission(VobjectEvent& e, string& message);
00203     /** @returns true always */
00204     virtual bool checkParentListenPermission(VobjectEvent& e, string& message);
00205 
00206     virtual const string getPolicyName();
00207 };
00208 
00209 /** @class ReadOnlyAccessControl accesscontrol.hh vos/corelibs/vos/accesscontrol.hh
00210  * Access control policy that allows requests for information (reads) and denies all
00211  * changes (writes). */
00212 class VOS_API ReadOnlyAccessControl : public SiteAccessControl
00213 {
00214 public:
00215     static ReadOnlyAccessControl static_;
00216 
00217     /** @returns true always */
00218     virtual bool checkReadChildPermission(VobjectEvent& e, string& message);
00219     /** @returns true always */
00220     virtual bool checkReadTypePermission(VobjectEvent& e, string& message);
00221     /** @returns true always */
00222     virtual bool checkReadParentPermission(VobjectEvent& e, string& message);
00223     /** @returns false always */
00224     virtual bool checkAddTypePermission(VobjectEvent& e, string& message);
00225     /** @returns false always */
00226     virtual bool checkSetChildPermission(VobjectEvent& e, string& message);
00227     /** @returns false always */
00228     virtual bool checkInsertChildPermission(VobjectEvent& e, string& message);
00229     /** @returns false always */
00230     virtual bool checkRemoveChildPermission(VobjectEvent& e, string& message);
00231     /** @returns false always */
00232     virtual bool checkCreateVobjectPermission(Vobject& requester, Site& site, const string name,
00233                                               const deque<string> types, string& message);
00234     /** @returns true always */
00235     virtual bool checkChildListenPermission(VobjectEvent& e, string& message);
00236     /** @returns true always */
00237     virtual bool checkParentListenPermission(VobjectEvent& e, string& message);
00238 
00239     virtual const string getPolicyName();
00240 };
00241 
00242 /** Access control policy that always says no.  Useful because the
00243     object is still accessable by the program, but not remotely. */
00244 class VOS_API LocalOnlyAccessControl : public SiteAccessControl
00245 {
00246 public:
00247     static LocalOnlyAccessControl static_;
00248 
00249     /** @returns false always */
00250     virtual bool checkReadChildPermission(VobjectEvent& e, string& message);
00251     /** @returns false always */
00252     virtual bool checkReadTypePermission(VobjectEvent& e, string& message);
00253     /** @returns false always */
00254     virtual bool checkReadParentPermission(VobjectEvent& e, string& message);
00255     /** @returns false always */
00256     virtual bool checkAddTypePermission(VobjectEvent& e, string& message);
00257     /** @returns false always */
00258     virtual bool checkSetChildPermission(VobjectEvent& e, string& message);
00259     /** @returns false always */
00260     virtual bool checkInsertChildPermission(VobjectEvent& e, string& message);
00261     /** @returns false always */
00262     virtual bool checkRemoveChildPermission(VobjectEvent& e, string& message);
00263     /** @returns false always */
00264     virtual bool checkCreateVobjectPermission(Vobject& requester, Site& site, const string name,
00265                                               const deque<string> types, string& message);
00266     /** @returns false always */
00267     virtual bool checkChildListenPermission(VobjectEvent& e, string& message);
00268     /** @returns false always */
00269     virtual bool checkParentListenPermission(VobjectEvent& e, string& message);
00270 
00271     virtual const string getPolicyName();
00272 };
00273 }
00274 
00275 #endif

Generated on Tue Aug 12 03:55:39 2003 for Interreality Project - VOS by doxygen 1.3.2