fix
This commit is contained in:
parent
d4c7aad3ab
commit
7860b94a55
|
@ -4,8 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"github.com/go-ldap/ldap/v3"
|
"fusenapi/utils/ldap_lib"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -44,28 +43,18 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
|
||||||
//从ldap获取组织架构数据
|
//从ldap获取组织架构数据
|
||||||
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
|
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
|
||||||
if len(rootCn) == 0 {
|
if len(rootCn) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "root dn is not set")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "root用户DN未设置")
|
||||||
}
|
}
|
||||||
searchRequest := ldap.NewSearchRequest(
|
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap)
|
||||||
l.svcCtx.Config.Ldap.BaseDN, //这里后续需要修改,不同的人只能查询他的下属列表
|
filter := "(&(objectClass=*)(!(ou=" + l.svcCtx.Config.Ldap.PeopleGroupOu + "))(!(" + rootCn[0] + ")))" //所有object但是不包括people以及root用户
|
||||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
searchResult, err := ldapServer.Search(l.svcCtx.Config.Ldap.BaseDN, filter, nil, nil)
|
||||||
"(&(objectClass=*)(!(ou="+l.svcCtx.Config.Ldap.PeopleGroupOu+"))(!("+rootCn[0]+")))", //所有object但是不包括people以及root用户
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
// 执行搜索请求
|
|
||||||
searchResult, err := l.svcCtx.Ldap.Search(searchRequest)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询失败:"+err.Error())
|
||||||
}
|
}
|
||||||
mapDN := make(map[string]*DNItem)
|
mapDN := make(map[string]*DNItem)
|
||||||
sortNum := 0
|
sortNum := 0
|
||||||
//每个DN存入map
|
//每个DN存入map
|
||||||
for _, v := range searchResult.Entries {
|
for _, v := range searchResult.Entries {
|
||||||
//如果是root用户则跳过
|
|
||||||
/*if v.DN == l.svcCtx.Config.Ldap.RootDN {
|
|
||||||
continue
|
|
||||||
}*/
|
|
||||||
sortNum++
|
sortNum++
|
||||||
attribute := make(map[string]interface{})
|
attribute := make(map[string]interface{})
|
||||||
for _, attr := range v.Attributes {
|
for _, attr := range v.Attributes {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user