summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@novemberain.com>2015-11-06 09:24:30 +0300
committerMichael Klishin <michael@novemberain.com>2015-11-06 09:24:30 +0300
commit32f97ff1f795551e46231ca32c9c82f8cddcf73b (patch)
treecaf679626c550d7a50eb14b383f225076d2639cc
parentfbc33dcaa55a9f416545e6d24add4ae227af9334 (diff)
parent1f8de3d70695b662ce396ff3c5e6bea85b49269b (diff)
downloadrabbitmq-server-git-32f97ff1f795551e46231ca32c9c82f8cddcf73b.tar.gz
Merge pull request #405 from rabbitmq/rabbitmq-server-119
Adds authentication command to rabbitmqctl.
-rw-r--r--docs/rabbitmqctl.1.xml27
-rw-r--r--src/rabbit_cli.erl6
-rw-r--r--src/rabbit_control_main.erl5
-rw-r--r--src/rabbit_ctl_misc.erl31
-rw-r--r--test/src/rabbit_tests.erl8
5 files changed, 77 insertions, 0 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml
index 82fb92b36f..f138ecff6c 100644
--- a/docs/rabbitmqctl.1.xml
+++ b/docs/rabbitmqctl.1.xml
@@ -722,6 +722,33 @@
</varlistentry>
<varlistentry>
+ <term>
+ <cmdsynopsis>
+ <command>authenticate_user</command> <arg choice="req"><replaceable>username</replaceable></arg> <arg choice="req"><replaceable>password</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <variablelist>
+ <varlistentry>
+ <term>username</term>
+ <listitem><para>The name of the user.</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>password</term>
+ <listitem><para>The password of the user.</para></listitem>
+ </varlistentry>
+ </variablelist>
+ <para role="example-prefix">For example:</para>
+ <screen role="example">rabbitmqctl authenticate_user tonyg verifyit</screen>
+ <para role="example">
+ This command instructs the RabbitMQ broker to authenticate the
+ user named <command>tonyg</command> with password
+ <command>verifyit</command>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><cmdsynopsis><command>set_user_tags</command> <arg choice="req"><replaceable>username</replaceable></arg> <arg choice="req"><replaceable>tag</replaceable> ...</arg></cmdsynopsis></term>
<listitem>
<variablelist>
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl
index 33098ce16b..1dfbb11b2a 100644
--- a/src/rabbit_cli.erl
+++ b/src/rabbit_cli.erl
@@ -66,6 +66,9 @@ main(ParseFun, DoFun, UsageMod) ->
case catch DoFun(Command, Node, Args, Opts) of
ok ->
rabbit_misc:quit(0);
+ {ok, Result} ->
+ rabbit_ctl_misc:print_cmd_result(Command, Result),
+ rabbit_misc:quit(0);
{'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> %% < R15
PrintInvalidCommandError(),
usage(UsageMod);
@@ -106,6 +109,9 @@ main(ParseFun, DoFun, UsageMod) ->
print_error("unable to connect to nodes ~p: ~w", [Nodes, Reason]),
print_badrpc_diagnostics(Nodes),
rabbit_misc:quit(2);
+ {refused, Username, _, _} ->
+ print_error("failed to authenticate user \"~s\"", [Username]),
+ rabbit_misc:quit(2);
Other ->
print_error("~p", [Other]),
rabbit_misc:quit(2)
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index c988ff1a49..1d98e5a354 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -52,6 +52,7 @@
delete_user,
change_password,
clear_password,
+ authenticate_user,
set_user_tags,
list_users,
@@ -379,6 +380,10 @@ action(clear_password, Node, Args = [Username], _Opts, Inform) ->
Inform("Clearing password for user \"~s\"", [Username]),
call(Node, {rabbit_auth_backend_internal, clear_password, Args});
+action(authenticate_user, Node, Args = [Username, _Password], _Opts, Inform) ->
+ Inform("Authenticating user \"~s\"", [Username]),
+ call(Node, {rabbit_access_control, check_user_pass_login, Args});
+
action(set_user_tags, Node, [Username | TagsStr], _Opts, Inform) ->
Tags = [list_to_atom(T) || T <- TagsStr],
Inform("Setting tags for user \"~s\" to ~p", [Username, Tags]),
diff --git a/src/rabbit_ctl_misc.erl b/src/rabbit_ctl_misc.erl
new file mode 100644
index 0000000000..92ae111028
--- /dev/null
+++ b/src/rabbit_ctl_misc.erl
@@ -0,0 +1,31 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_ctl_misc).
+
+-export([print_cmd_result/2]).
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(print_cmd_result/2 :: (atom(), term()) -> string()).
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
+print_cmd_result(authenticate_user, _Result) -> io:format("Success~n").
diff --git a/test/src/rabbit_tests.erl b/test/src/rabbit_tests.erl
index e85cf98864..d4072c62c4 100644
--- a/test/src/rabbit_tests.erl
+++ b/test/src/rabbit_tests.erl
@@ -1015,6 +1015,11 @@ test_user_management() ->
TestTags([administrator]),
TestTags([]),
+ %% user authentication
+ ok = control_action(authenticate_user, ["foo", "baz"]),
+ {refused, _User, _Format, _Params} =
+ control_action(authenticate_user, ["foo", "bar"]),
+
%% vhost creation
ok = control_action(add_vhost, ["/testhost"]),
{error, {vhost_already_exists, _}} =
@@ -1731,6 +1736,9 @@ control_action(Command, Node, Args, Opts) ->
ok ->
io:format("done.~n"),
ok;
+ {ok, Result} ->
+ rabbit_ctl_misc:print_cmd_result(Command, Result),
+ ok;
Other ->
io:format("failed.~n"),
Other