This commit is contained in:
laodaming 2023-11-15 14:18:45 +08:00
parent 84f8323832
commit 6822c3d94c
2 changed files with 7 additions and 8 deletions

View File

@ -15,6 +15,6 @@ type Config struct {
Host string
BindDN string
Password string
RootDN string
BaseDN string
}
}

View File

@ -32,19 +32,18 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// 处理进入前逻辑w,r
// func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
type mapDnItem struct {
type DNItem struct {
Attribute map[string]interface{} `json:"attribute"`
DN string `json:"dn"`
Sort int `json:"sort"`
Child []*mapDnItem `json:"child"`
Child []*DNItem `json:"child"`
}
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
//从ldap获取组织架构数据
searchBase := "dc=fusen,dc=com"
// 创建搜索请求
searchRequest := ldap.NewSearchRequest(
searchBase,
l.svcCtx.Config.Ldap.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
"(objectClass=*)",
[]string{ /*"cn", "sn", "givenName", "mail", "telephoneNumber", "department", "title"*/ },
@ -55,7 +54,7 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
if err != nil {
log.Fatal(err)
}
mapDN := make(map[string]*mapDnItem)
mapDN := make(map[string]*DNItem)
sortNum := 0
for _, v := range searchResult.Entries {
sortNum++
@ -71,11 +70,11 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
attribute[attr.Name] = strings.Join(attr.Values, ",")
}
}
mapDN[v.DN] = &mapDnItem{
mapDN[v.DN] = &DNItem{
DN: v.DN,
Attribute: attribute,
Sort: sortNum,
Child: make([]*mapDnItem, 0, 100),
Child: make([]*DNItem, 0, 100),
}
}
//组织层级关系