summaryrefslogtreecommitdiff
path: root/src
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 /src
parentfbc33dcaa55a9f416545e6d24add4ae227af9334 (diff)
parent1f8de3d70695b662ce396ff3c5e6bea85b49269b (diff)
downloadrabbitmq-server-git-32f97ff1f795551e46231ca32c9c82f8cddcf73b.tar.gz
Merge pull request #405 from rabbitmq/rabbitmq-server-119
Adds authentication command to rabbitmqctl.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_cli.erl6
-rw-r--r--src/rabbit_control_main.erl5
-rw-r--r--src/rabbit_ctl_misc.erl31
3 files changed, 42 insertions, 0 deletions
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").