00001 #ifndef QPID_ACLMODULE_ACL_H
00002 #define QPID_ACLMODULE_ACL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "qpid/shared_ptr.h"
00026 #include "qpid/RefCounted.h"
00027 #include <map>
00028 #include <set>
00029 #include <string>
00030
00031
00032 namespace qpid {
00033
00034 namespace acl {
00035
00036 enum ObjectType {QUEUE, EXCHANGE, BROKER, LINK, ROUTE, METHOD, OBJECTSIZE};
00037 enum Action {CONSUME, PUBLISH, CREATE, ACCESS, BIND, UNBIND, DELETE, PURGE,
00038 UPDATE, ACTIONSIZE};
00039 enum Property {NAME, DURABLE, OWNER, ROUTINGKEY, PASSIVE, AUTODELETE, EXCLUSIVE, TYPE, ALTERNATE,
00040 QUEUENAME, SCHEMAPACKAGE, SCHEMACLASS};
00041 enum AclResult {ALLOW, ALLOWLOG, DENY, DENYLOG};
00042
00043 }
00044
00045 namespace broker {
00046
00047
00048 class AclModule
00049 {
00050
00051 public:
00052
00053
00054 virtual bool doTransferAcl()=0;
00055
00056 virtual bool authorise(const std::string& id, const acl::Action& action, const acl::ObjectType& objType, const std::string& name,
00057 std::map<acl::Property, std::string>* params=0)=0;
00058 virtual bool authorise(const std::string& id, const acl::Action& action, const acl::ObjectType& objType, const std::string& ExchangeName,
00059 const std::string& RoutingKey)=0;
00060
00061
00062 virtual ~AclModule() {};
00063 };
00064
00065 }
00066
00067 namespace acl {
00068
00069 class AclHelper {
00070 private:
00071 AclHelper(){}
00072 public:
00073 static inline ObjectType getObjectType(const std::string& str) {
00074 if (str.compare("queue") == 0) return QUEUE;
00075 if (str.compare("exchange") == 0) return EXCHANGE;
00076 if (str.compare("broker") == 0) return BROKER;
00077 if (str.compare("link") == 0) return LINK;
00078 if (str.compare("route") == 0) return ROUTE;
00079 if (str.compare("method") == 0) return METHOD;
00080 throw str;
00081 }
00082 static inline std::string getObjectTypeStr(const ObjectType o) {
00083 switch (o) {
00084 case QUEUE: return "queue";
00085 case EXCHANGE: return "exchange";
00086 case BROKER: return "broker";
00087 case LINK: return "link";
00088 case ROUTE: return "route";
00089 case METHOD: return "method";
00090 default: assert(false);
00091 }
00092 return "";
00093 }
00094 static inline Action getAction(const std::string& str) {
00095 if (str.compare("consume") == 0) return CONSUME;
00096 if (str.compare("publish") == 0) return PUBLISH;
00097 if (str.compare("create") == 0) return CREATE;
00098 if (str.compare("access") == 0) return ACCESS;
00099 if (str.compare("bind") == 0) return BIND;
00100 if (str.compare("unbind") == 0) return UNBIND;
00101 if (str.compare("delete") == 0) return DELETE;
00102 if (str.compare("purge") == 0) return PURGE;
00103 if (str.compare("update") == 0) return UPDATE;
00104 throw str;
00105 }
00106 static inline std::string getActionStr(const Action a) {
00107 switch (a) {
00108 case CONSUME: return "consume";
00109 case PUBLISH: return "publish";
00110 case CREATE: return "create";
00111 case ACCESS: return "access";
00112 case BIND: return "bind";
00113 case UNBIND: return "unbind";
00114 case DELETE: return "delete";
00115 case PURGE: return "purge";
00116 case UPDATE: return "update";
00117 default: assert(false);
00118 }
00119 return "";
00120 }
00121 static inline Property getProperty(const std::string& str) {
00122 if (str.compare("name") == 0) return NAME;
00123 if (str.compare("durable") == 0) return DURABLE;
00124 if (str.compare("owner") == 0) return OWNER;
00125 if (str.compare("routingkey") == 0) return ROUTINGKEY;
00126 if (str.compare("passive") == 0) return PASSIVE;
00127 if (str.compare("autodelete") == 0) return AUTODELETE;
00128 if (str.compare("exclusive") == 0) return EXCLUSIVE;
00129 if (str.compare("type") == 0) return TYPE;
00130 if (str.compare("alternate") == 0) return ALTERNATE;
00131 if (str.compare("queuename") == 0) return QUEUENAME;
00132 if (str.compare("schemapackage") == 0) return SCHEMAPACKAGE;
00133 if (str.compare("schemaclass") == 0) return SCHEMACLASS;
00134 throw str;
00135 }
00136 static inline std::string getPropertyStr(const Property p) {
00137 switch (p) {
00138 case NAME: return "name";
00139 case DURABLE: return "durable";
00140 case OWNER: return "owner";
00141 case ROUTINGKEY: return "routingkey";
00142 case PASSIVE: return "passive";
00143 case AUTODELETE: return "autodelete";
00144 case EXCLUSIVE: return "exclusive";
00145 case TYPE: return "type";
00146 case ALTERNATE: return "alternate";
00147 case QUEUENAME: return "queuename";
00148 case SCHEMAPACKAGE: return "schemapackage";
00149 case SCHEMACLASS: return "schemaclass";
00150 default: assert(false);
00151 }
00152 return "";
00153 }
00154 static inline AclResult getAclResult(const std::string& str) {
00155 if (str.compare("allow") == 0) return ALLOW;
00156 if (str.compare("allow-log") == 0) return ALLOWLOG;
00157 if (str.compare("deny") == 0) return DENY;
00158 if (str.compare("deny-log") == 0) return DENYLOG;
00159 throw str;
00160 }
00161 static inline std::string getAclResultStr(const AclResult r) {
00162 switch (r) {
00163 case ALLOW: return "allow";
00164 case ALLOWLOG: return "allow-log";
00165 case DENY: return "deny";
00166 case DENYLOG: return "deny-log";
00167 default: assert(false);
00168 }
00169 return "";
00170 }
00171
00172 typedef std::set<Property> propSet;
00173 typedef boost::shared_ptr<propSet> propSetPtr;
00174 typedef std::pair<Action, propSetPtr> actionPair;
00175 typedef std::map<Action, propSetPtr> actionMap;
00176 typedef boost::shared_ptr<actionMap> actionMapPtr;
00177 typedef std::pair<ObjectType, actionMapPtr> objectPair;
00178 typedef std::map<ObjectType, actionMapPtr> objectMap;
00179 typedef objectMap::const_iterator omCitr;
00180 typedef boost::shared_ptr<objectMap> objectMapPtr;
00181
00182
00183 static void loadValidationMap(objectMapPtr& map) {
00184 if (!map.get()) return;
00185 map->clear();
00186 propSetPtr p0;
00187
00188
00189
00190 propSetPtr p1(new propSet);
00191 p1->insert(TYPE);
00192 p1->insert(ALTERNATE);
00193 p1->insert(PASSIVE);
00194 p1->insert(DURABLE);
00195
00196 propSetPtr p2(new propSet);
00197 p2->insert(ROUTINGKEY);
00198
00199 propSetPtr p3(new propSet);
00200 p3->insert(QUEUENAME);
00201 p3->insert(ROUTINGKEY);
00202
00203 actionMapPtr a0(new actionMap);
00204 a0->insert(actionPair(CREATE, p1));
00205 a0->insert(actionPair(DELETE, p0));
00206 a0->insert(actionPair(ACCESS, p0));
00207 a0->insert(actionPair(BIND, p2));
00208 a0->insert(actionPair(UNBIND, p2));
00209 a0->insert(actionPair(ACCESS, p3));
00210 a0->insert(actionPair(PUBLISH, p0));
00211
00212 map->insert(objectPair(EXCHANGE, a0));
00213
00214
00215
00216 propSetPtr p4(new propSet);
00217 p3->insert(ALTERNATE);
00218 p3->insert(PASSIVE);
00219 p3->insert(DURABLE);
00220 p3->insert(EXCLUSIVE);
00221 p3->insert(AUTODELETE);
00222
00223 actionMapPtr a1(new actionMap);
00224 a1->insert(actionPair(ACCESS, p0));
00225 a1->insert(actionPair(CREATE, p4));
00226 a1->insert(actionPair(PURGE, p0));
00227 a1->insert(actionPair(DELETE, p0));
00228 a1->insert(actionPair(CONSUME, p0));
00229
00230 map->insert(objectPair(QUEUE, a1));
00231
00232
00233
00234 actionMapPtr a2(new actionMap);
00235 a2->insert(actionPair(CREATE, p0));
00236
00237 map->insert(objectPair(LINK, a2));
00238
00239
00240
00241 actionMapPtr a3(new actionMap);
00242 a3->insert(actionPair(CREATE, p0));
00243 a3->insert(actionPair(DELETE, p0));
00244
00245 map->insert(objectPair(ROUTE, a3));
00246
00247
00248
00249 propSetPtr p5(new propSet);
00250 p5->insert(SCHEMAPACKAGE);
00251 p5->insert(SCHEMACLASS);
00252
00253 actionMapPtr a4(new actionMap);
00254 a4->insert(actionPair(ACCESS, p5));
00255
00256 map->insert(objectPair(METHOD, a4));
00257 }
00258 };
00259
00260
00261 }}
00262
00263 #endif // QPID_ACLMODULE_ACL_H