security

package
v0.0.0-...-8f9ce2e Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ACCESS_GRANTED = VoterResult(1)
	ACCESS_ABSTAIN = VoterResult(2)
	ACCESS_DENIED  = VoterResult(-1)

	ErrNotStringableAttribute = errors.New("attribute is not stringable")
)
View Source
var (
	ErrAccessForbidden = errors.New("access Forbidden")
)

Functions

func AccessCheckerMiddleware

func AccessCheckerMiddleware(ac *AccessChecker) func(c *web.C, h http.Handler) http.Handler

func CheckAccess

func CheckAccess(token SecurityToken, attrs Attributes, res http.ResponseWriter, req *http.Request, auth AuthorizationChecker) error

func ConfigureCors

func ConfigureCors(l *goapp.Lifecycle, conf *config.Config)

func ConfigureSecurity

func ConfigureSecurity(l *goapp.Lifecycle, conf *config.Config)

func EnsureRoles

func EnsureRoles(roles []string, rls ...string) []string

func RenderExpiredToken

func RenderExpiredToken(w http.ResponseWriter)

func RenderForbidden

func RenderForbidden(w http.ResponseWriter)

Types

type AccessChecker

type AccessChecker struct {
	Rules         []*AccessRule
	DecisionVoter DecisionVoter
}

func (*AccessChecker) Check

func (c *AccessChecker) Check(t SecurityToken, req *http.Request) bool

type AccessRule

type AccessRule struct {
	Path  *regexp.Regexp
	Roles Attributes
}

type AffirmativeDecision

type AffirmativeDecision struct {
	Voters                     []Voter
	AllowIfAllAbstainDecisions bool
}

func (*AffirmativeDecision) Decide

func (d *AffirmativeDecision) Decide(t SecurityToken, attrs Attributes, o interface{}) bool

func (*AffirmativeDecision) Support

func (d *AffirmativeDecision) Support(o interface{}) bool

type Attributes

type Attributes []interface{}

func AttributesFromString

func AttributesFromString(roles []string) Attributes

func (Attributes) ToStringSlice

func (attrs Attributes) ToStringSlice() ([]string, error)

type AuthorizationChecker

type AuthorizationChecker interface {
	IsGranted(t SecurityToken, attrs Attributes, o interface{}) (bool, error)
}

type DecisionVoter

type DecisionVoter interface {
	Support(o interface{}) bool
	Decide(t SecurityToken, attrs Attributes, o interface{}) bool
}

type DefaultAuthorizationChecker

type DefaultAuthorizationChecker struct {
	DecisionVoter DecisionVoter
}

func (*DefaultAuthorizationChecker) IsGranted

func (c *DefaultAuthorizationChecker) IsGranted(t SecurityToken, attrs Attributes, o interface{}) (bool, error)

type DefaultSecurityToken

type DefaultSecurityToken struct {
	Username string
	Roles    []string
}

Default implementation to the GuardToken

func (*DefaultSecurityToken) GetRoles

func (t *DefaultSecurityToken) GetRoles() []string

func (*DefaultSecurityToken) GetUsername

func (t *DefaultSecurityToken) GetUsername() string

type MockedDecisionVoter

type MockedDecisionVoter struct {
	mock.Mock
}

func (*MockedDecisionVoter) Decide

func (m *MockedDecisionVoter) Decide(t SecurityToken, attrs Attributes, o interface{}) bool

func (*MockedDecisionVoter) Support

func (m *MockedDecisionVoter) Support(o interface{}) bool

type MockedVoter

type MockedVoter struct {
	mock.Mock
}

func (*MockedVoter) Support

func (m *MockedVoter) Support(v interface{}) bool

func (*MockedVoter) Vote

func (m *MockedVoter) Vote(t SecurityToken, o interface{}, attrs Attributes) (VoterResult, error)

type RoleVoter

type RoleVoter struct {
	Prefix string
}

func (*RoleVoter) Support

func (v *RoleVoter) Support(o interface{}) bool

func (*RoleVoter) Vote

func (v *RoleVoter) Vote(t SecurityToken, o interface{}, attrs Attributes) (result VoterResult, err error)

type SecurityToken

type SecurityToken interface {
	// return the current username for the current token
	GetUsername() string

	// return the related roles linked to the current token
	GetRoles() []string
}

Bare interface to used inside a request lifecycle

func GetTokenFromContext

func GetTokenFromContext(c web.C) SecurityToken

type Voter

type Voter interface {
	Support(v interface{}) bool
	Vote(t SecurityToken, o interface{}, attrs Attributes) (VoterResult, error)
}

type VoterResult

type VoterResult int

Jump to

Keyboard shortcuts

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