parent
2f13adfa91
commit
7080589568
|
|
@ -1,9 +1,30 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/casbin/casbin/v2"
|
"github.com/casbin/casbin/v2"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
func CasbinACL(c *gin.Context){
|
func CasbinACL(c *gin.Context){
|
||||||
_, _ := casbin.NewEnforcer("config/model.conf", "config/policy.csv")
|
sub, _ :=c.Get("user")
|
||||||
|
obj:=c.Request.RequestURI
|
||||||
|
act:=c.Request.Method
|
||||||
|
e, err := casbin.NewEnforcer("config/model.conf", "config/policy.csv")
|
||||||
|
log.Println(sub,obj,act,err)
|
||||||
|
ok,err:=e.Enforce(sub,obj,act)
|
||||||
|
if err!=nil{
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 403,
|
||||||
|
"msg": "没有权限:"+err.Error(),
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
|
if !ok{
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 403,
|
||||||
|
"msg": fmt.Sprintf("没有权限:%s,%s,%s",sub,obj,act),
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue