This commit is contained in:
laodaming 2023-11-17 11:24:54 +08:00
parent 18b27b61ac
commit 3cc3751d09
12 changed files with 31 additions and 18 deletions

View File

@ -92,6 +92,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/ldap-admin/remove_ldap_organization_member",
Handler: RemoveLdapOrganizationMemberHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/ldap-admin/get_ldap_organization_members",
Handler: GetLdapOrganizationMembersHandler(serverCtx),
},
},
)
}

View File

@ -36,7 +36,7 @@ func (l *AddLdapOrganizationMemberLogic) AddLdapOrganizationMember(req *types.Ad
req.OrganizationDN = strings.Trim(req.OrganizationDN, " ")
req.UserDN = strings.Trim(req.UserDN, " ")
if len(req.OrganizationDN) <= 3 || req.OrganizationDN[:3] != "ou=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的目标组织DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的目标组织DN")
}
if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN")

View File

@ -36,17 +36,14 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
req.OrganizationOu = strings.Trim(req.OrganizationOu, " ")
req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ")
req.BusinessCategory = strings.Trim(req.BusinessCategory, " ")
if req.OrganizationOu == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,organization_ou不能为空")
}
if len(strings.Split(req.OrganizationOu, ",")) != 1 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的organization_ou")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的组织ou")
}
if req.ParentOrganizationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,parentOrganization_dn不能为空")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
}
if req.BusinessCategory == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,business_category不能为空")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,分类名不能为空")
}
//组装organization dn
organizationDN := "ou=" + req.OrganizationOu + "," + req.ParentOrganizationDN

View File

@ -42,13 +42,13 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, useri
req.Email = strings.Trim(req.Email, " ")
req.Password = strings.Trim(req.Password, " ")
if req.UserName == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "用户名不能为空")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,用户名不能为空")
}
if req.Password == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "密码不能为空")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,密码不能为空")
}
if !email.IsEmailValid(req.Email) {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "邮箱格式不正确")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,邮箱格式不正确")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
//把用户名转pinyin

View File

@ -35,7 +35,7 @@ func NewDeleteLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
func (l *DeleteLdapOrganizationLogic) DeleteLdapOrganization(req *types.DeleteLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.OrganizationDN = strings.Trim(req.OrganizationDN, " ")
if len(req.OrganizationDN) <= 3 || req.OrganizationDN[:3] != "ou=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的组织DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的组织DN")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
if err := ldapServer.Delete(req.OrganizationDN); err != nil {

View File

@ -35,7 +35,7 @@ func NewDeleteLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De
func (l *DeleteLdapUserLogic) DeleteLdapUser(req *types.DeleteLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.UserDN = strings.Trim(req.UserDN, " ")
if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的用户DN")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
err := ldapServer.Update(req.UserDN, map[string][]string{

View File

@ -35,7 +35,7 @@ func NewGetLdapUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
func (l *GetLdapUserInfoLogic) GetLdapUserInfo(req *types.GetLdapUserInfoReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "用户DN错误")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,用户DN错误")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
res, err := ldapServer.Search(req.UserDN, ldap.ScopeWholeSubtree, "", nil, nil)

View File

@ -36,10 +36,10 @@ func (l *RemoveLdapOrganizationMemberLogic) RemoveLdapOrganizationMember(req *ty
req.OrganizationDN = strings.Trim(req.OrganizationDN, " ")
req.UserDN = strings.Trim(req.UserDN, " ")
if len(req.OrganizationDN) <= 3 || req.OrganizationDN[:3] != "ou=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的目标组织DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的目标组织DN")
}
if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的用户DN")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
err := ldapServer.RemoveUserFromOrganization(req.OrganizationDN, req.UserDN)

View File

@ -35,10 +35,10 @@ func NewUpdateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.OrganizationDN = strings.Trim(req.OrganizationDN, " ")
if req.OrganizationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "组织DN不能为空")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织DN不能为空")
}
if len(req.OrganizationDN) <= 3 || req.OrganizationDN[:3] != "ou=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的组织DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的组织DN")
}
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
if err := ldapServer.Update(req.OrganizationDN, map[string][]string{

View File

@ -44,7 +44,7 @@ func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, useri
//todo 验证下是不是本人
}
if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN")
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,无效的用户DN")
}
//把用户名转pinyin
userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName)

View File

@ -134,6 +134,10 @@ type RemoveLdapOrganizationMemberReq struct {
UserDN string `json:"user_dn"` //用户DN
}
type GetLdapOrganizationMembersReq struct {
OrganizationDN string `json:"organization_dn"`
}
type Request struct {
}

View File

@ -60,6 +60,9 @@ service ldap-admin {
//ldap组织移除成员
@handler RemoveLdapOrganizationMemberHandler
post /api/ldap-admin/remove_ldap_organization_member(RemoveLdapOrganizationMemberReq) returns (response);
//获取ldap组织成员列表
@handler GetLdapOrganizationMembersHandler
get /api/ldap-admin/get_ldap_organization_members(GetLdapOrganizationMembersReq) returns (response);
}
type GetApisReq {
@ -187,3 +190,7 @@ type RemoveLdapOrganizationMemberReq {
OrganizationDN string `json:"organization_dn"` //目标组织DN
UserDN string `json:"user_dn"` //用户DN
}
//获取ldap组织成员列表
type GetLdapOrganizationMembersReq {
OrganizationDN string `json:"organization_dn"`
}