security

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAuthToken = errors.NewError("INVALID_TOKEN", "Invalid authentication token", 401)
	ErrInvalidAuthCode  = errors.NewError("INVALID_CODE", "Invalid authentication code", 401)
	ErrAccessDenied     = errors.NewFrozenError("ACCESS_DENIED", "Access denied", 403)
)

Functions

This section is empty.

Types

type CustomGatekeeper added in v0.17.0

type CustomGatekeeper interface {
	Gatekeeper

	// Policy is always a pointer to the route's policy.
	HandleSecurity(c *fasthttp.RequestCtx, perm Permission, policy any) error
}

type Gatekeeper

type Gatekeeper interface {

	// Describes the security scheme. This is a general description about how to authenticate
	// in the application.
	SecurityScheme() openapi.SecurityScheme

	// Describes the security requirement per route based on its permission tag (if any).
	SecurityRequirement(perm Permission) openapi.SecurityRequirement

	// Handler that always will be called exactly one (1) time at the beginning of any request,
	// regardless permission or policy. Good for e.g. setting a user value on the context.
	PreRequest(c *fasthttp.RequestCtx) error

	// Whether permission tags on routes is optional.
	OptionalPermTag() bool
}

type Permission

type Permission string

func Perm added in v0.13.0

func Perm(action, resource string) (p Permission)

func (Permission) Action

func (p Permission) Action() string

func (Permission) HasAction

func (p Permission) HasAction() bool

func (Permission) HasResource

func (p Permission) HasResource() bool

func (Permission) HasWildcard added in v0.13.0

func (p Permission) HasWildcard() bool

func (Permission) IsZero added in v0.13.0

func (p Permission) IsZero() bool

func (Permission) Match added in v0.13.0

func (p1 Permission) Match(p2 Permission) Permission

func (Permission) Resource

func (p Permission) Resource() string

func (*Permission) SetAction

func (p *Permission) SetAction(action string)

func (*Permission) SetResource

func (p *Permission) SetResource(resource string)

func (Permission) String

func (p Permission) String() string

type Policy

type Policy struct {
	Prio int64
	Cond []byte
}

type PolicyData added in v0.13.0

type PolicyData struct {
	Role string
	Perm Permission
	Prio int64
	Cond any
}

type PolicyKey

type PolicyKey struct {
	Role string
	Perm Permission
}

type PolicyStore added in v0.13.0

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

func (*PolicyStore) AddPolicies added in v0.13.0

func (s *PolicyStore) AddPolicies(policies iter.Seq[PolicyData]) (err error)

func (*PolicyStore) AddPoliciesSlice added in v0.17.1

func (s *PolicyStore) AddPoliciesSlice(policies []PolicyData) (err error)

func (*PolicyStore) AddPolicy added in v0.13.0

func (s *PolicyStore) AddPolicy(role string, perm Permission, prio int64, cond ...any) (err error)

func (*PolicyStore) Get added in v0.13.0

func (s *PolicyStore) Get(roles []string, perm Permission) (cond unsafe.Pointer, err error)

func (*PolicyStore) GetType added in v0.21.1

func (s *PolicyStore) GetType(perm Permission) (typ reflect.Type, ok bool)

func (*PolicyStore) Has added in v0.21.0

func (s *PolicyStore) Has(roles []string, perm Permission) bool

func (*PolicyStore) IteratePermissions added in v0.13.0

func (s *PolicyStore) IteratePermissions(inPolicy ...bool) iter.Seq[Permission]

func (*PolicyStore) IteratePolicies added in v0.13.0

func (s *PolicyStore) IteratePolicies() iter.Seq2[PolicyKey, Policy]

func (*PolicyStore) Register added in v0.13.0

func (s *PolicyStore) Register(perm Permission, typ reflect.Type) (err error)

func (*PolicyStore) Remove added in v0.13.0

func (s *PolicyStore) Remove(role string, perm Permission)

type RolesGatekeeper added in v0.17.0

type RolesGatekeeper interface {
	Gatekeeper

	// Returns the roles that a particular HTTP request has. Will only be called on routes with
	// a permission requirement set.
	UserRoles(c *fasthttp.RequestCtx) (roles []string, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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