Command-line Tools
Casbin CLIs expose the Casbin API from the command line so you can load models and policies, run enforce checks, and manage policy from your shell. Implementations are available for Go, Java, Node.js, Python, .NET, and Rust.
Installation
Go (casbin-go-cli)
-
Clone the repository:
git clone https://github.com/apache/casbin-go-cli.git -
Build the CLI:
cd casbin-go-cligo build -o casbin
Rust (casbin-rust-cli)
Install from crates.io
cargo install casbin-rust-cli
Aus dem Quellcode erstellen
-
Clone the repository:
git clone https://github.com/casbin-rs/casbin-rust-cli.git -
Build with release optimizations:
cd casbin-rust-clicargo build --release
Java (casbin-java-cli)
-
Clone the repository:
git clone https://github.com/jcasbin/casbin-java-cli.git -
Build using Maven (the JAR file will be created in the
targetdirectory):cd casbin-java-climvn clean install
Python (casbin-python-cli)
-
Clone the repository:
git clone https://github.com/apache/casbin-python-cli.git -
Install required dependencies:
cd casbin-python-clipip install -r requirements.txt -
Run the CLI:
python -m casbin_cli.client [command] [options] [args]
.NET (casbin-dotnet-cli)
-
Clone the repository:
git clone https://github.com/casbin-net/casbin-dotnet-cli.git -
Build the project:
cd casbin-dotnet-clidotnet build
Nutzung
Optionen
| Option | Description | Required | Notes |
|---|---|---|---|
-m, --model | Model file path or model definition text | Yes | Wrap in quotes and use | as line separator |
-p, --policy | Policy file path or policy definition text | Yes | Wrap in quotes and use | as line separator |
-e, --enforce | Evaluate access permissions | No | Wrap arguments in quotes |
-ex, --enforceEx | Evaluate permissions and display the matched policy | No | Wrap arguments in quotes |
-AF, --addFuntion | Register a custom function (casbin-java-cli only) | No | Wrap in quotes and use | as line separator |
-ap, --addPolicy | Append a policy rule to the policy file (casbin-java-cli only) | No | Wrap arguments in quotes |
-rp, --removePolicy | Delete a policy rule from the policy file (casbin-java-cli only) | No | Wrap arguments in quotes |
Erste Schritte
-
Verify if Alice can read data1:
./casbin enforce -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data1" "read"{"allow":true,"explain":null}./casbin enforce -m "[request_definition]\nr = sub, obj, act\n[policy_definition]\np = sub, obj, act\n[role_definition]\ng = _, _\n[policy_effect]\ne = some(where (p.eft == allow))\n[matchers]\nm = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act" -p "p, alice, data1, read\np, bob, data2, write\np, data2_admin, data2, read\np, data2_admin, data2, write\ng, alice, data2_admin" "alice" "data1" "read"{"allow":true,"explain":null} -
Verify if Alice can write to data2 and show which policy grants the permission:
./casbin enforceEx -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"{"allow":true,"explain":["data2_admin","data2","write"]} -
Add a new policy rule to the policy file (casbin-java-cli only):
./casbin addPolicy -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"{"allow":true,"explain":null} -
Remove a policy rule from the policy file (casbin-java-cli only):
./casbin removePolicy -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"{"allow":true,"explain":null}
Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.