-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctrl.go
42 lines (34 loc) · 1.41 KB
/
ctrl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package authz
import "github.com/gofiber/fiber/v2"
// AuthzController is the controller that holds the 3-factors to authenticate.
type AuthzController interface {
// GetPrincipial returns the principal.
GetPrincipial(ctx *fiber.Ctx) (AuthzPrincipal, error)
// GetObject returns the object.
GetObject(ctx *fiber.Ctx) (AuthzObject, error)
// GetAction returns the action.
GetAction(ctx *fiber.Ctx) (AuthzAction, error)
}
var _ AuthzController = (*DefaultAuthzController)(nil)
// DefaultAuthzController is the default implementation of the AuthzController.
type DefaultAuthzController struct {
PrincipalResolver AuthzPrincipalResolver
ObjectResolver AuthzObjectResolver
ActionResolver AuthzActionResolver
}
// NewDefaultAuthzController returns a new DefaultAuthzController.
func NewDefaultAuthzController(pr AuthzPrincipalResolver, or AuthzObjectResolver, ar AuthzActionResolver) *DefaultAuthzController {
return &DefaultAuthzController{}
}
// GetPrincipial returns the principal.
func (d *DefaultAuthzController) GetPrincipial(ctx *fiber.Ctx) (AuthzPrincipal, error) {
return d.PrincipalResolver.Resolve(ctx)
}
// GetObject returns the object.
func (d *DefaultAuthzController) GetObject(ctx *fiber.Ctx) (AuthzObject, error) {
return d.ObjectResolver.Resolve(ctx)
}
// GetAction returns the action.
func (d *DefaultAuthzController) GetAction(ctx *fiber.Ctx) (AuthzAction, error) {
return d.ActionResolver.Resolve(ctx)
}