Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
a53242b8d3
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
// }
|
|
@ -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)
|
||||
// }
|
|
@ -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)
|
||||
// }
|
|
@ -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)
|
||||
// }
|
|
@ -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)
|
||||
// }
|
|
@ -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)
|
||||
// }
|
|
@ -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 {
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user