Fix delete-resource authz failure.

This commit is contained in:
Yang Luo 2022-03-01 22:37:23 +08:00
parent 697b3e4998
commit 18aa70dfb2
2 changed files with 12 additions and 1 deletions

View File

@ -54,7 +54,7 @@ m = (r.subOwner == p.subOwner || p.subOwner == "*") && \
(r.urlPath == p.urlPath || p.urlPath == "*") && \
(r.objOwner == p.objOwner || p.objOwner == "*") && \
(r.objName == p.objName || p.objName == "*") || \
(r.urlPath == "/api/update-user" && r.subOwner == r.objOwner && r.subName == r.objName)
(r.subOwner == r.objOwner && r.subName == r.objName)
`
m, err := model.NewModelFromString(modelText)

View File

@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/astaxie/beego/context"
"github.com/casdoor/casdoor/authz"
@ -57,6 +58,8 @@ func getSubject(ctx *context.Context) (string, string) {
func getObject(ctx *context.Context) (string, string) {
method := ctx.Request.Method
path := ctx.Request.URL.Path
if method == http.MethodGet {
// query == "?id=built-in/admin"
id := ctx.Input.Query("id")
@ -78,6 +81,14 @@ func getObject(ctx *context.Context) (string, string) {
//panic(err)
return "", ""
}
if path == "/api/delete-resource" {
tokens := strings.Split(obj.Name, "/")
if len(tokens) >= 2 {
obj.Name = tokens[len(tokens)-2]
}
}
return obj.Owner, obj.Name
}
}