From eee4fe93a964af70bf94f3566c9f04378e74496a Mon Sep 17 00:00:00 2001 From: Liao Xin <93535922+liewstar@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:36:38 +0800 Subject: [PATCH] feat: Use "casbin" command instead of "java -jar target/casbin-java-cli.jar" command (#14) * feat: Use "casbin" command instead of "java -jar target/casbin-java-cli.jar" command * fix: remove .sh suffix --- README.md | 10 +++++----- casbin | 2 ++ casbin.cmd | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100755 casbin create mode 100644 casbin.cmd diff --git a/README.md b/README.md index 4c482ec..9921991 100644 --- a/README.md +++ b/README.md @@ -33,32 +33,32 @@ mvn clean install - Check whether Alice has read permission on data1 ```shell - java -jar target/casbin-java-cli.jar -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -e "alice, data1, read" + ./casbin -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -e "alice, data1, read" ``` > Allow ```shell - java -jar target/casbin-java-cli.jar -m "[request_definition]|r = sub, obj, act|[policy_definition]|p = sub, obj, act|[role_definition]|g = _, _|[policy_effect]|e = some(where (p.eft == allow))|[matchers]|m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act" -p "p, alice, data1, read|p, bob, data2, write|p, data2_admin, data2, read|p, data2_admin, data2, write|g, alice, data2_admin" -e "alice, data1, read" + ./casbin -m "[request_definition]|r = sub, obj, act|[policy_definition]|p = sub, obj, act|[role_definition]|g = _, _|[policy_effect]|e = some(where (p.eft == allow))|[matchers]|m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act" -p "p, alice, data1, read|p, bob, data2, write|p, data2_admin, data2, read|p, data2_admin, data2, write|g, alice, data2_admin" -e "alice, data1, read" ``` > Allow - Check whether Alice has write permission for data2. If so, display the effective policy. ```shell - java -jar target/casbin-java-cli.jar -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -ex "alice, data2, write" + ./casbin -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -ex "alice, data2, write" ``` > true Reason: [alice, data2, write] - Add a policy to the policy file ```shell - java -jar target/casbin-java-cli.jar -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -ap "alice, data2, write" + ./casbin -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -ap "alice, data2, write" ``` > Add Success - Delete a policy from the policy file ```shell - java -jar target/casbin-java-cli.jar -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -rp "alice,data1,read" + ./casbin -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" -rp "alice,data1,read" ``` > Remove Success diff --git a/casbin b/casbin new file mode 100755 index 0000000..00c2157 --- /dev/null +++ b/casbin @@ -0,0 +1,2 @@ +#!/bin/sh +java -jar target/casbin-java-cli.jar "$@" \ No newline at end of file diff --git a/casbin.cmd b/casbin.cmd new file mode 100644 index 0000000..70124d9 --- /dev/null +++ b/casbin.cmd @@ -0,0 +1,5 @@ +@echo off +setlocal +set JAR_PATH=target\casbin-java-cli.jar +java -jar "%JAR_PATH%" %* +endlocal \ No newline at end of file