@@ -553,8 +553,8 @@ handle_frame_pre_auth(Transport, #stream_connection{socket = S} = Connection, St
553
553
{Connection , State , Rest };
554
554
handle_frame_pre_auth (Transport ,
555
555
# stream_connection {socket = S ,
556
- authentication_state = AuthState0 ,
557
- host = Host } = Connection0 , State ,
556
+ authentication_state = AuthState0 ,
557
+ host = Host } = Connection0 , State ,
558
558
<<? COMMAND_SASL_AUTHENTICATE :16 , ? VERSION_0 :16 , CorrelationId :32 ,
559
559
MechanismLength :16 , Mechanism :MechanismLength /binary ,
560
560
SaslFragment /binary >>, Rest ) ->
@@ -578,39 +578,39 @@ handle_frame_pre_auth(Transport,
578
578
C1 = Connection0 # stream_connection {auth_mechanism = {Mechanism , AuthMechanism }},
579
579
{C2 , FrameFragment } =
580
580
case AuthMechanism :handle_response (SaslBin , AuthState ) of
581
- {refused , Username , Msg , Args } ->
582
- rabbit_core_metrics :auth_attempt_failed (RemoteAddress , Username , stream ),
583
- auth_fail (Username , Msg , Args , C1 , State ),
584
- rabbit_log :warning (Msg , Args ),
585
- {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_AUTHENTICATION_FAILURE :16 >>};
586
- {protocol_error , Msg , Args } ->
587
- rabbit_core_metrics :auth_attempt_failed (RemoteAddress , <<>>, stream ),
588
- notify_auth_result (none , user_authentication_failure ,
589
- [{error , rabbit_misc :format (Msg , Args )}],
590
- C1 , State ),
591
- rabbit_log :warning (Msg , Args ),
592
- {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_SASL_ERROR :16 >>};
593
- {challenge , Challenge , AuthState1 } ->
594
- rabbit_core_metrics :auth_attempt_succeeded (RemoteAddress , <<>>, stream ),
595
- ChallengeSize = byte_size (Challenge ),
596
- {C1 # stream_connection {authentication_state = AuthState1 , connection_step = authenticating },
597
- <<? RESPONSE_SASL_CHALLENGE :16 , ChallengeSize :32 , Challenge /binary >>
598
- };
599
- {ok , User = # user {username = Username }} ->
600
- case rabbit_access_control :check_user_loopback (Username , S ) of
601
- ok ->
602
- rabbit_core_metrics :auth_attempt_succeeded (RemoteAddress , Username , stream ),
603
- notify_auth_result (Username , user_authentication_success ,
604
- [], C1 , State ),
605
- {C1 # stream_connection {authentication_state = done , user = User , connection_step = authenticated },
606
- <<? RESPONSE_CODE_OK :16 >>
607
- };
608
- not_allowed ->
609
- rabbit_core_metrics :auth_attempt_failed (RemoteAddress , Username , stream ),
610
- rabbit_log :warning (" User '~s ' can only connect via localhost~n " , [Username ]),
611
- {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_SASL_AUTHENTICATION_FAILURE_LOOPBACK :16 >>}
612
- end
613
- end ,
581
+ {refused , Username , Msg , Args } ->
582
+ rabbit_core_metrics :auth_attempt_failed (RemoteAddress , Username , stream ),
583
+ auth_fail (Username , Msg , Args , C1 , State ),
584
+ rabbit_log :warning (Msg , Args ),
585
+ {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_AUTHENTICATION_FAILURE :16 >>};
586
+ {protocol_error , Msg , Args } ->
587
+ rabbit_core_metrics :auth_attempt_failed (RemoteAddress , <<>>, stream ),
588
+ notify_auth_result (none , user_authentication_failure ,
589
+ [{error , rabbit_misc :format (Msg , Args )}],
590
+ C1 , State ),
591
+ rabbit_log :warning (Msg , Args ),
592
+ {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_SASL_ERROR :16 >>};
593
+ {challenge , Challenge , AuthState1 } ->
594
+ rabbit_core_metrics :auth_attempt_succeeded (RemoteAddress , <<>>, stream ),
595
+ ChallengeSize = byte_size (Challenge ),
596
+ {C1 # stream_connection {authentication_state = AuthState1 , connection_step = authenticating },
597
+ <<? RESPONSE_SASL_CHALLENGE :16 , ChallengeSize :32 , Challenge /binary >>
598
+ };
599
+ {ok , User = # user {username = Username }} ->
600
+ case rabbit_access_control :check_user_loopback (Username , S ) of
601
+ ok ->
602
+ rabbit_core_metrics :auth_attempt_succeeded (RemoteAddress , Username , stream ),
603
+ notify_auth_result (Username , user_authentication_success ,
604
+ [], C1 , State ),
605
+ {C1 # stream_connection {authentication_state = done , user = User , connection_step = authenticated },
606
+ <<? RESPONSE_CODE_OK :16 >>
607
+ };
608
+ not_allowed ->
609
+ rabbit_core_metrics :auth_attempt_failed (RemoteAddress , Username , stream ),
610
+ rabbit_log :warning (" User '~s ' can only connect via localhost~n " , [Username ]),
611
+ {C1 # stream_connection {connection_step = failure }, <<? RESPONSE_SASL_AUTHENTICATION_FAILURE_LOOPBACK :16 >>}
612
+ end
613
+ end ,
614
614
Frame = <<? COMMAND_SASL_AUTHENTICATE :16 , ? VERSION_0 :16 , CorrelationId :32 , FrameFragment /binary >>,
615
615
frame (Transport , C1 , Frame ),
616
616
{C2 , Rest };
@@ -689,9 +689,9 @@ handle_frame_post_auth(Transport, #stream_connection{socket = S, credits = Credi
689
689
PublisherId :8 /unsigned ,
690
690
MessageCount :32 , Messages /binary >>, Rest ) ->
691
691
case rabbit_stream_utils :check_write_permitted (
692
- # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
693
- User ,
694
- #{}) of
692
+ # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
693
+ User ,
694
+ #{}) of
695
695
ok ->
696
696
case lookup_leader (Stream , Connection ) of
697
697
cluster_not_found ->
@@ -721,9 +721,9 @@ handle_frame_post_auth(Transport, #stream_connection{socket = Socket,
721
721
<<? COMMAND_SUBSCRIBE :16 , ? VERSION_0 :16 , CorrelationId :32 , SubscriptionId :8 /unsigned , StreamSize :16 , Stream :StreamSize /binary ,
722
722
OffsetType :16 /signed , OffsetAndCredit /binary >>, Rest ) ->
723
723
case rabbit_stream_utils :check_read_permitted (
724
- # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
725
- User ,
726
- #{}) of
724
+ # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
725
+ User ,
726
+ #{}) of
727
727
ok ->
728
728
case rabbit_stream_manager :lookup_local_member (VirtualHost , Stream ) of
729
729
{error , not_available } ->
@@ -851,13 +851,13 @@ handle_frame_post_auth(Transport, #stream_connection{socket = S, send_file_oct =
851
851
handle_frame_post_auth (_Transport , # stream_connection {virtual_host = VirtualHost , user = User } = Connection ,
852
852
State ,
853
853
<<? COMMAND_COMMIT_OFFSET :16 , ? VERSION_0 :16 , _CorrelationId :32 ,
854
- ReferenceSize :16 , Reference :ReferenceSize /binary ,
855
- StreamSize :16 , Stream :StreamSize /binary , Offset :64 >>, Rest ) ->
854
+ ReferenceSize :16 , Reference :ReferenceSize /binary ,
855
+ StreamSize :16 , Stream :StreamSize /binary , Offset :64 >>, Rest ) ->
856
856
857
857
case rabbit_stream_utils :check_write_permitted (
858
- # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
859
- User ,
860
- #{}) of
858
+ # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
859
+ User ,
860
+ #{}) of
861
861
ok ->
862
862
case lookup_leader (Stream , Connection ) of
863
863
cluster_not_found ->
@@ -880,24 +880,24 @@ handle_frame_post_auth(Transport, #stream_connection{socket = S, virtual_host =
880
880
StreamSize :16 , Stream :StreamSize /binary >>, Rest ) ->
881
881
FrameSize = ? RESPONSE_FRAME_SIZE + 8 ,
882
882
{ResponseCode , Offset } = case rabbit_stream_utils :check_read_permitted (
883
- # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
884
- User ,
885
- #{}) of
886
- ok ->
887
- case rabbit_stream_manager :lookup_local_member (VirtualHost , Stream ) of
888
- {error , not_found } ->
889
- {? RESPONSE_CODE_STREAM_DOES_NOT_EXIST , 0 };
890
- {ok , LocalMemberPid } ->
891
- {? RESPONSE_CODE_OK , case osiris :read_tracking (LocalMemberPid , Reference ) of
892
- undefined ->
893
- 0 ;
894
- Offt ->
895
- Offt
896
- end }
897
- end ;
898
- error ->
899
- {? RESPONSE_CODE_ACCESS_REFUSED , 0 }
900
- end ,
883
+ # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
884
+ User ,
885
+ #{}) of
886
+ ok ->
887
+ case rabbit_stream_manager :lookup_local_member (VirtualHost , Stream ) of
888
+ {error , not_found } ->
889
+ {? RESPONSE_CODE_STREAM_DOES_NOT_EXIST , 0 };
890
+ {ok , LocalMemberPid } ->
891
+ {? RESPONSE_CODE_OK , case osiris :read_tracking (LocalMemberPid , Reference ) of
892
+ undefined ->
893
+ 0 ;
894
+ Offt ->
895
+ Offt
896
+ end }
897
+ end ;
898
+ error ->
899
+ {? RESPONSE_CODE_ACCESS_REFUSED , 0 }
900
+ end ,
901
901
Transport :send (S , [<<FrameSize :32 , ? COMMAND_QUERY_OFFSET :16 , ? VERSION_0 :16 >>,
902
902
<<CorrelationId :32 >>, <<ResponseCode :16 >>, <<Offset :64 >>]),
903
903
{Connection , State , Rest };
@@ -909,9 +909,9 @@ handle_frame_post_auth(Transport, #stream_connection{virtual_host = VirtualHost,
909
909
{ok , StreamName } ->
910
910
{Arguments , _Rest } = rabbit_stream_utils :parse_map (ArgumentsBinary , ArgumentsCount ),
911
911
case rabbit_stream_utils :check_configure_permitted (
912
- # resource {name = StreamName , kind = queue , virtual_host = VirtualHost },
913
- User ,
914
- #{}) of
912
+ # resource {name = StreamName , kind = queue , virtual_host = VirtualHost },
913
+ User ,
914
+ #{}) of
915
915
ok ->
916
916
case rabbit_stream_manager :create (VirtualHost , StreamName , Arguments , Username ) of
917
917
{ok , #{leader_pid := LeaderPid , replica_pids := ReturnedReplicas }} ->
@@ -940,9 +940,9 @@ handle_frame_post_auth(Transport, #stream_connection{socket = S, virtual_host =
940
940
user = # user {username = Username } = User } = Connection , State ,
941
941
<<? COMMAND_DELETE_STREAM :16 , ? VERSION_0 :16 , CorrelationId :32 , StreamSize :16 , Stream :StreamSize /binary >>, Rest ) ->
942
942
case rabbit_stream_utils :check_configure_permitted (
943
- # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
944
- User ,
945
- #{}) of
943
+ # resource {name = Stream , kind = queue , virtual_host = VirtualHost },
944
+ User ,
945
+ #{}) of
946
946
ok ->
947
947
case rabbit_stream_manager :delete (VirtualHost , Stream , Username ) of
948
948
{ok , deleted } ->
@@ -973,6 +973,8 @@ handle_frame_post_auth(Transport, #stream_connection{socket = S, virtual_host =
973
973
% % get the nodes involved in the streams
974
974
NodesMap = lists :foldl (fun (Stream , Acc ) ->
975
975
case rabbit_stream_manager :topology (VirtualHost , Stream ) of
976
+ {ok , #{leader_node := undefined , replica_nodes := ReplicaNodes }} ->
977
+ lists :foldl (fun (ReplicaNode , NodesAcc ) -> maps :put (ReplicaNode , ok , NodesAcc ) end , Acc , ReplicaNodes );
976
978
{ok , #{leader_node := LeaderNode , replica_nodes := ReplicaNodes }} ->
977
979
Acc1 = maps :put (LeaderNode , ok , Acc ),
978
980
lists :foldl (fun (ReplicaNode , NodesAcc ) -> maps :put (ReplicaNode , ok , NodesAcc ) end , Acc1 , ReplicaNodes );
0 commit comments