MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / Check

Method Check

middleware/permit/permit.go:42–90  ·  view source on GitHub ↗
(method string, path string)

Source from the content-addressed store, hash-verified

40}
41
42func (p *PermitMiddleware) Check(method string, path string) (bool, []gin.HandlerFunc) {
43 // 当前路径是否有配置权限
44 accessRules, has := permit.GetPathRule(method, path)
45
46 if !has || len(accessRules) == 0 {
47 return false, nil
48 }
49
50 return true, []gin.HandlerFunc{
51 func(ginCtx *gin.Context) {
52 userId := utils.UserId(ginCtx)
53 if userId == "" {
54 // 未开启游客模式
55 ginCtx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"code": http.StatusForbidden, "msg": "not login", "success": "fail"})
56 ginCtx.Abort()
57 return
58 }
59
60 for _, group := range checkSort {
61 accessList, has := accessRules[group]
62 if !has {
63 // 当前分组没有配置权限
64 continue
65 }
66
67 domainHandler, has := permit.SelectDomain(group)
68 if !has {
69 // 当前分组没有配置身份handler
70 continue
71 }
72 _, myAccess, ok := domainHandler(ginCtx)
73 if !ok {
74 continue
75 }
76 accessMap := utils.SliceToMapO(myAccess, func(s string) (string, struct{}) {
77 return s, struct{}{}
78 })
79 for _, acc := range accessList {
80 if _, ok := accessMap[acc]; ok {
81 return
82 }
83 }
84 }
85 //所有group都校验不通过
86 log.DebugF("no permission:%s", ginCtx.FullPath())
87 ginCtx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"code": http.StatusForbidden, "msg": "no permission", "success": "fail"})
88 },
89 }
90}
91
92func (p *PermitMiddleware) Name() string {
93 return "permit"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected