From 25c7c0a414021a31bb7482eab66120fb4bde5f55 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 27 Nov 2023 18:17:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=89=B4=E6=9D=83=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/ldap_lib/auth.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/ldap_lib/auth.go b/utils/ldap_lib/auth.go index 6561e50d..c5a74738 100644 --- a/utils/ldap_lib/auth.go +++ b/utils/ldap_lib/auth.go @@ -128,10 +128,14 @@ func (l *Ldap) VerifyAuthorityGroup(r *http.Request, options ...LdapOptions) boo func getAllApis(metadata []*GroupAuthMetadata, apiMaps *map[int64]string) { apiMapsData := *apiMaps for _, v := range metadata { - if v.Type == "api" { - apiMapsData[v.Id] = v.Name - } else if v.Type == "group" { - getAllApis(v.Metadata, apiMaps) + if v != nil { + if v.Type == "api" { + apiMapsData[v.Id] = v.Name + } else if v.Type == "group" { + getAllApis(v.Metadata, apiMaps) + } else { + continue + } } else { continue } From cc4a840732aafa8eb7727998850f87c8face6f4f Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 27 Nov 2023 18:23:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=89=B4=E6=9D=83=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/ldap_lib/auth.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/ldap_lib/auth.go b/utils/ldap_lib/auth.go index c5a74738..7364fb6f 100644 --- a/utils/ldap_lib/auth.go +++ b/utils/ldap_lib/auth.go @@ -113,7 +113,7 @@ func (l *Ldap) VerifyAuthorityGroup(r *http.Request, options ...LdapOptions) boo logx.Error("系统出错", err) return false } - getAllApis(metadata, &apiMaps) + getAllMetadata(metadata, "api", &apiMaps) c.Set(groupKey, apiMaps, 5*time.Minute) } } @@ -125,14 +125,14 @@ func (l *Ldap) VerifyAuthorityGroup(r *http.Request, options ...LdapOptions) boo } } -func getAllApis(metadata []*GroupAuthMetadata, apiMaps *map[int64]string) { - apiMapsData := *apiMaps +func getAllMetadata(metadata []*GroupAuthMetadata, dataType string, maps *map[int64]string) { + apiMapsData := *maps for _, v := range metadata { if v != nil { - if v.Type == "api" { + if v.Type == dataType { apiMapsData[v.Id] = v.Name } else if v.Type == "group" { - getAllApis(v.Metadata, apiMaps) + getAllMetadata(v.Metadata, dataType, maps) } else { continue }