2222-include_lib (" kernel/include/logger.hrl" ).
2323-include_lib (" rabbitmq_web_dispatch/include/rabbitmq_web_dispatch_records.hrl" ).
2424
25- dispatcher () -> [{" /ldap/validate/bind/:name " , ? MODULE , []}].
25+ dispatcher () -> [{" /ldap/validate/simple- bind" , ? MODULE , []}].
2626
2727web_ui () -> [].
2828
@@ -45,22 +45,34 @@ is_authorized(ReqData, Context) ->
4545
4646accept_content (ReqData0 , Context ) ->
4747 F = fun (_Values , BodyMap , ReqData1 ) ->
48- _Name = name (ReqData1 ),
4948 Port = rabbit_mgmt_util :parse_int (maps :get (port , BodyMap , 389 )),
5049 _UseSsl = rabbit_mgmt_util :parse_bool (maps :get (use_ssl , BodyMap , false )),
5150 _UseStartTls = rabbit_mgmt_util :parse_bool (maps :get (use_starttls , BodyMap , false )),
5251 Servers = maps :get (servers , BodyMap , []),
53- _Password = maps :get (password , BodyMap , <<" " >>),
52+ UserDN = maps :get (user_dn , BodyMap , <<" " >>),
53+ Password = maps :get (password , BodyMap , <<" " >>),
5454 Options = [
5555 {port , Port },
5656 {timeout , 5000 },
5757 {ssl , false }
5858 ],
5959 ? LOG_DEBUG (" eldap:open Servers: ~tp Options: ~tp " , [Servers , Options ]),
6060 case eldap :open (Servers , Options ) of
61- {ok , H } ->
62- eldap :close (H ),
63- {true , ReqData1 , Context };
61+ {ok , LDAP } ->
62+ ? LOG_DEBUG (" eldap:simple_bind UserDN: ~tp Password: ~tp " , [UserDN , Password ]),
63+ Result = case eldap :simple_bind (LDAP , UserDN , Password ) of
64+ ok ->
65+ {true , ReqData1 , Context };
66+ {error , invalidCredentials } ->
67+ rabbit_mgmt_util :not_authorised (" invalid credentials" , ReqData1 , Context );
68+ {error , unwillingToPerform } ->
69+ rabbit_mgmt_util :not_authorised (" invalid credentials" , ReqData1 , Context );
70+ {error , E } ->
71+ Reason = unicode_format (E ),
72+ rabbit_mgmt_util :bad_request (Reason , ReqData1 , Context )
73+ end ,
74+ eldap :close (LDAP ),
75+ Result ;
6476 {error , E } ->
6577 Reason = unicode_format (E ),
6678 rabbit_mgmt_util :bad_request (Reason , ReqData1 , Context )
@@ -70,11 +82,5 @@ accept_content(ReqData0, Context) ->
7082
7183% %--------------------------------------------------------------------
7284
73- name (ReqData ) ->
74- case rabbit_mgmt_util :id (name , ReqData ) of
75- [Value ] -> Value ;
76- Value -> Value
77- end .
78-
7985unicode_format (Arg ) ->
8086 rabbit_data_coercion :to_utf8_binary (io_lib :format (" ~tp " , [Arg ])).
0 commit comments