/home/tetron/hack/vos/libs/vos/vos/acl.hh
Go to the documentation of this file.00001 #ifndef _ACL_HH_
00002 #define _ACL_HH_
00003
00004 #include <vos/vos/iterator.hh>
00005
00006 namespace VOS {
00007 class Identity;
00008 class Group;
00009 class VobjectIterator;
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 class VOS_API AccessControlList : public VUtil::RefCounted
00020 {
00021 private:
00022 mutable boost::mutex acl_mutex;
00023
00024 mutable std::set<Identity*> identity_members;
00025 mutable std::set<Group*> group_members;
00026 std::map<std::string, std::string> policies;
00027
00028 public:
00029
00030
00031
00032
00033 AccessControlList(const std::string& policy);
00034
00035
00036
00037
00038
00039 static std::string canonicalizeName(const std::string& policy);
00040
00041
00042
00043
00044 std::string getPolicyName() const;
00045
00046
00047
00048
00049 VobjectIterator getMembers() const;
00050
00051
00052 std::string getPolicy(const std::string& domain);
00053
00054
00055 void add(Identity*);
00056
00057
00058 void add(Group*);
00059
00060
00061 void remove(Identity*);
00062
00063
00064 void remove(Group*);
00065
00066
00067 bool hasIdentity(Identity*) const;
00068
00069
00070 bool hasGroup(Group*) const;
00071
00072
00073
00074 bool hasGroupWith(Identity* id) const;
00075
00076 static std::string mapToString(const std::map<std::string, std::string>& policies);
00077 static void stringToMap(const std::string& aclname, std::map<std::string, std::string>& policies);
00078 };
00079 }
00080
00081 namespace VUtil {
00082 template<> inline void iteratorReleaseItem(VOS::AccessControlList** v)
00083 {
00084 (*v)->release();
00085 }
00086 }
00087
00088 namespace VOS {
00089
00090
00091
00092 class VOS_API ACLIterator : public VUtil::Iterator<AccessControlList*>
00093 {
00094 public:
00095 ACLIterator() : VUtil::Iterator<AccessControlList*>() { }
00096 ACLIterator(const ACLIterator& i) : VUtil::Iterator<AccessControlList*>(i) { }
00097 ACLIterator(const std::map<std::string, AccessControlList*>& aclset) {
00098 items->resize(aclset.size());
00099 int c = 0;
00100 for(std::map<std::string, AccessControlList*>::const_iterator i = aclset.begin();
00101 i != aclset.end();
00102 i++)
00103 {
00104 (*items)[c] = (*i).second;
00105 (*items)[c]->acquire();
00106 c++;
00107 }
00108 }
00109 ACLIterator(const std::vector<AccessControlList*>& aclset) {
00110 items->resize(aclset.size());
00111 for(unsigned int i = 0; i < aclset.size(); i++) {
00112 (*items)[i] = aclset[i];
00113 (*items)[i]->acquire();
00114 }
00115 }
00116
00117 VUtil::vRef<AccessControlList> operator*() {
00118 if(pos < items->size())
00119 return VUtil::vRef<AccessControlList>((*items)[pos], true);
00120 else return VUtil::vRef<AccessControlList>();
00121 }
00122 };
00123 };
00124
00125 #endif