diff options
| author | Matthias Radestock <matthias@lshift.net> | 2009-01-16 13:46:15 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2009-01-16 13:46:15 +0000 |
| commit | ed334fbf951ddd6337a7bf93ba5225bbad23adfd (patch) | |
| tree | 32ea85d3c1942ee466462f1eb8195ca2d1955c9a | |
| parent | b98f55452132043f05b0876c01b69416a6ceba89 (diff) | |
| download | rabbitmq-server-git-ed334fbf951ddd6337a7bf93ba5225bbad23adfd.tar.gz | |
modify table structure in preparation for permissions
| -rw-r--r-- | include/rabbit.hrl | 3 | ||||
| -rw-r--r-- | src/rabbit_access_control.erl | 33 | ||||
| -rw-r--r-- | src/rabbit_mnesia.erl | 8 |
3 files changed, 26 insertions, 18 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl index d07aeaf845..02f1ec21c7 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -30,7 +30,8 @@ %% -record(user, {username, password}). --record(user_vhost, {username, virtual_host}). +-record(permission, {configuration, messaging}). +-record(user_permission, {username, virtual_host, permission}). -record(vhost, {virtual_host, dummy}). diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index 36270efddc..e248575b60 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -113,8 +113,9 @@ internal_lookup_vhost_access(Username, VHostPath) -> rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:match_object( - #user_vhost{username = Username, - virtual_host = VHostPath}) of + #user_permission{username = Username, + virtual_host = VHostPath, + _ = '_'}) of [] -> not_found; [R] -> {ok, R} end @@ -151,7 +152,7 @@ delete_user(Username) -> Username, fun () -> ok = mnesia:delete({user, Username}), - ok = mnesia:delete({user_vhost, Username}) + ok = mnesia:delete({user_permission, Username}) end)), rabbit_log:info("Deleted user ~p~n", [Username]), R. @@ -232,23 +233,23 @@ list_vhosts() -> list_vhost_users(VHostPath) -> [Username || - #user_vhost{username = Username} <- + #user_permission{username = Username} <- %% TODO: use dirty ops instead rabbit_misc:execute_mnesia_transaction( rabbit_misc:with_vhost( VHostPath, - fun () -> mnesia:index_read(user_vhost, VHostPath, - #user_vhost.virtual_host) + fun () -> mnesia:index_read(user_permission, VHostPath, + #user_permission.virtual_host) end))]. list_user_vhosts(Username) -> [VHostPath || - #user_vhost{virtual_host = VHostPath} <- + #user_permission{virtual_host = VHostPath} <- %% TODO: use dirty ops instead rabbit_misc:execute_mnesia_transaction( rabbit_misc:with_user( Username, - fun () -> mnesia:read({user_vhost, Username}) end))]. + fun () -> mnesia:read({user_permission, Username}) end))]. map_user_vhost(Username, VHostPath) -> rabbit_misc:execute_mnesia_transaction( @@ -256,8 +257,11 @@ map_user_vhost(Username, VHostPath) -> Username, VHostPath, fun () -> ok = mnesia:write( - #user_vhost{username = Username, - virtual_host = VHostPath}) + #user_permission{username = Username, + virtual_host = VHostPath, + permission = #permission{ + configuration = ".*", + messaging = ".*"}}) end)). unmap_user_vhost(Username, VHostPath) -> @@ -265,8 +269,11 @@ unmap_user_vhost(Username, VHostPath) -> rabbit_misc:with_user_and_vhost( Username, VHostPath, fun () -> - ok = mnesia:delete_object( - #user_vhost{username = Username, - virtual_host = VHostPath}) + [ok = mnesia:delete_object(R) || + R <- mnesia:match_object( + #user_permission{username = Username, + virtual_host = VHostPath, + _ = '_'})], + ok end)). diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index eebb38fa61..31c0efbed7 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -102,10 +102,10 @@ force_reset() -> reset(true). table_definitions() -> [{user, [{disc_copies, [node()]}, {attributes, record_info(fields, user)}]}, - {user_vhost, [{type, bag}, - {disc_copies, [node()]}, - {attributes, record_info(fields, user_vhost)}, - {index, [virtual_host]}]}, + {user_permission, [{type, bag}, + {disc_copies, [node()]}, + {attributes, record_info(fields, user_permission)}, + {index, [virtual_host]}]}, {vhost, [{disc_copies, [node()]}, {attributes, record_info(fields, vhost)}]}, {rabbit_config, [{disc_copies, [node()]}]}, |
