From 51fa197af6b20fbb7cec0cca4500107a76f2582c Mon Sep 17 00:00:00 2001 From: kanzihuang Date: Sat, 26 Aug 2023 12:06:29 +0800 Subject: [PATCH] fix: LDAP login --- server/internal/auth/api/ldap_login.go | 10 ++++++---- server/internal/sys/domain/entity/config.go | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/internal/auth/api/ldap_login.go b/server/internal/auth/api/ldap_login.go index b4a1b09e..98a1cd30 100644 --- a/server/internal/auth/api/ldap_login.go +++ b/server/internal/auth/api/ldap_login.go @@ -3,6 +3,9 @@ package api import ( "crypto/tls" "fmt" + "github.com/go-ldap/ldap/v3" + "github.com/pkg/errors" + "gorm.io/gorm" "mayfly-go/internal/auth/api/form" msgapp "mayfly-go/internal/msg/application" sysapp "mayfly-go/internal/sys/application" @@ -16,10 +19,6 @@ import ( "strconv" "strings" "time" - - "github.com/go-ldap/ldap/v3" - "github.com/pkg/errors" - "gorm.io/gorm" ) type LdapLogin struct { @@ -117,6 +116,9 @@ type UserInfo struct { // Authenticate 通过 LDAP 验证用户名密码 func Authenticate(username, password string) (*UserInfo, error) { ldapConf := sysapp.GetConfigApp().GetConfig(sysentity.ConfigKeyLdapLogin).ToLdapLogin() + if !ldapConf.Enable { + return nil, errors.Errorf("未启用 LDAP 登录") + } conn, err := Connect(ldapConf) if err != nil { return nil, errors.Errorf("connect: %v", err) diff --git a/server/internal/sys/domain/entity/config.go b/server/internal/sys/domain/entity/config.go index c439c68b..9d3a0f88 100644 --- a/server/internal/sys/domain/entity/config.go +++ b/server/internal/sys/domain/entity/config.go @@ -135,6 +135,7 @@ func (c *Config) ToLdapLogin() *ConfigLdapLogin { ll := new(ConfigLdapLogin) ll.Enable = c.ConvBool(jm["enable"], false) ll.Host = jm["host"] + ll.Port = jm["port"] ll.SkipTLSVerify = c.ConvBool(jm["skipTLSVerify"], true) ll.SecurityProtocol = jm["securityProtocol"] ll.BindDN = stringx.Trim(jm["bindDN"])