6363-export ([refresh_config_local /0 , ready_for_close /1 ]).
6464-export ([refresh_interceptors /0 ]).
6565-export ([force_event_refresh /1 ]).
66- -export ([source /2 ]).
66+ -export ([source /2 , update_user_state / 2 ]).
6767
6868-export ([init /1 , terminate /2 , code_change /3 , handle_call /3 , handle_cast /2 ,
6969 handle_info /2 , handle_pre_hibernate /1 , handle_post_hibernate /1 ,
7070 prioritise_call /4 , prioritise_cast /3 , prioritise_info /3 ,
7171 format_message_queue /2 ]).
7272
73- -deprecated ([{force_event_refresh , 1 , eventually }]).
74-
7573% % Internal
7674-export ([list_local /0 , emit_info_local /3 , deliver_reply_local /3 ]).
7775-export ([get_vhost /1 , get_user /1 ]).
@@ -452,18 +450,31 @@ ready_for_close(Pid) ->
452450
453451-spec force_event_refresh (reference ()) -> 'ok' .
454452
453+ % Note: https://www.pivotaltracker.com/story/show/166962656
454+ % This event is necessary for the stats timer to be initialized with
455+ % the correct values once the management agent has started
455456force_event_refresh (Ref ) ->
456457 [gen_server2 :cast (C , {force_event_refresh , Ref }) || C <- list ()],
457458 ok .
458459
459460list_queue_states (Pid ) ->
460461 gen_server2 :call (Pid , list_queue_states ).
461462
462- -spec source (pid (), any ()) -> any () .
463+ -spec source (pid (), any ()) -> 'ok' | { error , channel_terminated } .
463464
464465source (Pid , Source ) when is_pid (Pid ) ->
465466 case erlang :is_process_alive (Pid ) of
466- true -> Pid ! {channel_source , Source };
467+ true -> Pid ! {channel_source , Source },
468+ ok ;
469+ false -> {error , channel_terminated }
470+ end .
471+
472+ -spec update_user_state (pid (), rabbit_types :auth_user ()) -> 'ok' | {error , channel_terminated }.
473+
474+ update_user_state (Pid , UserState ) when is_pid (Pid ) ->
475+ case erlang :is_process_alive (Pid ) of
476+ true -> Pid ! {update_user_state , UserState },
477+ ok ;
467478 false -> {error , channel_terminated }
468479 end .
469480
@@ -489,6 +500,8 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
489500 _ ->
490501 Limiter0
491502 end ,
503+ % % Process dictionary is used here because permission cache already uses it. MK.
504+ put (permission_cache_can_expire , rabbit_access_control :permission_cache_can_expire (User )),
492505 MaxMessageSize = get_max_message_size (),
493506 ConsumerTimeout = get_consumer_timeout (),
494507 State = # ch {cfg = # conf {state = starting ,
@@ -691,6 +704,9 @@ handle_cast({send_drained, CTagCredit},
691704 || {ConsumerTag , CreditDrained } <- CTagCredit ],
692705 noreply (State );
693706
707+ % Note: https://www.pivotaltracker.com/story/show/166962656
708+ % This event is necessary for the stats timer to be initialized with
709+ % the correct values once the management agent has started
694710handle_cast ({force_event_refresh , Ref }, State ) ->
695711 rabbit_event :notify (channel_created , infos (? CREATION_EVENT_KEYS , State ),
696712 Ref ),
@@ -838,6 +854,10 @@ handle_info({{Ref, Node}, LateAnswer},
838854 noreply (State );
839855
840856handle_info (tick , State0 = # ch {queue_states = QueueStates0 }) ->
857+ case get (permission_cache_can_expire ) of
858+ true -> ok = clear_permission_cache ();
859+ _ -> ok
860+ end ,
841861 QueueStates1 =
842862 maps :filter (fun (_ , QS ) ->
843863 QName = rabbit_quorum_queue :queue_name (QS ),
@@ -850,7 +870,10 @@ handle_info(tick, State0 = #ch{queue_states = QueueStates0}) ->
850870 Return
851871 end ;
852872handle_info ({channel_source , Source }, State = # ch {cfg = Cfg }) ->
853- noreply (State # ch {cfg = Cfg # conf {source = Source }}).
873+ noreply (State # ch {cfg = Cfg # conf {source = Source }});
874+ handle_info ({update_user_state , User }, State = # ch {cfg = Cfg }) ->
875+ noreply (State # ch {cfg = Cfg # conf {user = User }}).
876+
854877
855878handle_pre_hibernate (State0 ) ->
856879 ok = clear_permission_cache (),
@@ -973,7 +996,7 @@ return_queue_declare_ok(#resource{name = ActualName},
973996
974997check_resource_access (User , Resource , Perm , Context ) ->
975998 V = {Resource , Context , Perm },
976-
999+
9771000 Cache = case get (permission_cache ) of
9781001 undefined -> [];
9791002 Other -> Other
@@ -1051,8 +1074,8 @@ check_topic_authorisation(_, _, _, _, _, _) ->
10511074 ok .
10521075
10531076check_topic_authorisation (# exchange {name = Name = # resource {virtual_host = VHost }, type = topic },
1054- User = # user {username = Username },
1055- AmqpParams , RoutingKey , Permission ) ->
1077+ User = # user {username = Username },
1078+ AmqpParams , RoutingKey , Permission ) ->
10561079 Resource = Name # resource {kind = topic },
10571080 VariableMap = build_topic_variable_map (AmqpParams , VHost , Username ),
10581081 Context = #{routing_key => RoutingKey ,
0 commit comments