authz

package
v0.0.0-...-f8e2896 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

admin/common/authz/adapter.go

admin/common/authz/subject.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

func NewAdapter

func NewAdapter(client *ent.Client) *Adapter

func (*Adapter) AddPolicy

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

func (*Adapter) LoadPolicy

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

func (*Adapter) RemoveFilteredPolicy

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

func (*Adapter) RemovePolicy

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

func (*Adapter) SavePolicy

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

type Subject

type Subject struct {
	UserID     int64    `json:"user_id"`
	Username   string   `json:"username"`
	TenantID   int64    `json:"tenant_id"`   // 当前操作的租户
	RoleCodes  []string `json:"role_codes"`  // 用户在当前租户下的角色code列表
	IsPlatform bool     `json:"is_platform"` // 是否拥有平台级角色
}

Subject ABAC主体,包含用户的所有授权相关属性

func (*Subject) HasAnyRole

func (s *Subject) HasAnyRole(roleCodes ...string) bool

HasAnyRole 检查是否拥有任意一个角色

func (*Subject) HasRole

func (s *Subject) HasRole(roleCode string) bool

HasRole 检查是否拥有某个角色

type SubjectBuilder

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

SubjectBuilder 从数据库构建Subject

func NewSubjectBuilder

func NewSubjectBuilder(client *ent.Client) *SubjectBuilder

func (*SubjectBuilder) BuildSubject

func (b *SubjectBuilder) BuildSubject(ctx context.Context, userID int64, tenantID int64) (*Subject, error)

BuildSubject 根据userID和tenantID构建Subject

Jump to

Keyboard shortcuts

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