diff --git a/server/ldap-admin/internal/handler/addldaporganizationmemberhandler.go b/server/ldap-admin/internal/handler/addldaporganizationmemberhandler.go new file mode 100644 index 00000000..36830cba --- /dev/null +++ b/server/ldap-admin/internal/handler/addldaporganizationmemberhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func AddLdapOrganizationMemberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.AddLdapOrganizationMemberReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewAddLdapOrganizationMemberLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.AddLdapOrganizationMember(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/createldaporginationhandler.go b/server/ldap-admin/internal/handler/createldaporganizationhandler.go similarity index 69% rename from server/ldap-admin/internal/handler/createldaporginationhandler.go rename to server/ldap-admin/internal/handler/createldaporganizationhandler.go index a0954734..fcfe86f6 100644 --- a/server/ldap-admin/internal/handler/createldaporginationhandler.go +++ b/server/ldap-admin/internal/handler/createldaporganizationhandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/ldap-admin/internal/types" ) -func CreateLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func CreateLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.CreateLdapOrginationReq + var req types.CreateLdapOrganizationReq userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewCreateLdapOrginationLogic(r.Context(), svcCtx) + l := logic.NewCreateLdapOrganizationLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.CreateLdapOrgination(&req, userinfo) + resp := l.CreateLdapOrganization(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/ldap-admin/internal/handler/deleteldaporginationhandler.go b/server/ldap-admin/internal/handler/deleteldaporganizationhandler.go similarity index 69% rename from server/ldap-admin/internal/handler/deleteldaporginationhandler.go rename to server/ldap-admin/internal/handler/deleteldaporganizationhandler.go index 93fd0d0f..b209a1a6 100644 --- a/server/ldap-admin/internal/handler/deleteldaporginationhandler.go +++ b/server/ldap-admin/internal/handler/deleteldaporganizationhandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/ldap-admin/internal/types" ) -func DeleteLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func DeleteLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.DeleteLdapOrginationReq + var req types.DeleteLdapOrganizationReq userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewDeleteLdapOrginationLogic(r.Context(), svcCtx) + l := logic.NewDeleteLdapOrganizationLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.DeleteLdapOrgination(&req, userinfo) + resp := l.DeleteLdapOrganization(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/ldap-admin/internal/handler/getldaporginationshandler.go b/server/ldap-admin/internal/handler/getldaporganizationshandler.go similarity index 74% rename from server/ldap-admin/internal/handler/getldaporginationshandler.go rename to server/ldap-admin/internal/handler/getldaporganizationshandler.go index 0ba2eb2a..b98edbd4 100644 --- a/server/ldap-admin/internal/handler/getldaporginationshandler.go +++ b/server/ldap-admin/internal/handler/getldaporganizationshandler.go @@ -11,7 +11,7 @@ import ( "fusenapi/server/ldap-admin/internal/types" ) -func GetLdapOrginationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func GetLdapOrganizationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request @@ -21,12 +21,12 @@ func GetLdapOrginationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } // 创建一个业务逻辑层实例 - l := logic.NewGetLdapOrginationsLogic(r.Context(), svcCtx) + l := logic.NewGetLdapOrganizationsLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.GetLdapOrginations(&req, userinfo) + resp := l.GetLdapOrganizations(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/ldap-admin/internal/handler/removeldaporganizationmemberhandler.go b/server/ldap-admin/internal/handler/removeldaporganizationmemberhandler.go new file mode 100644 index 00000000..43d70aab --- /dev/null +++ b/server/ldap-admin/internal/handler/removeldaporganizationmemberhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func RemoveLdapOrganizationMemberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.RemoveLdapOrganizationMemberReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewRemoveLdapOrganizationMemberLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.RemoveLdapOrganizationMember(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/routes.go b/server/ldap-admin/internal/handler/routes.go index f17e1a45..cc2d93ae 100644 --- a/server/ldap-admin/internal/handler/routes.go +++ b/server/ldap-admin/internal/handler/routes.go @@ -44,23 +44,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/api/ldap-admin/get_ldap_orginations", - Handler: GetLdapOrginationsHandler(serverCtx), + Path: "/api/ldap-admin/get_ldap_organizations", + Handler: GetLdapOrganizationsHandler(serverCtx), }, { Method: http.MethodPost, - Path: "/api/ldap-admin/create_ldap_orgination", - Handler: CreateLdapOrginationHandler(serverCtx), + Path: "/api/ldap-admin/create_ldap_organization", + Handler: CreateLdapOrganizationHandler(serverCtx), }, { Method: http.MethodPost, - Path: "/api/ldap-admin/delete_ldap_orgination", - Handler: DeleteLdapOrginationHandler(serverCtx), + Path: "/api/ldap-admin/delete_ldap_organization", + Handler: DeleteLdapOrganizationHandler(serverCtx), }, { Method: http.MethodPost, - Path: "/api/ldap-admin/update_ldap_orgination", - Handler: UpdateLdapOrginationHandler(serverCtx), + Path: "/api/ldap-admin/update_ldap_organization", + Handler: UpdateLdapOrganizationHandler(serverCtx), }, { Method: http.MethodPost, @@ -82,6 +82,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/ldap-admin/get_ldap_user_info", Handler: GetLdapUserInfoHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/add_ldap_organization_member", + Handler: AddLdapOrganizationMemberHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/remove_ldap_organization_member", + Handler: RemoveLdapOrganizationMemberHandler(serverCtx), + }, }, ) } diff --git a/server/ldap-admin/internal/handler/updateldaporginationhandler.go b/server/ldap-admin/internal/handler/updateldaporganizationhandler.go similarity index 69% rename from server/ldap-admin/internal/handler/updateldaporginationhandler.go rename to server/ldap-admin/internal/handler/updateldaporganizationhandler.go index 31e9a88b..8a9846a6 100644 --- a/server/ldap-admin/internal/handler/updateldaporginationhandler.go +++ b/server/ldap-admin/internal/handler/updateldaporganizationhandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/ldap-admin/internal/types" ) -func UpdateLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func UpdateLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.UpdateLdapOrginationReq + var req types.UpdateLdapOrganizationReq userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewUpdateLdapOrginationLogic(r.Context(), svcCtx) + l := logic.NewUpdateLdapOrganizationLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.UpdateLdapOrgination(&req, userinfo) + resp := l.UpdateLdapOrganization(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go b/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go new file mode 100644 index 00000000..887d1217 --- /dev/null +++ b/server/ldap-admin/internal/logic/addldaporganizationmemberlogic.go @@ -0,0 +1,50 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "strings" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddLdapOrganizationMemberLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewAddLdapOrganizationMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLdapOrganizationMemberLogic { + return &AddLdapOrganizationMemberLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *AddLdapOrganizationMemberLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *AddLdapOrganizationMemberLogic) AddLdapOrganizationMember(req *types.AddLdapOrganizationMemberReq, userinfo *auth.UserInfo) (resp *basic.Response) { + 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") + } + if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN") + } + //ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *AddLdapOrganizationMemberLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/createldaporginationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go similarity index 64% rename from server/ldap-admin/internal/logic/createldaporginationlogic.go rename to server/ldap-admin/internal/logic/createldaporganizationlogic.go index eb38d260..b95da217 100644 --- a/server/ldap-admin/internal/logic/createldaporginationlogic.go +++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go @@ -14,14 +14,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type CreateLdapOrginationLogic struct { +type CreateLdapOrganizationLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewCreateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapOrginationLogic { - return &CreateLdapOrginationLogic{ +func NewCreateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapOrganizationLogic { + return &CreateLdapOrganizationLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -29,32 +29,32 @@ func NewCreateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContex } // 处理进入前逻辑w,r -// func (l *CreateLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *CreateLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *CreateLdapOrginationLogic) CreateLdapOrgination(req *types.CreateLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) { - req.OrginationOu = strings.Trim(req.OrginationOu, " ") - req.ParentOrginationDN = strings.Trim(req.ParentOrginationDN, " ") +func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) { + req.OrganizationOu = strings.Trim(req.OrganizationOu, " ") + req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ") req.BusinessCategory = strings.Trim(req.BusinessCategory, " ") - if req.OrginationOu == "" { + if req.OrganizationOu == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,organization_ou不能为空") } - if len(strings.Split(req.OrginationOu, ",")) != 1 { + if len(strings.Split(req.OrganizationOu, ",")) != 1 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的organization_ou") } - if req.ParentOrginationDN == "" { + if req.ParentOrganizationDN == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,parentOrganization_dn不能为空") } if req.BusinessCategory == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,business_category不能为空") } //组装organization dn - organizationDN := "ou=" + req.OrginationOu + "," + req.ParentOrginationDN + organizationDN := "ou=" + req.OrganizationOu + "," + req.ParentOrganizationDN ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) err := ldapServer.Create(organizationDN, map[string][]string{ "objectClass": {"top", "groupOfUniqueNames"}, "cn": {req.BusinessCategory}, - "ou": {req.OrginationOu}, + "ou": {req.OrganizationOu}, "businessCategory": {req.BusinessCategory}, "uniqueMember": {l.svcCtx.Config.Ldap.RootDN}, //创建groupOfUniqueNames对象类型需要至少一个member,把root加进去 }) @@ -66,6 +66,6 @@ func (l *CreateLdapOrginationLogic) CreateLdapOrgination(req *types.CreateLdapOr } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *CreateLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *CreateLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/ldap-admin/internal/logic/deleteldaporginationlogic.go b/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go similarity index 52% rename from server/ldap-admin/internal/logic/deleteldaporginationlogic.go rename to server/ldap-admin/internal/logic/deleteldaporganizationlogic.go index e91fd559..c3956d2a 100644 --- a/server/ldap-admin/internal/logic/deleteldaporginationlogic.go +++ b/server/ldap-admin/internal/logic/deleteldaporganizationlogic.go @@ -14,14 +14,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type DeleteLdapOrginationLogic struct { +type DeleteLdapOrganizationLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewDeleteLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLdapOrginationLogic { - return &DeleteLdapOrginationLogic{ +func NewDeleteLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLdapOrganizationLogic { + return &DeleteLdapOrganizationLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -29,19 +29,16 @@ func NewDeleteLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContex } // 处理进入前逻辑w,r -// func (l *DeleteLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *DeleteLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *DeleteLdapOrginationLogic) DeleteLdapOrgination(req *types.DeleteLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) { - req.OrginationDN = strings.Trim(req.OrginationDN, " ") - if req.OrginationDN == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "组织DN不能为空") - } - if len(req.OrginationDN) <= 3 || req.OrginationDN[:3] != "ou=" { +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") } ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) - if err := ldapServer.Delete(req.OrginationDN); err != nil { + if err := ldapServer.Delete(req.OrganizationDN); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "删除ldap组织失败,", err.Error()) } @@ -49,6 +46,6 @@ func (l *DeleteLdapOrginationLogic) DeleteLdapOrgination(req *types.DeleteLdapOr } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *DeleteLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *DeleteLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/ldap-admin/internal/logic/getldaporginationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go similarity index 86% rename from server/ldap-admin/internal/logic/getldaporginationslogic.go rename to server/ldap-admin/internal/logic/getldaporganizationslogic.go index 38cf3349..6162499a 100644 --- a/server/ldap-admin/internal/logic/getldaporginationslogic.go +++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go @@ -16,14 +16,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type GetLdapOrginationsLogic struct { +type GetLdapOrganizationsLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewGetLdapOrginationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLdapOrginationsLogic { - return &GetLdapOrginationsLogic{ +func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLdapOrganizationsLogic { + return &GetLdapOrganizationsLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -31,7 +31,7 @@ func NewGetLdapOrginationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) } // 处理进入前逻辑w,r -// func (l *GetLdapOrginationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } type DNItem struct { Attribute map[string]interface{} `json:"attribute"` @@ -41,7 +41,7 @@ type DNItem struct { Child []*DNItem `json:"child"` } -func (l *GetLdapOrginationsLogic) GetLdapOrginations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { //从ldap获取组织架构数据 rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",") if len(rootCn) == 0 { @@ -120,6 +120,6 @@ func (l *GetLdapOrginationsLogic) GetLdapOrginations(req *types.Request, userinf } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *GetLdapOrginationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *GetLdapOrganizationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go new file mode 100644 index 00000000..443a3457 --- /dev/null +++ b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RemoveLdapOrganizationMemberLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewRemoveLdapOrganizationMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveLdapOrganizationMemberLogic { + return &RemoveLdapOrganizationMemberLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *RemoveLdapOrganizationMemberLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *RemoveLdapOrganizationMemberLogic) RemoveLdapOrganizationMember(req *types.RemoveLdapOrganizationMemberReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *RemoveLdapOrganizationMemberLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/updateldaporginationlogic.go b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go similarity index 58% rename from server/ldap-admin/internal/logic/updateldaporginationlogic.go rename to server/ldap-admin/internal/logic/updateldaporganizationlogic.go index 00978ddd..6efc5ba3 100644 --- a/server/ldap-admin/internal/logic/updateldaporginationlogic.go +++ b/server/ldap-admin/internal/logic/updateldaporganizationlogic.go @@ -14,14 +14,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type UpdateLdapOrginationLogic struct { +type UpdateLdapOrganizationLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewUpdateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLdapOrginationLogic { - return &UpdateLdapOrginationLogic{ +func NewUpdateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLdapOrganizationLogic { + return &UpdateLdapOrganizationLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -29,19 +29,19 @@ func NewUpdateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContex } // 处理进入前逻辑w,r -// func (l *UpdateLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *UpdateLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *UpdateLdapOrginationLogic) UpdateLdapOrgination(req *types.UpdateLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) { - req.OrginationDN = strings.Trim(req.OrginationDN, " ") - if req.OrginationDN == "" { +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不能为空") } - if len(req.OrginationDN) <= 3 || req.OrginationDN[:3] != "ou=" { + if len(req.OrganizationDN) <= 3 || req.OrganizationDN[:3] != "ou=" { 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.OrginationDN, map[string][]string{ + if err := ldapServer.Update(req.OrganizationDN, map[string][]string{ "cn": {req.BusinessCategory}, "businessCategory": {req.BusinessCategory}, }); err != nil { @@ -52,6 +52,6 @@ func (l *UpdateLdapOrginationLogic) UpdateLdapOrgination(req *types.UpdateLdapOr } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *UpdateLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *UpdateLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 431f6ece..d92e6240 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -73,18 +73,18 @@ type MenuItem struct { Status int64 `json:"status"` } -type CreateLdapOrginationReq struct { - OrginationOu string `json:"orgination_ou"` //组织ou - BusinessCategory string `json:"business_category"` //组织分类名称 - ParentOrginationDN string `json:"parent_orgination_dn"` //父级dn +type CreateLdapOrganizationReq struct { + OrganizationOu string `json:"organization_ou"` //组织ou + BusinessCategory string `json:"business_category"` //组织分类名称 + ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn } -type DeleteLdapOrginationReq struct { - OrginationDN string `json:"orgination_dn"` //组织dn +type DeleteLdapOrganizationReq struct { + OrganizationDN string `json:"organization_dn"` //组织dn } -type UpdateLdapOrginationReq struct { - OrginationDN string `json:"orgination_dn"` //组织dn +type UpdateLdapOrganizationReq struct { + OrganizationDN string `json:"organization_dn"` //组织dn BusinessCategory string `json:"business_category"` //组织分类名称 } @@ -124,6 +124,16 @@ type GetLdapUserInfoRsp struct { Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } +type AddLdapOrganizationMemberReq struct { + OrganizationDN string `json:"organization_dn"` //目标组织DN + UserDN string `json:"user_dn"` //用户DN +} + +type RemoveLdapOrganizationMemberReq struct { + OrganizationDN string `json:"organization_dn"` //目标组织DN + UserDN string `json:"user_dn"` //用户DN +} + type Request struct { } diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index afd49324..a8d0c65c 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -40,17 +40,17 @@ service ldap-admin { @handler GetMenusHandler get /api/ldap-admin/get_menus(GetMenusReq) returns (response); //获取ldap组织列表 - @handler GetLdapOrginationsHandler - get /api/ldap-admin/get_ldap_orginations(request) returns (response); + @handler GetLdapOrganizationsHandler + get /api/ldap-admin/get_ldap_organizations(request) returns (response); //增加ldap组织 - @handler CreateLdapOrginationHandler - post /api/ldap-admin/create_ldap_orgination(CreateLdapOrginationReq) returns (response); + @handler CreateLdapOrganizationHandler + post /api/ldap-admin/create_ldap_organization(CreateLdapOrganizationReq) returns (response); //删除ldap组织 - @handler DeleteLdapOrginationHandler - post /api/ldap-admin/delete_ldap_orgination(DeleteLdapOrginationReq) returns (response); + @handler DeleteLdapOrganizationHandler + post /api/ldap-admin/delete_ldap_organization(DeleteLdapOrganizationReq) returns (response); //修改ldap组织 - @handler UpdateLdapOrginationHandler - post /api/ldap-admin/update_ldap_orgination(UpdateLdapOrginationReq) returns (response); + @handler UpdateLdapOrganizationHandler + post /api/ldap-admin/update_ldap_organization(UpdateLdapOrganizationReq) returns (response); //添加ldap用户到员工基本组中 @handler CreateLdapUserHandler post /api/ldap-admin/create_ldap_user(CreateLdapUserReq) returns (response); @@ -63,6 +63,12 @@ service ldap-admin { //获取ldap用户信息 @handler GetLdapUserInfoHandler get /api/ldap-admin/get_ldap_user_info(GetLdapUserInfoReq) returns (response); + //ldap组织添加成员 + @handler AddLdapOrganizationMemberHandler + post /api/ldap-admin/add_ldap_organization_member(AddLdapOrganizationMemberReq) returns (response); + //ldap组织移除成员 + @handler RemoveLdapOrganizationMemberHandler + post /api/ldap-admin/remove_ldap_organization_member(RemoveLdapOrganizationMemberReq) returns (response); } type ( GetLdapGroupsReq {} @@ -136,18 +142,18 @@ type MenuItem { Status int64 `json:"status"` } //增加ldap组织 -type CreateLdapOrginationReq { - OrginationOu string `json:"orgination_ou"` //组织ou - BusinessCategory string `json:"business_category"` //组织分类名称 - ParentOrginationDN string `json:"parent_orgination_dn"` //父级dn +type CreateLdapOrganizationReq { + OrganizationOu string `json:"organization_ou"` //组织ou + BusinessCategory string `json:"business_category"` //组织分类名称 + ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn } //删除ldap组织 -type DeleteLdapOrginationReq { - OrginationDN string `json:"orgination_dn"` //组织dn +type DeleteLdapOrganizationReq { + OrganizationDN string `json:"organization_dn"` //组织dn } //修改ldap组织 -type UpdateLdapOrginationReq { - OrginationDN string `json:"orgination_dn"` //组织dn +type UpdateLdapOrganizationReq { + OrganizationDN string `json:"organization_dn"` //组织dn BusinessCategory string `json:"business_category"` //组织分类名称 } //添加ldap用户到员工基本组中 @@ -184,4 +190,14 @@ type GetLdapUserInfoRsp { Mobile string `json:"mobile"` //手机号 Avatar string `json:"avatar"` //头像地址 Status int64 `json:"status,options=0|1"` //状态 1正常0离职 +} +//ldap组织添加成员 +type AddLdapOrganizationMemberReq { + OrganizationDN string `json:"organization_dn"` //目标组织DN + UserDN string `json:"user_dn"` //用户DN +} +//ldap组织移除成员 +type RemoveLdapOrganizationMemberReq { + OrganizationDN string `json:"organization_dn"` //目标组织DN + UserDN string `json:"user_dn"` //用户DN } \ No newline at end of file diff --git a/utils/ldap_lib/ldap_group.go b/utils/ldap_lib/ldap_group.go index f7290759..922cc303 100644 --- a/utils/ldap_lib/ldap_group.go +++ b/utils/ldap_lib/ldap_group.go @@ -65,8 +65,8 @@ func (l *Ldap) Search(DN string, scope int, filter string, attr []string, contro return l.conn.Search(searchRequest) } -// AddUserToGroup 添加用户到分组 -func (l *Ldap) AddUserToGroup(groupDN, userDN string) error { +// AddUserToGroup 添加用户到组织 +func (l *Ldap) AddUserToOrganization(groupDN, userDN string) error { //判断dn是否以ou开头 if groupDN[:3] == "ou=" { return errors.New("不能添加用户到OU组织单元") @@ -77,7 +77,7 @@ func (l *Ldap) AddUserToGroup(groupDN, userDN string) error { } // DelUserFromGroup 将用户从分组删除 -func (l *Ldap) RemoveUserFromGroup(groupDN, userDN string) error { +func (l *Ldap) RemoveUserFromOrganization(groupDN, userDN string) error { modify := ldap.NewModifyRequest(groupDN, nil) modify.Delete("uniqueMember", []string{userDN}) return l.conn.Modify(modify)