@@ -86,7 +86,7 @@ func (c *LDAPClient) openLDAP(options interface{}) error {
86
86
return sdk .ErrLDAPConn
87
87
}
88
88
89
- // Reconnect with TLS
89
+ //Reconnect with TLS
90
90
err = c .conn .StartTLS (& tls.Config {InsecureSkipVerify : true })
91
91
if err != nil {
92
92
log .Error ("Auth> Cannot start TLS %s : %s" , address , err )
@@ -225,6 +225,23 @@ func (c *LDAPClient) Bind(username, password string) error {
225
225
return nil
226
226
}
227
227
228
+ //BindDN
229
+ func (c * LDAPClient ) BindDN (dn , password string ) error {
230
+ log .Debug ("LDAP> Bind DN %s" , dn )
231
+ if err := c .conn .Bind (dn , password ); err != nil {
232
+ if ! shoudRetry (err ) {
233
+ return err
234
+ }
235
+ if err = c .openLDAP (c .conf ); err != nil {
236
+ return err
237
+ }
238
+ if err = c .conn .Bind (dn , password ); err != nil {
239
+ return err
240
+ }
241
+ }
242
+ return nil
243
+ }
244
+
228
245
//Search search
229
246
func (c * LDAPClient ) Search (filter string , attributes ... string ) ([]Entry , error ) {
230
247
attr := append (attributes , "dn" )
@@ -370,15 +387,23 @@ func (c *LDAPClient) searchAndInsertOrUpdateUser(db gorp.SqlExecutor, username s
370
387
371
388
//Authentify check username and password
372
389
func (c * LDAPClient ) Authentify (username , password string ) (bool , error ) {
390
+ // Search user
391
+ r , err := c .Search ("(&(uid=" + username + "))" )
392
+ if err != nil {
393
+ return false , nil
394
+ }
395
+
373
396
//Bind user
374
- if err := c .Bind (username , password ); err != nil {
375
- log .Warning ("LDAP> Bind error %s %s" , username , err )
397
+ if r != nil {
398
+ if err = c .BindDN (r [0 ].DN , password ); err != nil {
399
+ log .Warning ("LDAP> Bind error %s %s" , username , err )
376
400
377
- if ! isCredentialError (err ) {
378
- return false , err
401
+ if ! isCredentialError (err ) {
402
+ return false , err
403
+ }
404
+ //Try local auth
405
+ return c .local .Authentify (username , password )
379
406
}
380
- //Try local auth
381
- return c .local .Authentify (username , password )
382
407
}
383
408
384
409
log .Debug ("LDAP> Bind successful %s" , username )
0 commit comments