beego: Index | Files

package authz

import ""

Package authz provides handlers to enable ACL, RBAC, ABAC authorization support. Simple Usage:


func main(){
	// mediate the access for every request
	beego.InsertFilter("*", beego.BeforeRouter, authz.NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")))

Advanced Usage:

func main(){
	e := casbin.NewEnforcer("authz_model.conf", "")
	e.AddRoleForUser("alice", "admin")

	beego.InsertFilter("*", beego.BeforeRouter, authz.NewAuthorizer(e))


Package Files


func NewAuthorizer Uses

func NewAuthorizer(e *casbin.Enforcer) beego.FilterFunc

NewAuthorizer returns the authorizer. Use a casbin enforcer as input

type BasicAuthorizer Uses

type BasicAuthorizer struct {
    // contains filtered or unexported fields

BasicAuthorizer stores the casbin handler

func (*BasicAuthorizer) CheckPermission Uses

func (a *BasicAuthorizer) CheckPermission(r *http.Request) bool

CheckPermission checks the user/method/path combination from the request. Returns true (permission granted) or false (permission forbidden)

func (*BasicAuthorizer) GetUserName Uses

func (a *BasicAuthorizer) GetUserName(r *http.Request) string

GetUserName gets the user name from the request. Currently, only HTTP basic authentication is supported

func (*BasicAuthorizer) RequirePermission Uses

func (a *BasicAuthorizer) RequirePermission(w http.ResponseWriter)

RequirePermission returns the 403 Forbidden to the client

Package authz imports 4 packages (graph). Updated 2018-08-14. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).