Skip to content

Commit

Permalink
Merge pull request #79 from NorskHelsenett/fix/set-ldap-query-defaulk…
Browse files Browse the repository at this point in the history
…t-timeout

add default timeout 10s
  • Loading branch information
havardelnan authored Apr 23, 2024
2 parents 9d05937 + fea955e commit 9bb1c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/auth/userauth/activedirectory/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/go-ldap/ldap"
)

var DefaultTimeout = 10 * time.Second

type AdConfig struct {
Domain string `json:"domain"`
BindUser string `json:"bindUser"`
Expand Down Expand Up @@ -84,6 +86,8 @@ func (l *AdClient) Connect() error {
//shuffle servers to spread the love
rand.Shuffle(len(l.config.Servers), func(i, j int) { l.config.Servers[i], l.config.Servers[j] = l.config.Servers[j], l.config.Servers[i] })

ldap.DefaultTimeout = DefaultTimeout

for _, ldapserver := range l.config.Servers {
rlog.Infof("Trying server %s for domain %s.", ldapserver.Host, l.config.Domain)
if l.config.Certificate != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/auth/userauth/ldaps/openldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"strconv"
"time"

"github.com/NorskHelsenett/ror/pkg/auth/authtools"
identitymodels "github.com/NorskHelsenett/ror/pkg/models/identity"
Expand All @@ -14,6 +15,8 @@ import (
"github.com/go-ldap/ldap"
)

var DefaultTimeout = 10 * time.Second

type LdapConfig struct {
Domain string `json:"domain"`
BindUser string `json:"bindUser"`
Expand Down Expand Up @@ -45,6 +48,8 @@ func NewLdapsClient(config LdapConfig) (*LdapsClient, error) {
func (l *LdapsClient) Connect() error {
var client *ldap.Conn

ldap.DefaultTimeout = DefaultTimeout

for _, ldapserver := range l.config.Servers {
ldapsport, err := strconv.Atoi(ldap.DefaultLdapsPort)
rlog.Infof("Trying server %s for domain %s.", ldapserver.Host, l.config.Domain)
Expand Down

0 comments on commit 9bb1c36

Please sign in to comment.