【权限匹配修改为正则匹配】
This commit is contained in:
parent
6b2a07b4f7
commit
7e7f2109d2
@ -1,7 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"regexp"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
@ -48,24 +48,15 @@ func permissionMiddleware() gin.HandlerFunc {
|
||||
|
||||
// 验证路径
|
||||
func validateUserPath(path, method string, paths []*dto.AuthPath) bool {
|
||||
reqPathArr := strings.Split(path, "/")
|
||||
for _, p := range paths {
|
||||
if p.Method == "*" || p.Method == method {
|
||||
authPathArr := strings.Split(p.Path, "/")
|
||||
isValid := true
|
||||
for i, p := range reqPathArr {
|
||||
if authPathArr[i] == "{id}" || authPathArr[i] == ":id" || p == authPathArr[i] {
|
||||
continue
|
||||
} else if authPathArr[i] == "*" {
|
||||
isValid = true
|
||||
break
|
||||
} else {
|
||||
isValid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if isValid {
|
||||
if p.Path == path {
|
||||
return true
|
||||
} else {
|
||||
authReg, _ := regexp.Compile(p.Path)
|
||||
if authReg.MatchString(path) { // 匹配路径
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user