summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2010-09-07 13:37:16 +0100
committerSimon MacMullen <simon@rabbitmq.com>2010-09-07 13:37:16 +0100
commitefa751c2b583d4902928ced8950acc3f2e801caa (patch)
tree80b361e4634dc0d0408254b3c41841f4b27b591e
parent7a184d635b48ca1c428a56cfb0110b4359baba53 (diff)
downloadrabbitmq-server-efa751c2b583d4902928ced8950acc3f2e801caa.tar.gz
Finish adding is_admin boolean to user.
-rw-r--r--docs/rabbitmqctl.1.xml28
-rw-r--r--src/rabbit.erl2
-rw-r--r--src/rabbit_access_control.erl22
-rw-r--r--src/rabbit_control.erl4
4 files changed, 31 insertions, 25 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml
index 0f7cfcff..5179eb25 100644
--- a/docs/rabbitmqctl.1.xml
+++ b/docs/rabbitmqctl.1.xml
@@ -401,7 +401,7 @@
<variablelist>
<varlistentry>
- <term><cmdsynopsis><command>add_user</command> <arg choice="req"><replaceable>username</replaceable></arg> <arg choice="req"><replaceable>password</replaceable></arg> <arg choice="req"><replaceable>is_admin</replaceable></arg></cmdsynopsis></term>
+ <term><cmdsynopsis><command>add_user</command> <arg choice="req"><replaceable>username</replaceable></arg> <arg choice="req"><replaceable>password</replaceable></arg></cmdsynopsis></term>
<listitem>
<variablelist>
<varlistentry>
@@ -412,22 +412,12 @@
<term>password</term>
<listitem><para>The password the created user will use to log in to the broker.</para></listitem>
</varlistentry>
-
- <varlistentry>
- <term>is_admin</term>
- <listitem><para>Whether the user is an administrative
- user. This has no effect when the user logs in via
- AMQP, but can be used to permit access to additional
- features when the user logs in via some other means
- (for example with the management
- plugin).</para></listitem>
- </varlistentry>
</variablelist>
<para role="example-prefix">For example:</para>
- <screen role="example">rabbitmqctl add_user tonyg changeit true</screen>
+ <screen role="example">rabbitmqctl add_user tonyg changeit</screen>
<para role="example">
- This command instructs the RabbitMQ broker to create an
- administrative user named <command>tonyg</command> with
+ This command instructs the RabbitMQ broker to create a
+ (non-administrative) user named <command>tonyg</command> with
(initial) password
<command>changeit</command>.
</para>
@@ -489,7 +479,11 @@
<screen role="example">rabbitmqctl set_admin tonyg</screen>
<para role="example">
This command instructs the RabbitMQ broker to ensure the user
- named <command>tonyg</command> is an administrator.
+ named <command>tonyg</command> is an administrator. This has no
+ effect when the user logs in via AMQP, but can be used to permit
+ the user to manage users, virtual hosts and permissions when the
+ user logs in via some other means (for example with the
+ management plugin).
</para>
</listitem>
</varlistentry>
@@ -520,7 +514,9 @@
<para role="example-prefix">For example:</para>
<screen role="example">rabbitmqctl list_users</screen>
<para role="example">
- This command instructs the RabbitMQ broker to list all users.
+ This command instructs the RabbitMQ broker to list all
+ users. Each result row will contain the user name and
+ the administrator status of the user, in that order.
</para>
</listitem>
</varlistentry>
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 8b7f8a8a..8c36a9f0 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -496,7 +496,7 @@ insert_default_data() ->
ok = rabbit_access_control:add_vhost(DefaultVHost),
ok = rabbit_access_control:add_user(DefaultUser, DefaultPass),
case DefaultAdmin of
- true -> rabbit_access_control:set_admin(DefaultUser, true);
+ true -> rabbit_access_control:set_admin(DefaultUser);
_ -> ok
end,
ok = rabbit_access_control:set_permissions(DefaultUser, DefaultVHost,
diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl
index 65463e8e..b4af5b09 100644
--- a/src/rabbit_access_control.erl
+++ b/src/rabbit_access_control.erl
@@ -35,8 +35,8 @@
-export([check_login/2, user_pass_login/2,
check_vhost_access/2, check_resource_access/3]).
--export([add_user/2, delete_user/1, change_password/2, set_admin/2,
- list_users/0, lookup_user/1]).
+-export([add_user/2, delete_user/1, change_password/2, set_admin/1,
+ clear_admin/1, list_users/0, lookup_user/1]).
-export([add_vhost/1, delete_vhost/1, list_vhosts/0]).
-export([set_permissions/5, set_permissions/6, clear_permissions/2,
list_vhost_permissions/1, list_user_permissions/1]).
@@ -68,7 +68,8 @@
-spec(add_user/2 :: (username(), password()) -> 'ok').
-spec(delete_user/1 :: (username()) -> 'ok').
-spec(change_password/2 :: (username(), password()) -> 'ok').
--spec(set_admin/2 :: (username(), boolean()) -> 'ok').
+-spec(set_admin/1 :: (username()) -> 'ok').
+-spec(clear_admin/1 :: (username()) -> 'ok').
-spec(list_users/0 :: () -> [username()]).
-spec(lookup_user/1 ::
(username()) -> rabbit_types:ok(rabbit_types:user())
@@ -252,14 +253,21 @@ change_password(Username, Password) ->
rabbit_log:info("Changed password for user ~p~n", [Username]),
R.
+set_admin(Username) ->
+ set_admin(Username, true).
+
+clear_admin(Username) ->
+ set_admin(Username, false).
+
set_admin(Username, IsAdmin) ->
R = rabbit_misc:execute_mnesia_transaction(
rabbit_misc:with_user(
Username,
fun () ->
+ {ok, User} = lookup_user(Username),
ok = mnesia:write(rabbit_user,
- #user{username = Username,
- is_admin = IsAdmin},
+ User#user{username = Username,
+ is_admin = IsAdmin},
write)
end)),
rabbit_log:info("Set user admin flag for user ~p to ~p~n",
@@ -267,7 +275,9 @@ set_admin(Username, IsAdmin) ->
R.
list_users() ->
- mnesia:dirty_all_keys(rabbit_user).
+ [{Username, IsAdmin} ||
+ #user{username = Username, is_admin = IsAdmin} <-
+ mnesia:dirty_match_object(rabbit_user, #user{_ = '_'})].
lookup_user(Username) ->
rabbit_misc:dirty_read({rabbit_user, Username}).
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index f3ce06b9..965da011 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -211,11 +211,11 @@ action(change_password, Node, Args = [Username, _Newpassword], _Opts, Inform) ->
action(set_admin, Node, [Username], _Opts, Inform) ->
Inform("Setting administrative status for user ~p", [Username]),
- call(Node, {rabbit_access_control, set_admin, [Username, true]});
+ call(Node, {rabbit_access_control, set_admin, [Username]});
action(clear_admin, Node, [Username], _Opts, Inform) ->
Inform("Clearing administrative status for user ~p", [Username]),
- call(Node, {rabbit_access_control, set_admin, [Username, false]});
+ call(Node, {rabbit_access_control, clear_admin, [Username]});
action(list_users, Node, [], _Opts, Inform) ->
Inform("Listing users", []),