@@ -100,7 +100,7 @@ namespace rabbitmq {
100100 }
101101
102102
103- /* ** PERMISSION **********************************************************/
103+ /* ** PERMISSIONS **********************************************************/
104104
105105 void permissions::jsonize (jsontools::node & node_,
106106 const unsigned long int /* version_ */ )
@@ -113,5 +113,100 @@ namespace rabbitmq {
113113 return ;
114114 }
115115
116+ void permissions::clear () {
117+ user = " " ;
118+ vhost = " " ;
119+ configure = " " ;
120+ write = " " ;
121+ read = " " ;
122+ }
123+
124+ void permissions::vire_add_exchange_request_perms (const std::string exchange_name) {
125+ add_amqgen_to (configure);
126+ add_exchange_to (write, exchange_name);
127+ add_amqgen_to (read);
128+ }
129+
130+ void permissions::vire_add_exchange_service_perms (const std::string exchange_name) {
131+ add_amqgen_to (configure);
132+ add_amqdef_to (write);
133+ add_amqgen_to (write);
134+ add_exchange_to (read, exchange_name);
135+ add_amqgen_to (read);
136+ }
137+
138+ void permissions::vire_add_exchange_event_producer_perms (const std::string exchange_name) {
139+ add_exchange_to (write, exchange_name);
140+ }
141+
142+ void permissions::vire_add_exchange_event_listener_perms (const std::string exchange_name) {
143+ add_amqgen_to (configure);
144+ add_amqgen_to (write);
145+ add_exchange_to (read, exchange_name);
146+ add_amqgen_to (read);
147+ }
148+
149+ void permissions::vire_add_direct_request_perms () {
150+ add_amqgen_to (configure);
151+ add_amqdef_to (write);
152+ add_amqgen_to (read);
153+ }
154+
155+ void permissions::vire_add_direct_service_perms (const std::string queue_name) {
156+ add_amqdef_to (write);
157+ add_queue_to (read, queue_name);
158+ }
159+
160+ void permissions::vire_add_direct_event_producer_perms () {
161+ add_amqdef_to (write);
162+ }
163+
164+ void permissions::vire_add_direct_event_listener_perms (const std::string queue_name) {
165+ add_queue_to (read, queue_name);
166+ }
167+
168+ void permissions::add_amqgen_to (std::string & single_perm) {
169+ const std::string AMQGEN_PERM (" ^amq\\ .gen*" );
170+ add_regexp_to (single_perm, AMQGEN_PERM);
171+ }
172+
173+ void permissions::add_amqdef_to (std::string & single_perm) {
174+ const std::string AMQDEF_PERM (" ^amq\\ .default$" );
175+ add_regexp_to (single_perm, AMQDEF_PERM);
176+ }
177+
178+ void permissions::add_queue_to (std::string & single_perm, const std::string queue_name) {
179+ add_mbox_to (single_perm, queue_name);
180+ }
181+
182+ void permissions::add_exchange_to (std::string & single_perm, const std::string exchange_name) {
183+ add_mbox_to (single_perm, exchange_name);
184+ }
185+
186+ void permissions::add_mbox_to (std::string & single_perm, const std::string mbox) {
187+ const std::string mbox_perm = mbox_to_regexp (mbox);
188+ add_regexp_to (single_perm, mbox_perm);
189+ }
190+
191+ void permissions::add_regexp_to (std::string & single_perm, const std::string regexp) {
192+ if (single_perm == " " ) {
193+ single_perm = regexp;
194+ } else if (single_perm.find (regexp) == std::string::npos) {
195+ single_perm = single_perm + " |" + regexp;
196+ }
197+ }
198+
199+ std::string permissions::mbox_to_regexp (const std::string & mbox) {
200+ size_t pos = 0 ;
201+ std::string reg_mbox (mbox);
202+ while ((pos = reg_mbox.find (" ." , pos)) != std::string::npos) {
203+ reg_mbox.replace (pos, 1 , " \\ ." );
204+ pos = pos + 2 ;
205+ }
206+ reg_mbox = " ^" + reg_mbox;
207+ reg_mbox = reg_mbox + " $" ;
208+ return reg_mbox;
209+ }
210+
116211
117212} // end of namespace rabbitmq
0 commit comments