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
-**Continuous monitoring** for ongoing authorization
13
13
14
+
## Prerequisites
15
+
16
+
- Basic knowledge of [Casbin](https://github.com/casbin/casbin) is required,
17
+
since Casbin-UCON extends Casbin with session-based usage control.
18
+
14
19
## Installation
15
20
16
21
```bash
17
22
go get github.com/casbin/casbin-ucon
18
23
```
19
24
25
+
## Continuous Authorization Behavior
26
+
27
+
It's important to understand how continuous authorization works in Casbin-UCON:
28
+
29
+
1. EnforceWithSession(sessionID) performs pre-checks (pre-conditions and pre-obligations) and automatically starts monitoring for ongoing conditions and obligations.
30
+
31
+
2. StartMonitoring(sessionID) only starts monitoring without pre-checks.
32
+
33
+
3. If a session no longer satisfies the conditions, session.IfActive() will return false, and you can use session.GetStopReason() to determine why the session stopped.
34
+
35
+
4. Your application is responsible for handling these notifications and deciding how to terminate the session.
36
+
37
+
Always call StopMonitoring() to clean up resources when done.
38
+
Example:
39
+
40
+
```go
41
+
gofunc() {
42
+
for {
43
+
if !session.IfActive() {
44
+
if session.GetStopReason() == ucon.NormalStopReason {
45
+
// NormalStopReason means the session was stopped by user code calling StopMonitoring().
46
+
break
47
+
}
48
+
//TODO
49
+
//decide how to handle session termination yourself
50
+
// For example, clean up resources, close connections, write logs, notify the frontend, etc.
51
+
fmt.Printf("%s%s%s is stopped because: %s\n", session.GetSubject(), session.GetAction(), session.GetObject(),session.GetStopReason())
52
+
break
53
+
}
54
+
time.Sleep(200 * time.Millisecond)
55
+
}
56
+
}()
57
+
```
58
+
20
59
## Quick Start
21
60
61
+
Casbin-UCON requires standard Casbin configuration files:
62
+
63
+
-**model.conf**: defines the access control model (RBAC, ABAC, etc.)
0 commit comments