You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This doesn't deviate from the core functionalities of the Enforcer, which is described in the interface IEnforcer. The types of enforcers acts as a decorator to the actual Enforcer. As such, users should be able to use the middleware with other types of Enforcer.
Additional Context (optional)
No response
Code Snippet (optional)
package main
import (
c "github.com/casbin/casbin/v2""github.com/gofiber/contrib/casbin""github.com/gofiber/fiber/v2"
)
funcmain() {
enforcer, _:=c.NewEnforcer("path/to/basic_model.conf", "path/to/basic_policy.csv")
//enforcer, _ := c.NewSyncedEnforcer("path/to/basic_model.conf", "path/to/basic_policy.csv") // This fails, but it should work.returncasbin.New(casbin.Config{
Enforcer: enforcer,
Lookup: func(c*fiber.Ctx) string {
claims, ok:=c.UserContext().Value(model.AuthContextKey).(*model.AuthClaims)
if!ok {
logger.Error(nil, "failed to get auth claims")
return""
}
returnclaims.Role
},
Unauthorized: func(c*fiber.Ctx) error {
returnmodel.Response(c, http.StatusUnauthorized)
},
Forbidden: func(c*fiber.Ctx) error {
returnmodel.Response(c, http.StatusForbidden)
},
})
}
There's a simple fix which just changes /gofiber/casbin.Config.Enforcer type from casbin.*Enforcer to casbin.IEnforcer. However this does not take into account the behavior of DistributedEnforcer, which have another interface casbin.IDistributedEnforcer.
Feature Description
Currently, Casbin supports multiple types of
Enforcer
:Enforcer
SyncedEnforcer
CachedEnforcer
SyncedCachedEnforcer
DistributedEnforcer
This doesn't deviate from the core functionalities of the
Enforcer
, which is described in the interfaceIEnforcer
. The types of enforcers acts as a decorator to the actual Enforcer. As such, users should be able to use the middleware with other types of Enforcer.Additional Context (optional)
No response
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: