This commit is contained in:
laodaming 2023-11-15 12:30:08 +08:00
parent 99e7ce25de
commit 00be6206a9

37
utils/ldap_lib/ldap.go Normal file
View File

@ -0,0 +1,37 @@
package ldap_lib
import (
"github.com/go-ldap/ldap/v3"
)
type LdapGroup struct {
conn *ldap.Conn
}
func NewLdapGroup(conn *ldap.Conn) *LdapGroup {
return &LdapGroup{conn}
}
// 更新分组信息
func (l *LdapGroup) UpdateGroup(groupDN string, attr map[string][]string) error {
modify := ldap.NewModifyRequest(groupDN, nil)
for key, v := range attr {
modify.Replace(key, v)
}
return l.conn.Modify(modify)
}
// 删除分组
func (l *LdapGroup) DeleteGroup(groupDN string) error {
del := ldap.NewDelRequest(groupDN, nil)
return l.conn.Del(del)
}
// 创建分组
func (l *LdapGroup) CreateGroup(groupDN string, attr map[string][]string) error {
add := ldap.NewAddRequest(groupDN, nil)
for key, v := range attr {
add.Attribute(key, v)
}
return l.conn.Add(add)
}