NewContextEnforcer creates a context-aware enforcer via file or DB.
(params ...interface{})
| 32 | |
| 33 | // NewContextEnforcer creates a context-aware enforcer via file or DB. |
| 34 | func NewContextEnforcer(params ...interface{}) (IEnforcerContext, error) { |
| 35 | e := &ContextEnforcer{} |
| 36 | var err error |
| 37 | e.Enforcer, err = NewEnforcer(params...) |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | |
| 42 | if e.Enforcer.adapter != nil { |
| 43 | if contextAdapter, ok := e.Enforcer.adapter.(persist.ContextAdapter); ok { |
| 44 | e.adapterCtx = contextAdapter |
| 45 | } else { |
| 46 | return nil, errors.New("adapter does not support context operations, ContextAdapter interface not implemented") |
| 47 | } |
| 48 | } else { |
| 49 | return nil, errors.New("no adapter provided, ContextEnforcer requires a ContextAdapter") |
| 50 | } |
| 51 | |
| 52 | return e, nil |
| 53 | } |
| 54 | |
| 55 | // LoadPolicyCtx loads all policy rules from the storage with context. |
| 56 | func (e *ContextEnforcer) LoadPolicyCtx(ctx context.Context) error { |
searching dependent graphs…