auth

package
v0.0.0-...-5110490 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActionAdd = "add"

predefine permission action

View Source
var ActionDelete = "delete"
View Source
var ActionList = "list"
View Source
var ActionQuery = "query"
View Source
var ActionUpdate = "update"
View Source
var ErrLoadCasbinPolicy = errors.New("load casbin policy err")
View Source
var ErrNotFoundPermission = errors.New("cannot find url's permission")

errors

View Source
var ErrNotInitCasbinAuth = errors.New("not init defaultCasbinAuth")
View Source
var ErrParsePermission = errors.New("parse permission err")
View Source
var ErrParseWrongClaim = errors.New("not find target claims.")

errors

View Source
var ErrTokenHasBeenExpired = errors.New("token has been expired.")
View Source
var ErrTokenInvalid = errors.New("token is not valid.")
View Source
var ErrTokenNotValidYet = errors.New("token is not valid yet.")

Functions

func GetUrlPermission

func GetUrlPermission(fullPath string, method string) (string, string, error)

get url permission's resource and action(the resource act of db recordId)

func HasPermissionUser

func HasPermissionUser(userId string, resource string, act string) (bool, error)

func InitCasbinAuth

func InitCasbinAuth(role CasbinRoleManager, per CasbinPermissionManager) error

func JwtGenerateToken

func JwtGenerateToken(user *UserClaim) (string, error)

func RefreshPolicy

func RefreshPolicy() error

func RegisteHandler

func RegisteHandler(engine *gin.Engine)

func WithNoPermission

func WithNoPermission(url string, method string, handler gin.HandlerFunc)

Types

type CasbinPermissionManager

type CasbinPermissionManager interface {
	ListPermissionOfUsers() ([]*CasbinUserPermission, error)
}

type CasbinRoleManager

type CasbinRoleManager interface {
	ListRoleOfUsers() ([]*CasbinUserRole, error)
	ListPermissionOfRoles() ([]*CasbinRolePermission, error)
}

type CasbinRolePermission

type CasbinRolePermission struct {
	RoleId   string
	Action   string
	Resource string
}

type CasbinUserPermission

type CasbinUserPermission struct {
	UserId   string
	Action   string
	Resource string
}

type CasbinUserRole

type CasbinUserRole struct {
	UserId string
	RoleId string
}

type Controller

type Controller struct {
	Handler gin.HandlerFunc
	Action  string // permission
	Url     string // relative path
	Method  string // http method
}

type LocalCasbinAdapter

type LocalCasbinAdapter struct {
	// contains filtered or unexported fields
}

func (*LocalCasbinAdapter) AddPolicy

func (a *LocalCasbinAdapter) 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 (*LocalCasbinAdapter) LoadPolicy

func (a *LocalCasbinAdapter) LoadPolicy(model model.Model) error

func (*LocalCasbinAdapter) RemoveFilteredPolicy

func (a *LocalCasbinAdapter) 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 (*LocalCasbinAdapter) RemovePolicy

func (a *LocalCasbinAdapter) 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 (*LocalCasbinAdapter) SavePolicy

func (a *LocalCasbinAdapter) SavePolicy(model model.Model) error

donot save policy, it save by biz

type RestfulEndPoint

type RestfulEndPoint struct {
	Resource    string
	Controllers []*Controller
}

func WithResource

func WithResource(resource string) *RestfulEndPoint

func (*RestfulEndPoint) WithActEndPoint

func (r *RestfulEndPoint) WithActEndPoint(action string, url string, handler gin.HandlerFunc)

if url with / prefix, it will register the /resource+utl path

func (*RestfulEndPoint) WithAddEndPoint

func (r *RestfulEndPoint) WithAddEndPoint(handler gin.HandlerFunc)

func (*RestfulEndPoint) WithDeleteEndPoint

func (r *RestfulEndPoint) WithDeleteEndPoint(handler gin.HandlerFunc)

func (*RestfulEndPoint) WithEndPoint

func (r *RestfulEndPoint) WithEndPoint(action string, url string, method string, handler gin.HandlerFunc)

if url with / prefix, it will register the /resource+utl path

func (*RestfulEndPoint) WithListEndPoint

func (r *RestfulEndPoint) WithListEndPoint(handler gin.HandlerFunc)

add '/' suffix avoid match conflicts with /:id

func (*RestfulEndPoint) WithQueryEndPoint

func (r *RestfulEndPoint) WithQueryEndPoint(handler gin.HandlerFunc)

func (*RestfulEndPoint) WithUpdateEndPoint

func (r *RestfulEndPoint) WithUpdateEndPoint(handler gin.HandlerFunc)

type UserClaim

type UserClaim struct {
	Id string
}

func JwtValidToken

func JwtValidToken(token string) (*UserClaim, error)

Jump to

Keyboard shortcuts

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