mirror of
https://github.com/casdoor/casdoor.git
synced 2025-08-04 03:50:30 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
462ecce43b | ||
![]() |
a84664b55d | ||
![]() |
941c56e69e | ||
![]() |
a28b871a46 | ||
![]() |
387f5d58f7 |
@@ -40,6 +40,18 @@ func (c *ApiController) Enforce() {
|
||||
enforcerId := c.Input().Get("enforcerId")
|
||||
owner := c.Input().Get("owner")
|
||||
|
||||
params := []string{permissionId, modelId, resourceId, enforcerId, owner}
|
||||
nonEmpty := 0
|
||||
for _, param := range params {
|
||||
if param != "" {
|
||||
nonEmpty++
|
||||
}
|
||||
}
|
||||
if nonEmpty > 1 {
|
||||
c.ResponseError("Only one of the parameters (permissionId, modelId, resourceId, enforcerId, owner) should be provided")
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.Ctx.Input.RequestBody) == 0 {
|
||||
c.ResponseError("The request body should not be empty")
|
||||
return
|
||||
@@ -169,6 +181,18 @@ func (c *ApiController) BatchEnforce() {
|
||||
enforcerId := c.Input().Get("enforcerId")
|
||||
owner := c.Input().Get("owner")
|
||||
|
||||
params := []string{permissionId, modelId, enforcerId, owner}
|
||||
nonEmpty := 0
|
||||
for _, param := range params {
|
||||
if param != "" {
|
||||
nonEmpty++
|
||||
}
|
||||
}
|
||||
if nonEmpty > 1 {
|
||||
c.ResponseError("Only one of the parameters (permissionId, modelId, enforcerId, owner) should be provided")
|
||||
return
|
||||
}
|
||||
|
||||
var requests [][]string
|
||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &requests)
|
||||
if err != nil {
|
||||
|
@@ -125,10 +125,10 @@ func getPolicies(permission *Permission) [][]string {
|
||||
for _, action := range permission.Actions {
|
||||
if domainExist {
|
||||
for _, domain := range permission.Domains {
|
||||
policies = append(policies, []string{userOrRole, domain, resource, strings.ToLower(action), strings.ToLower(permission.Effect), permissionId})
|
||||
policies = append(policies, []string{userOrRole, domain, resource, action, strings.ToLower(permission.Effect), permissionId})
|
||||
}
|
||||
} else {
|
||||
policies = append(policies, []string{userOrRole, resource, strings.ToLower(action), strings.ToLower(permission.Effect), "", permissionId})
|
||||
policies = append(policies, []string{userOrRole, resource, action, strings.ToLower(permission.Effect), "", permissionId})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/casdoor/casdoor/conf"
|
||||
"github.com/casdoor/casdoor/util"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
@@ -341,10 +342,31 @@ func getClaimsCustom(claims Claims, tokenField []string) jwt.MapClaims {
|
||||
res["provider"] = claims.Provider
|
||||
|
||||
for _, field := range tokenField {
|
||||
userField := userValue.FieldByName(field)
|
||||
if userField.IsValid() {
|
||||
newfield := util.SnakeToCamel(util.CamelToSnakeCase(field))
|
||||
res[newfield] = userField.Interface()
|
||||
if strings.HasPrefix(field, "Properties") {
|
||||
/*
|
||||
Use selected properties fields as custom claims.
|
||||
Converts `Properties.my_field` to custom claim with name `my_field`.
|
||||
*/
|
||||
parts := strings.Split(field, ".")
|
||||
if len(parts) != 2 || parts[0] != "Properties" { // Either too many segments, or not properly scoped to `Properties`, so skip.
|
||||
continue
|
||||
}
|
||||
base, fieldName := parts[0], parts[1]
|
||||
mField := userValue.FieldByName(base)
|
||||
if !mField.IsValid() { // Can't find `Properties` field, so skip.
|
||||
continue
|
||||
}
|
||||
finalField := mField.MapIndex(reflect.ValueOf(fieldName))
|
||||
if finalField.IsValid() { // // Provided field within `Properties` exists, add claim.
|
||||
res[fieldName] = finalField.Interface()
|
||||
}
|
||||
|
||||
} else { // Use selected user field as claims.
|
||||
userField := userValue.FieldByName(field)
|
||||
if userField.IsValid() {
|
||||
newfield := util.SnakeToCamel(util.CamelToSnakeCase(field))
|
||||
res[newfield] = userField.Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,6 +403,14 @@ func generateJwtToken(application *Application, user *User, provider string, non
|
||||
refreshExpireTime = expireTime
|
||||
}
|
||||
|
||||
if conf.GetConfigBool("useGroupPathInToken") {
|
||||
groupPath, err := user.GetUserFullGroupPath()
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
user.Groups = groupPath
|
||||
}
|
||||
user = refineUser(user)
|
||||
|
||||
_, originBackend := getOriginFromHost(host)
|
||||
|
@@ -1331,6 +1331,56 @@ func (user *User) CheckUserFace(faceIdImage []string, provider *Provider) (bool,
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (user *User) GetUserFullGroupPath() ([]string, error) {
|
||||
if len(user.Groups) == 0 {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
var orgGroups []*Group
|
||||
orgGroups, err := GetGroups(user.Owner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupMap := make(map[string]Group)
|
||||
for _, group := range orgGroups {
|
||||
groupMap[group.Name] = *group
|
||||
}
|
||||
|
||||
var groupFullPath []string
|
||||
|
||||
for _, groupId := range user.Groups {
|
||||
_, groupName := util.GetOwnerAndNameFromIdNoCheck(groupId)
|
||||
group, ok := groupMap[groupName]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
groupPath := groupName
|
||||
|
||||
curGroup, ok := groupMap[group.ParentId]
|
||||
if !ok {
|
||||
return []string{}, fmt.Errorf("group:Group %s not exist", group.ParentId)
|
||||
}
|
||||
for {
|
||||
groupPath = util.GetId(curGroup.Name, groupPath)
|
||||
if curGroup.IsTopGroup {
|
||||
break
|
||||
}
|
||||
|
||||
curGroup, ok = groupMap[curGroup.ParentId]
|
||||
if !ok {
|
||||
return []string{}, fmt.Errorf("group:Group %s not exist", curGroup.ParentId)
|
||||
}
|
||||
}
|
||||
|
||||
groupPath = util.GetId(curGroup.Owner, groupPath)
|
||||
groupFullPath = append(groupFullPath, groupPath)
|
||||
}
|
||||
|
||||
return groupFullPath, nil
|
||||
}
|
||||
|
||||
func GenerateIdForNewUser(application *Application) (string, error) {
|
||||
if application == nil || application.GetSignupItemRule("ID") != "Incremental" {
|
||||
return util.GenerateId(), nil
|
||||
|
@@ -88,7 +88,10 @@ class ProviderTable extends React.Component {
|
||||
}
|
||||
}} >
|
||||
{
|
||||
Setting.getDeduplicatedArray(this.props.providers, table, "name").map((provider, index) => <Option key={index} value={provider.name}>{provider.name}</Option>)
|
||||
Setting.getDeduplicatedArray(this.props.providers, table, "name").filter(provider => provider.category !== "Captcha" || !table.some(tableItem => {
|
||||
const existingProvider = Setting.getArrayItem(this.props.providers, "name", tableItem.name);
|
||||
return existingProvider && existingProvider.category === "Captcha";
|
||||
})).map((provider, index) => <Option key={index} value={provider.name}>{provider.name}</Option>)
|
||||
}
|
||||
</Select>
|
||||
);
|
||||
|
Reference in New Issue
Block a user