casbin

package
v0.5.0-rc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubSwitchOn = 1 << 2 // single 000, group 100
	ObjSwitchOn = 1 << 1 // single 000, group 010
	ActSwitchOn = 1      // single 000, group 001
)
View Source
const (
	GroupTypeUser = "user"
	GroupTypeApp  = "app"
	GroupTypeURL  = "url"
)

Variables

View Source
var (
	Casbin *CasbinService

	ActionReadMenu Action = "menu:read"
)

Functions

func CasbinAppObjKey

func CasbinAppObjKey(appName, appEnv string) string

func CasbinGroupKey

func CasbinGroupKey(gType string, name string) (key string)

func InitCasbin

func InitCasbin(adapter persist.Adapter) (err error)

InitCasbin 初始化casbin

func PolicyAuthList

func PolicyAuthList() (list []db.CasbinPolicyAuth, err error)

func PolicyGroupList

func PolicyGroupList() (list []db.CasbinPolicyGroup, err error)

Types

type APIItem

type APIItem struct {
	Name   string `yaml:"name" json:"name"`
	Path   string `yaml:"path" json:"path"`
	Method string `yaml:"method" json:"method,omitempty"`
}

type APIListItem

type APIListItem struct {
	Name   string `json:"name"`
	Path   string `json:"path"`
	Method string `json:"method"`
}

type Action

type Action string

type AppPermissionItem

type AppPermissionItem struct {
	Name string `yaml:"name" json:"name"`
	Key  string `yaml:"key" json:"key"`
}

type AppPermissionList

type AppPermissionList []AppPermissionItem

type CasbinAdapter

type CasbinAdapter struct{}

CasbinAdapter ..

func (*CasbinAdapter) AddPolicy

func (a *CasbinAdapter) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy adds a policy rule to the storage. This is part of the Auto-Save feature.

func (*CasbinAdapter) LoadPolicy

func (a *CasbinAdapter) LoadPolicy(model casbinModel.Model) (err error)

LoadPolicy loads all policy rules from the storage.

func (*CasbinAdapter) RemoveFilteredPolicy

func (a *CasbinAdapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy removes policy rules that match the filter from the storage. This is part of the Auto-Save feature.

func (*CasbinAdapter) RemovePolicy

func (a *CasbinAdapter) RemovePolicy(sec string, ptype string, rule []string) error

RemovePolicy removes a policy rule from the storage. This is part of the Auto-Save feature.

func (*CasbinAdapter) SavePolicy

func (a *CasbinAdapter) SavePolicy(model casbinModel.Model) error

SavePolicy saves all policy rules to the storage.

type CasbinService

type CasbinService struct {
	*casbin.SyncedEnforcer

	Resource struct {
		Permission PermissionTree    `yaml:"permission" json:"permission"`
		App        AppPermissionList `yaml:"app" json:"app"`
	}
	// contains filtered or unexported fields
}

func (*CasbinService) APIList

func (c *CasbinService) APIList(sub string) (list []APIItem)

func (*CasbinService) AppPermissionList

func (c *CasbinService) AppPermissionList() AppPermissionList

func (*CasbinService) CheckAPIValid

func (c *CasbinService) CheckAPIValid(path, method string) bool

func (*CasbinService) CheckAppPermissionKeyValid

func (c *CasbinService) CheckAppPermissionKeyValid(key string) bool

func (*CasbinService) CheckPermission

func (c *CasbinService) CheckPermission(sub, object, action string, policyType db.CasbinPolicyType) (ok bool, err error)

func (*CasbinService) CheckUserPermission

func (c *CasbinService) CheckUserPermission(u *db.User, object string, action string, policyType db.CasbinPolicyType) (ok bool, err error)

func (*CasbinService) FullAPIList

func (c *CasbinService) FullAPIList() (list []APIItem)

获取所有的API权限列表(去重结果)

func (*CasbinService) GetAPIItem

func (c *CasbinService) GetAPIItem(path, method string) (apiItem *APIItem)

func (*CasbinService) GetMenu

func (c *CasbinService) GetMenu(sub string) (menu view.MenuTree, err error)

func (*CasbinService) LoadPolicy added in v0.4.0

func (c *CasbinService) LoadPolicy() error

func (*CasbinService) UserMenu

func (c *CasbinService) UserMenu(u *db.User) (menu view.MenuTree, err error)
type MenuTreeItem struct {
	Name     string         `yaml:"name" json:"name"`
	Path     string         `yaml:"path" json:"path"`
	Icon     string         `yaml:"icon" json:"icon"`
	API      []APIItem      `yaml:"api" json:"api"`
	Children PermissionTree `yaml:"children" json:"children"`
}

type Object

type Object struct {
	Resource string
	Type     db.CasbinPolicyType
}

type PermissionTree

type PermissionTree []MenuTreeItem

type PolicyType

type PolicyType struct {
	SubSwitchOn int
	ObjSwitchOn int
	ActSwitchOn int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL