2019-12-06 08:15:54 +00:00
|
|
|
package authentication
|
|
|
|
|
|
|
|
import (
|
2020-03-19 04:22:46 +00:00
|
|
|
"github.com/go-ldap/ldap/v3"
|
2019-12-06 08:15:54 +00:00
|
|
|
)
|
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// LDAPConnectionFactory an interface of factory of ldap connections.
|
2019-12-06 08:15:54 +00:00
|
|
|
type LDAPConnectionFactory interface {
|
2021-08-05 04:30:00 +00:00
|
|
|
DialURL(addr string, opts ...ldap.DialOpt) (LDAPConnection, error)
|
2019-12-06 08:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LDAPConnectionFactoryImpl the production implementation of an ldap connection factory.
|
|
|
|
type LDAPConnectionFactoryImpl struct{}
|
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// NewLDAPConnectionFactoryImpl create a concrete ldap connection factory.
|
2019-12-06 08:15:54 +00:00
|
|
|
func NewLDAPConnectionFactoryImpl() *LDAPConnectionFactoryImpl {
|
|
|
|
return &LDAPConnectionFactoryImpl{}
|
|
|
|
}
|
|
|
|
|
2021-01-04 10:28:55 +00:00
|
|
|
// DialURL creates a connection from an LDAP URL when successful.
|
2021-08-05 04:30:00 +00:00
|
|
|
func (lcf *LDAPConnectionFactoryImpl) DialURL(addr string, opts ...ldap.DialOpt) (LDAPConnection, error) {
|
|
|
|
conn, err := ldap.DialURL(addr, opts...)
|
2019-12-06 08:15:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2022-03-17 04:02:54 +00:00
|
|
|
return conn, nil
|
2019-12-06 08:15:54 +00:00
|
|
|
}
|