diff --git a/ctrl.go b/ctrl.go index 63211b5..d3a3009 100644 --- a/ctrl.go +++ b/ctrl.go @@ -2,23 +2,41 @@ package authz import "github.com/gofiber/fiber/v2" -// AuthzController is the controller that holds the authz checker. +// AuthzController is the controller that holds the 3-factors to authenticate. type AuthzController interface { - // Resolve is the resolver. - Resolve(ctx *fiber.Ctx) (AuthzPrincipal, AuthzObject, AuthzAction, error) + // 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{} +type DefaultAuthzController struct { + PrincipalResolver AuthzPrincipalResolver + ObjectResolver AuthzObjectResolver + ActionResolver AuthzActionResolver +} // NewDefaultAuthzController returns a new DefaultAuthzController. -func NewDefaultAuthzController() *DefaultAuthzController { +func NewDefaultAuthzController(pr AuthzPrincipalResolver, or AuthzObjectResolver, ar AuthzActionResolver) *DefaultAuthzController { return &DefaultAuthzController{} } -// ResolvePrincipal is the principal resolver. -func (d *DefaultAuthzController) Resolve(ctx *fiber.Ctx) (AuthzPrincipal, AuthzObject, AuthzAction, error) { - return AuthzNoPrincipial, AuthzNoObject, AuthzNoAction, nil +// 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) }