RunDetections runs all detectors on all role managers. Returns the first error encountered, or nil if all checks pass. Silently skips role managers that don't support the required iteration methods.
()
| 311 | // Returns the first error encountered, or nil if all checks pass. |
| 312 | // Silently skips role managers that don't support the required iteration methods. |
| 313 | func (e *Enforcer) RunDetections() error { |
| 314 | if e.detectors == nil || len(e.detectors) == 0 { |
| 315 | return nil |
| 316 | } |
| 317 | |
| 318 | // Run detectors on all role managers |
| 319 | for _, rm := range e.rmMap { |
| 320 | for _, d := range e.detectors { |
| 321 | err := d.Check(rm) |
| 322 | // Skip if the role manager doesn't support the required iteration or is not initialized |
| 323 | if err != nil && (strings.Contains(err.Error(), "does not support Range iteration") || |
| 324 | strings.Contains(err.Error(), "not properly initialized")) { |
| 325 | continue |
| 326 | } |
| 327 | if err != nil { |
| 328 | return err |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Run detectors on all conditional role managers |
| 334 | for _, crm := range e.condRmMap { |
| 335 | for _, d := range e.detectors { |
| 336 | err := d.Check(crm) |
| 337 | // Skip if the role manager doesn't support the required iteration or is not initialized |
| 338 | if err != nil && (strings.Contains(err.Error(), "does not support Range iteration") || |
| 339 | strings.Contains(err.Error(), "not properly initialized")) { |
| 340 | continue |
| 341 | } |
| 342 | if err != nil { |
| 343 | return err |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return nil |
| 349 | } |
| 350 | |
| 351 | // ClearPolicy clears all policy. |
| 352 | func (e *Enforcer) ClearPolicy() { |