authz

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleUser  = "user"
	RoleAdmin = "admin"
)

Variables

This section is empty.

Functions

func IsSelfAssignableRole

func IsSelfAssignableRole(role string) bool

func NormalizeRole

func NormalizeRole(raw string) (string, bool)

func NormalizeRoleOrDefault

func NormalizeRoleOrDefault(raw string) string

func NormalizeSelfAssignableRoles

func NormalizeSelfAssignableRoles(rawRoles []string) ([]string, error)

Types

type CasbinAuthorizer

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

func NewCasbinAuthorizer

func NewCasbinAuthorizer(db *gorm.DB, defaultRole string, adminIdentityIDs []string) (*CasbinAuthorizer, error)

func NewCasbinAuthorizerWithOptions

func NewCasbinAuthorizerWithOptions(db *gorm.DB, opts Options) (*CasbinAuthorizer, error)

NewCasbinAuthorizerWithOptions allows applications to provide domain ownership checks. Without a resolver, only the global "*" domain is allowed.

func NewCasbinAuthorizerWithPolicies

func NewCasbinAuthorizerWithPolicies(db *gorm.DB, defaultRole string, adminIdentityIDs []string, policies []Policy) (*CasbinAuthorizer, error)

NewCasbinAuthorizerWithPolicies initializes RBAC with framework policies and application-owned policies. Policies are idempotently persisted by Casbin.

func (*CasbinAuthorizer) AddUserRole

func (a *CasbinAuthorizer) AddUserRole(_ context.Context, userID, role string) error

func (*CasbinAuthorizer) Can

func (a *CasbinAuthorizer) Can(_ context.Context, userID, dom, obj, act string) (bool, error)

func (*CasbinAuthorizer) EnsureDefaultRole

func (a *CasbinAuthorizer) EnsureDefaultRole(_ context.Context, userID string) (string, error)

func (*CasbinAuthorizer) GetUserRoles

func (a *CasbinAuthorizer) GetUserRoles(ctx context.Context, userID string) ([]string, error)

func (*CasbinAuthorizer) HasUserRole

func (a *CasbinAuthorizer) HasUserRole(_ context.Context, userID, role string) (bool, error)

func (*CasbinAuthorizer) SetUserSelfSelectedRoles

func (a *CasbinAuthorizer) SetUserSelfSelectedRoles(_ context.Context, userID string, rawRoles []string) ([]string, error)

type DomainAccessFunc

type DomainAccessFunc func(ctx context.Context, userID, domain, object, action string) (bool, error)

type Options

type Options struct {
	DefaultRole                  string
	AdminIdentityIDs             []string
	Policies                     []Policy
	DomainAccess                 DomainAccessFunc
	NormalizeRole                RoleNormalizer
	NormalizeSelfAssignableRoles SelfAssignableRolesNormalizer
	IsSelfAssignableRole         SelfAssignableRoleChecker
	RoleOrder                    []string
}

type Policy

type Policy struct {
	Role   string
	Domain string
	Object string
	Action string
	Effect string
}

type RoleNormalizer added in v0.7.1

type RoleNormalizer func(raw string) (string, bool)

type SelfAssignableRoleChecker added in v0.7.1

type SelfAssignableRoleChecker func(role string) bool

type SelfAssignableRolesNormalizer added in v0.7.1

type SelfAssignableRolesNormalizer func(rawRoles []string) ([]string, error)

Jump to

Keyboard shortcuts

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