An example of how to use casbin as an ACL service with CSV configuration
$ go install github.com/casbin/casbin/v2@latest
$ go get github.com/casbin/casbin/v2
$ go build server/main.go
The ACL policy is provided in policy.csv
p, alice, data1, read
p, bob, data2, write
The definition of each line within the file defines that:
alice
hasread
access todata1
bob
haswrite
access todata2
To run the application, execute this following line:
$ go run server/main.go <user> <resource> <action>
The following table provides the expected result of go run
execution
User | Resource | Action | Result |
---|---|---|---|
alice | data1 | read | Access allowed |
alice | data1 | write | Access denied |
alice | data2 | read | Access denied |
alice | data2 | write | Access denied |
bob | data1 | read | Access denied |
bob | data1 | write | Access denied |
bob | data2 | read | Access denied |
bob | data2 | write | Access allowed |
charlie | data1 | red | Access denied |