access_control

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Definitions = []di.Def{
	{
		Build: func(ctn di.Container) (interface{}, error) {
			accessControl := ctn.Get("focus.accessControl").(*AccessControl)
			newAction := ctn.Get("focus.access.createActionRule").(CreateActionRule)
			return NewAccessMiddleware(accessControl, newAction), nil
		},
		Name: "focus.accessMiddleware",
	},
	{
		Build: func(ctn di.Container) (interface{}, error) {
			jwtRSACert := ctn.Get("focus.access.jwtRSACert").(string)
			rsaPub, err := jwt.ParseRSAPublicKeyFromPEM([]byte(jwtRSACert))
			if err != nil {
				return nil, err
			}
			return NewAccessControl(rsaPub), nil
		},
		Name: "focus.accessControl",
	},
	{
		Build: func(ctn di.Container) (interface{}, error) {
			rolesFile := ctn.Get("focus.access.rolesFile").(string)
			return RolesFromFile(rolesFile), nil
		},
		Name: "focus.access.roles",
	},
}

Functions

This section is empty.

Types

type Access

type Access uint
const (
	Nil      Access = iota // Не установлено
	Denied                 // Доступ запрещен
	Accessed               // Доступ разрешен
)

func (Access) String

func (a Access) String() string

type AccessClaims

type AccessClaims struct {
	jwt.RegisteredClaims
	Scope      string `json:"scope"`
	FirstName  string `json:"firstName"`
	LastName   string `json:"lastName"`
	MiddleName string `json:"middleName"`
}

type AccessControl

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

func NewAccessControl

func NewAccessControl(jwtRSACert *rsa.PublicKey) *AccessControl

func (AccessControl) CheckAccess

func (s AccessControl) CheckAccess(tokenString string, action *Action) error

CheckAccess проверяет доступ пользователя к определенному действию

func (AccessControl) GetClaims

func (s AccessControl) GetClaims(tokenString string) (*AccessClaims, error)

type AccessMiddleware

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

func NewAccessMiddleware

func NewAccessMiddleware(accessControl *AccessControl, newAction CreateActionRule) *AccessMiddleware

func (AccessMiddleware) CheckAccess

func (m AccessMiddleware) CheckAccess(c *gin.Context)

type Action

type Action struct {
	Path   string
	Method string
}

Action - действие пользователя

func NewAction

func NewAction(route string, method string) *Action

func (Action) String

func (a Action) String() string

type CreateActionRule

type CreateActionRule func(c *gin.Context) *Action

type Privilege

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

func NewPrivilege

func NewPrivilege(access Access) *Privilege

type Privileges

type Privileges map[string]*Privilege

type Role

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

func NewRole

func NewRole(name string, privilegesStrings []string) *Role

func RolesFromFile

func RolesFromFile(filename string) (roles []*Role)

func (Role) HasAccess

func (r Role) HasAccess(action *Action) bool

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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