This commit is contained in:
laodaming 2023-11-17 15:11:23 +08:00
parent 71850d505e
commit 86216a6456
3 changed files with 6 additions and 6 deletions

View File

@ -33,10 +33,10 @@ func NewCreateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
// } // }
func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.OrganizationOu = strings.Trim(req.OrganizationOu, " ") req.OrganizationEnName = strings.Trim(req.OrganizationEnName, " ")
req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ") req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ")
req.BusinessCategory = strings.Trim(req.BusinessCategory, " ") req.BusinessCategory = strings.Trim(req.BusinessCategory, " ")
if len(strings.Split(req.OrganizationOu, ",")) != 1 { if len(strings.Split(req.OrganizationEnName, ",")) != 1 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的组织ou") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的组织ou")
} }
if req.ParentOrganizationDN == "" { if req.ParentOrganizationDN == "" {
@ -46,12 +46,12 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,分类名不能为空") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,分类名不能为空")
} }
//组装organization dn //组装organization dn
organizationDN := "ou=" + req.OrganizationOu + "," + req.ParentOrganizationDN organizationDN := "ou=" + req.OrganizationEnName + "," + req.ParentOrganizationDN
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
err := ldapServer.Create(organizationDN, map[string][]string{ err := ldapServer.Create(organizationDN, map[string][]string{
"objectClass": {"top", "groupOfUniqueNames"}, "objectClass": {"top", "groupOfUniqueNames"},
"cn": {req.BusinessCategory}, "cn": {req.BusinessCategory},
"ou": {req.OrganizationOu}, "ou": {req.OrganizationEnName},
"businessCategory": {req.BusinessCategory}, "businessCategory": {req.BusinessCategory},
"uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去 "uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去
}) })

View File

@ -107,7 +107,7 @@ type MenuItem struct {
} }
type CreateLdapOrganizationReq struct { type CreateLdapOrganizationReq struct {
OrganizationOu string `json:"organization_ou"` //组织ou OrganizationEnName string `json:"organization_en_name"` //组织英文名
BusinessCategory string `json:"business_category"` //组织分类名称 BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
} }

View File

@ -178,7 +178,7 @@ type MenuItem {
} }
//增加ldap组织 //增加ldap组织
type CreateLdapOrganizationReq { type CreateLdapOrganizationReq {
OrganizationOu string `json:"organization_ou"` //组织ou OrganizationEnName string `json:"organization_en_name"` //组织英文名
BusinessCategory string `json:"business_category"` //组织分类名称 BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
} }