mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 23:40:24 +08:00
@@ -3,6 +3,9 @@ package api
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
"mayfly-go/internal/auth/api/form"
|
"mayfly-go/internal/auth/api/form"
|
||||||
msgapp "mayfly-go/internal/msg/application"
|
msgapp "mayfly-go/internal/msg/application"
|
||||||
sysapp "mayfly-go/internal/sys/application"
|
sysapp "mayfly-go/internal/sys/application"
|
||||||
@@ -16,10 +19,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LdapLogin struct {
|
type LdapLogin struct {
|
||||||
@@ -117,6 +116,9 @@ type UserInfo struct {
|
|||||||
// Authenticate 通过 LDAP 验证用户名密码
|
// Authenticate 通过 LDAP 验证用户名密码
|
||||||
func Authenticate(username, password string) (*UserInfo, error) {
|
func Authenticate(username, password string) (*UserInfo, error) {
|
||||||
ldapConf := sysapp.GetConfigApp().GetConfig(sysentity.ConfigKeyLdapLogin).ToLdapLogin()
|
ldapConf := sysapp.GetConfigApp().GetConfig(sysentity.ConfigKeyLdapLogin).ToLdapLogin()
|
||||||
|
if !ldapConf.Enable {
|
||||||
|
return nil, errors.Errorf("未启用 LDAP 登录")
|
||||||
|
}
|
||||||
conn, err := Connect(ldapConf)
|
conn, err := Connect(ldapConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("connect: %v", err)
|
return nil, errors.Errorf("connect: %v", err)
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ func (c *Config) ToLdapLogin() *ConfigLdapLogin {
|
|||||||
ll := new(ConfigLdapLogin)
|
ll := new(ConfigLdapLogin)
|
||||||
ll.Enable = c.ConvBool(jm["enable"], false)
|
ll.Enable = c.ConvBool(jm["enable"], false)
|
||||||
ll.Host = jm["host"]
|
ll.Host = jm["host"]
|
||||||
|
ll.Port = jm["port"]
|
||||||
ll.SkipTLSVerify = c.ConvBool(jm["skipTLSVerify"], true)
|
ll.SkipTLSVerify = c.ConvBool(jm["skipTLSVerify"], true)
|
||||||
ll.SecurityProtocol = jm["securityProtocol"]
|
ll.SecurityProtocol = jm["securityProtocol"]
|
||||||
ll.BindDN = stringx.Trim(jm["bindDN"])
|
ll.BindDN = stringx.Trim(jm["bindDN"])
|
||||||
|
|||||||
Reference in New Issue
Block a user