Skip to content

Commit

Permalink
feat: use default authz controller
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jun 27, 2024
1 parent e642428 commit 9faac6c
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 9faac6c

Please sign in to comment.