parent
17f16c53af
commit
b2d863d466
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/casbin/casbin/v2/model"
|
"github.com/casbin/casbin/v2/model"
|
||||||
"github.com/casbin/casbin/v2/persist"
|
"github.com/casbin/casbin/v2/persist"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +24,9 @@ func GetCasbin(logger *zap.Logger) *casbin.Enforcer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add policies after creating the enforcer
|
// Add policies after creating the enforcer
|
||||||
_ = a.AddPolicy("admin", "/admin", "GET")
|
_ = a.AddPolicy("admin", "/admin", []string{"GET"})
|
||||||
_ = a.AddPolicy("admin", "/admin", "POST")
|
_ = a.AddPolicy("admin", "/admin", []string{"POST"})
|
||||||
_ = a.AddPolicy("admin", "/admin", "DELETE")
|
_ = a.AddPolicy("admin", "/admin", []string{"DELETE"})
|
||||||
|
|
||||||
err = e.LoadPolicy()
|
err = e.LoadPolicy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -70,12 +71,12 @@ func (a *PolicyAdapter) SavePolicy(model model.Model) error {
|
||||||
|
|
||||||
// AddPolicy adds a policy rule to the storage.
|
// AddPolicy adds a policy rule to the storage.
|
||||||
// AddPolicy adds a policy rule to the storage.
|
// AddPolicy adds a policy rule to the storage.
|
||||||
func (a *PolicyAdapter) AddPolicy(sub string, obj string, act string) error {
|
func (a *PolicyAdapter) AddPolicy(sec string, ptype string, rule []string) error {
|
||||||
a.lock.Lock()
|
a.lock.Lock()
|
||||||
defer a.lock.Unlock()
|
defer a.lock.Unlock()
|
||||||
|
|
||||||
// Create a line representing the policy rule
|
// Create a line representing the policy rule
|
||||||
line := sub + ", " + obj + ", " + act
|
line := ptype + ", " + strings.Join(rule, ", ")
|
||||||
|
|
||||||
// Check if the policy rule already exists
|
// Check if the policy rule already exists
|
||||||
for _, existingLine := range a.policy {
|
for _, existingLine := range a.policy {
|
||||||
|
|
Loading…
Reference in New Issue