From e09bf9e728c92fc53176ee46a97d754197f5a149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Fri, 12 Aug 2022 10:14:06 +0800 Subject: [PATCH] =?UTF-8?q?enhance(security):=E5=A2=9E=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=98=AF=E5=90=A6=E4=BB=85=E6=98=AF=E8=BF=90=E7=BB=B4?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E5=88=A4=E6=96=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- security/security.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/security/security.go b/security/security.go index cb9d4e6..8cff1e3 100644 --- a/security/security.go +++ b/security/security.go @@ -54,3 +54,13 @@ func ManagementAuthorize(c *gin.Context) { } c.Next() } + +// 用于对用户会话进行是否运维用户的判断 +// ! 通过该中间件以后,是可以保证上下文中一定具有用户会话信息的。 +func OPSAuthorize(c *gin.Context) { + session, exists := c.Get("session") + if sess, ok := session.(*model.Session); !exists || !ok || sess.Type != 2 { + c.AbortWithStatus(http.StatusForbidden) + } + c.Next() +}