summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnupama Singh <anupamasingh31@gmail.com>2020-06-04 10:52:46 +0200
committerMichael Klishin <michael@clojurewerkz.org>2020-08-24 20:14:28 +0300
commit1a36c2eb03672505137e98860f0dd779a65f9314 (patch)
treeb22a44bee4fdc24c53153d097b93b59a0d7dd0e7
parent4d910349ad0459e25e7938e39d7d189216ca0e2f (diff)
downloadrabbitmq-server-git-1a36c2eb03672505137e98860f0dd779a65f9314.tar.gz
Checking user connection limit before starting connection
-rw-r--r--src/rabbit_reader.erl13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 79895d95fa..4335671e43 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -1218,7 +1218,8 @@ handle_method0(#'connection.open'{virtual_host = VHost},
sock = Sock,
throttle = Throttle}) ->
- ok = is_over_connection_limit(VHost, User),
+ ok = is_over_vhost_connection_limit(VHost, User),
+ ok = is_over_user_connection_limit(User),
ok = rabbit_access_control:check_vhost_access(User, VHost, {socket, Sock}, #{}),
ok = is_vhost_alive(VHost, User),
NewConnection = Connection#connection{vhost = VHost},
@@ -1317,7 +1318,7 @@ is_vhost_alive(VHostPath, User) ->
[VHostPath, User#user.username, VHostPath])
end.
-is_over_connection_limit(VHostPath, User) ->
+is_over_vhost_connection_limit(VHostPath, User) ->
try rabbit_vhost_limit:is_over_connection_limit(VHostPath) of
false -> ok;
{true, Limit} -> rabbit_misc:protocol_error(not_allowed,
@@ -1329,6 +1330,14 @@ is_over_connection_limit(VHostPath, User) ->
rabbit_misc:protocol_error(not_allowed, "vhost ~s not found", [VHostPath])
end.
+is_over_user_connection_limit(User) ->
+ case rabbit_auth_backend_internal:is_over_connection_limit(User#user.username) of
+ false -> ok;
+ {true, Limit} -> rabbit_misc:protocol_error(not_allowed,
+ "Connection refused for user '~s': "
+ "User connection limit (~p) is reached",
+ [User#user.username, Limit])
+ end.
validate_negotiated_integer_value(Field, Min, ClientValue) ->
ServerValue = get_env(Field),