|
|
@ -61,6 +61,7 @@ type Config struct {
|
|
|
|
CacheSize int `envconfig:"cache_size" default:"512" desc:"a user info cache's size in KiB"`
|
|
|
|
CacheSize int `envconfig:"cache_size" default:"512" desc:"a user info cache's size in KiB"`
|
|
|
|
CacheTTL time.Duration `envconfig:"cache_ttl" default:"30m" desc:"a user info cache TTL"`
|
|
|
|
CacheTTL time.Duration `envconfig:"cache_ttl" default:"30m" desc:"a user info cache TTL"`
|
|
|
|
IsTLS bool `envconfig:"is_tls" default:"false" desc:"should LDAP connection be established via TLS"`
|
|
|
|
IsTLS bool `envconfig:"is_tls" default:"false" desc:"should LDAP connection be established via TLS"`
|
|
|
|
|
|
|
|
ConnectionTimeout time.Duration `envconfig:"connection_timeout" default:"60s" desc:"LDAP server connection timeout"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Client is a LDAP client (compatible with Active Directory).
|
|
|
|
// Client is a LDAP client (compatible with Active Directory).
|
|
|
@ -80,6 +81,7 @@ func New(cnf Config) *Client {
|
|
|
|
RoleBaseDN: cnf.RoleBaseDN,
|
|
|
|
RoleBaseDN: cnf.RoleBaseDN,
|
|
|
|
IsTLS: cnf.IsTLS,
|
|
|
|
IsTLS: cnf.IsTLS,
|
|
|
|
RoleSearchQuery: cnf.RoleSearchQuery,
|
|
|
|
RoleSearchQuery: cnf.RoleSearchQuery,
|
|
|
|
|
|
|
|
ConnectionTimeout: cnf.ConnectionTimeout,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cache: freecache.NewCache(cnf.CacheSize * 1024),
|
|
|
|
cache: freecache.NewCache(cnf.CacheSize * 1024),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -296,10 +298,11 @@ type ldapConnector struct {
|
|
|
|
IsTLS bool
|
|
|
|
IsTLS bool
|
|
|
|
UserSearchQuery string
|
|
|
|
UserSearchQuery string
|
|
|
|
RoleSearchQuery string
|
|
|
|
RoleSearchQuery string
|
|
|
|
|
|
|
|
ConnectionTimeout time.Duration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *ldapConnector) Connect(ctx context.Context, addr string) (conn, error) {
|
|
|
|
func (c *ldapConnector) Connect(ctx context.Context, addr string) (conn, error) {
|
|
|
|
d := net.Dialer{Timeout: ldap.DefaultTimeout}
|
|
|
|
d := net.Dialer{Timeout: c.ConnectionTimeout}
|
|
|
|
tcpcn, err := d.DialContext(ctx, "tcp", addr)
|
|
|
|
tcpcn, err := d.DialContext(ctx, "tcp", addr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|