22
22
-include_lib (" kernel/include/logger.hrl" ).
23
23
-include_lib (" rabbitmq_web_dispatch/include/rabbitmq_web_dispatch_records.hrl" ).
24
24
25
- dispatcher () -> [{" /ldap/validate/bind/:name " , ? MODULE , []}].
25
+ dispatcher () -> [{" /ldap/validate/simple- bind" , ? MODULE , []}].
26
26
27
27
web_ui () -> [].
28
28
@@ -45,22 +45,34 @@ is_authorized(ReqData, Context) ->
45
45
46
46
accept_content (ReqData0 , Context ) ->
47
47
F = fun (_Values , BodyMap , ReqData1 ) ->
48
- _Name = name (ReqData1 ),
49
48
Port = rabbit_mgmt_util :parse_int (maps :get (port , BodyMap , 389 )),
50
49
_UseSsl = rabbit_mgmt_util :parse_bool (maps :get (use_ssl , BodyMap , false )),
51
50
_UseStartTls = rabbit_mgmt_util :parse_bool (maps :get (use_starttls , BodyMap , false )),
52
51
Servers = maps :get (servers , BodyMap , []),
53
- _Password = maps :get (password , BodyMap , <<" " >>),
52
+ UserDN = maps :get (user_dn , BodyMap , <<" " >>),
53
+ Password = maps :get (password , BodyMap , <<" " >>),
54
54
Options = [
55
55
{port , Port },
56
56
{timeout , 5000 },
57
57
{ssl , false }
58
58
],
59
59
? LOG_DEBUG (" eldap:open Servers: ~tp Options: ~tp " , [Servers , Options ]),
60
60
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 ;
64
76
{error , E } ->
65
77
Reason = unicode_format (E ),
66
78
rabbit_mgmt_util :bad_request (Reason , ReqData1 , Context )
@@ -70,11 +82,5 @@ accept_content(ReqData0, Context) ->
70
82
71
83
% %--------------------------------------------------------------------
72
84
73
- name (ReqData ) ->
74
- case rabbit_mgmt_util :id (name , ReqData ) of
75
- [Value ] -> Value ;
76
- Value -> Value
77
- end .
78
-
79
85
unicode_format (Arg ) ->
80
86
rabbit_data_coercion :to_utf8_binary (io_lib :format (" ~tp " , [Arg ])).
0 commit comments