Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions docs/CommandLineTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ keywords: [command-line tools, casbin, cli]
authors: [liulifox233]
---

**Casbin CLIs** are command-line tools that provide a command-line interface for Casbin, enabling you to use all of Casbin APIs in the shell. This documentation covers the usage of Casbin CLI for various languages including Rust, Java, Go, Python, .NET, and NodeJs.
**Casbin CLIs** offer command-line interfaces that expose Casbin's full API directly in your shell environment. This guide explains how to use Casbin's CLI implementations across multiple languages, including Rust, Java, Go, Python, .NET, and Node.js.

## Installation

### Go (casbin-go-cli)

1. Clone project from repository
1. Clone the repository:

```bash
git clone https://github.com/casbin/casbin-go-cli.git
```

2. Build project
2. Build the CLI:

```bash
cd casbin-go-cli
Expand All @@ -27,21 +27,21 @@ authors: [liulifox233]

### Rust (casbin-rust-cli)

#### From crates.io
#### Install from crates.io

```bash
cargo install casbin-rust-cli
```

#### From source
#### Build from source

1. Clone project from repository
1. Clone the repository:

```bash
git clone https://github.com/casbin-rs/casbin-rust-cli.git
```

2. Build project
2. Build with release optimizations:

```bash
cd casbin-rust-cli
Expand All @@ -50,13 +50,13 @@ cargo install casbin-rust-cli

### Java (casbin-java-cli)

1. Clone project from repository
1. Clone the repository:

```bash
git clone https://github.com/jcasbin/casbin-java-cli.git
```

2. Build project, the jar package will be generated in the target directory
2. Build using Maven (the JAR file will be created in the `target` directory):

```bash
cd casbin-java-cli
Expand All @@ -65,34 +65,34 @@ cargo install casbin-rust-cli

### Python (casbin-python-cli)

1. Clone project from repository
1. Clone the repository:

```bash
git clone https://github.com/casbin/casbin-python-cli.git
```

2. Install dependencies
2. Install required dependencies:

```bash
cd casbin-python-cli
pip install -r requirements.txt
```

3. Run CLI
3. Run the CLI:

```bash
python -m casbin_cli.client [command] [options] [args]
```

### .NET (casbin-dotnet-cli)

1. Clone project from repository
1. Clone the repository:

```bash
git clone https://github.com/casbin-net/casbin-dotnet-cli.git
```

2. Build project
2. Build the project:

```bash
cd casbin-dotnet-cli
Expand All @@ -103,19 +103,19 @@ cargo install casbin-rust-cli

## Options

| options | description | must | remark |
|-----------------------|----------------------------------------------------------------------|------|-----------------------------------------------------------|
| `-m, --model` | The path of the model file or model text | y | Please wrap it with `""` and separate each line with `\|` |
| `-p, --policy` | The path of the policy file or policy text | y | Please wrap it with `""` and separate each line with `\|` |
| `-e, --enforce` | Check permissions | n | Please wrap it with `""` |
| `-ex, --enforceEx` | Check permissions and get which policy it is | n | Please wrap it with `""` |
| `-AF, --addFuntion` | Add custom funtion ( casbin-java-cli only ) | n | Please wrap it with `""` and separate each line with `\|` |
| `-ap, --addPolicy` | Add a policy rule to the policy file ( casbin-java-cli only ) | n | Please wrap it with `""` |
| `-rp, --removePolicy` | Remove a policy rule from the policy file ( casbin-java-cli only ) | n | Please wrap it with `""` |
| 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 |

## Get started
## Getting Started

- Check whether Alice has read permission on data1
- Verify if Alice can read data1:

```shell
./casbin enforce -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data1" "read"
Expand All @@ -129,23 +129,23 @@ cargo install casbin-rust-cli

> `{"allow":true,"explain":null}`

- Check whether Alice has write permission for data2. If so, display the effective policy.
- Verify if Alice can write to data2 and show which policy grants the permission:

```shell
./casbin enforceEx -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"
```

> `{"allow":true,"explain":["data2_admin","data2","write"]}`

- Add a policy to the policy file ( casbin-java-cli only )
- Add a new policy rule to the policy file (casbin-java-cli only):

```shell
./casbin addPolicy -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"
```

> `{"allow":true,"explain":null}`

- Delete a policy from the policy file ( casbin-java-cli only )
- Remove a policy rule from the policy file (casbin-java-cli only):

```shell
./casbin removePolicy -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data2" "write"
Expand Down
44 changes: 22 additions & 22 deletions docs/Contributing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ keywords: [Contributing]
authors: [Selflocking, EmperorYP7]
---

Casbin is a powerful authorization library that supports access control models with implementations in many programming languages. If you are proficient in any programming language, you can contribute to the development of Casbin. New contributors are always welcome.
Casbin is an authorization library that implements access control models across multiple programming languages. Contributors with expertise in any supported language are welcome to participate in its development.

Currently, there are two main types of projects:
The project consists of two primary categories:

* **Algorithms-oriented projects** - These projects involve implementing algorithms in different programming languages. Casbin supports a wide range of languages, including Golang, Java, C++, Elixir, Dart, and Rust, along with their related products.
* **Algorithm-focused projects** - These involve implementing Casbin's core algorithms in various languages, including Go, Java, C++, Elixir, Dart, and Rust, along with their ecosystem integrations.

| [![golang](/img/langs/golang.png)](https://github.com/casbin/casbin) | [![java](/img/langs/java.png)](https://github.com/casbin/jcasbin) | [![nodejs](/img/langs/nodejs.png)](https://github.com/casbin/node-casbin) | [![php](/img/langs/php.png)](https://github.com/php-casbin/php-casbin) |
|----------------------------------------------------------------------|-------------------------------------------------------------------|---------------------------------------------------------------------------|------------------------------------------------------------------------|
Expand All @@ -22,35 +22,35 @@ Currently, there are two main types of projects:
| [PyCasbin](https://github.com/casbin/pycasbin) | [Casbin.NET](https://github.com/casbin/Casbin.NET) | [Casbin-CPP](https://github.com/casbin/casbin-cpp) | [Casbin-RS](https://github.com/casbin/casbin-rs) |
| Production-ready | Production-ready | Production-ready | Production-ready |

* **Application-oriented projects** - These projects are related to applications built on top of Casbin.
* **Application-based projects** - These projects build applications on top of the Casbin library.

| Project | Demo | Details | Skill Stacks |
|----------------------------------------------------------|--------------------------------------------|---------------------------------------------------------------------|--------------------|
| [Casbin Editor](https://github.com/casbin/casbin-editor) | [Casbin Editor](https://editor.casbin.org) | Casbin-editor is a web-based editor for Casbin models and policies. | TypeScript + React |
| Project | Demo | Details | Tech Stack |
|----------------------------------------------------------|--------------------------------------------|-----------------------------------------------------------------------------------|--------------------|
| [Casbin Editor](https://github.com/casbin/casbin-editor) | [Casbin Editor](https://editor.casbin.org) | A browser-based editor for creating and testing Casbin models and policies. | TypeScript + React |

## Getting Involved
## Ways to Contribute

There are many ways to contribute to Casbin. Here are some ideas to get started:
There are multiple ways to help Casbin grow:

* **Use Casbin and report issues!** When using Casbin, report any issues you encounter to help promote the development of Casbin. Whether it's a bug or a proposal, filing an issue on [GitHub](https://github.com/casbin/casbin) is recommended. However, it would be better to have a discussion first on [Discord](https://discord.gg/S5UjpzGZjN) or [GitHub Discussions](https://github.com/casbin/casbin/discussions) before filing an issue.
* **Use Casbin and provide feedback** - Your real-world experience helps us improve. Report bugs or suggest features on [GitHub](https://github.com/casbin/casbin). Before opening an issue, consider discussing it first on [Discord](https://discord.gg/S5UjpzGZjN) or [GitHub Discussions](https://github.com/casbin/casbin/discussions).

> Note: When reporting an issue, please use English to describe the details of your problem.
> Note: Please describe issues in English.

* **Help with documentation!** Contributing to the documentation is a good starting point for your contribution.
* **Improve documentation** - Documentation improvements are an excellent starting point for new contributors.

* **Help solve issues!** We have prepared a table containing easy tasks suitable for beginners, with different levels of challenges labeled with different tags. You can check the table [here](https://github.com/orgs/casbin/projects/2).
* **Resolve existing issues** - Check our [issue board](https://github.com/orgs/casbin/projects/2) for beginner-friendly tasks, labeled by difficulty level.

## Pull Requests
## Submitting Pull Requests

Casbin uses GitHub as its development platform, so pull requests are the main way to contribute.
Casbin develops on GitHub, making pull requests the standard contribution method.

Before opening a pull request, there are a few things you need to know:
Before submitting a pull request:

* Explain why you are sending the pull request and what it will do for the repository.
* Clearly explain the purpose and impact of your changes on the repository.

* Make sure the pull request does only one thing. If there are multiple changes, please split them into separate pull requests.
* Keep each pull request focused on a single change. Submit separate pull requests for unrelated modifications.

* If you are adding new files, please include the Casbin license at the top of the new file(s).
* When adding new files, include the Casbin license header at the top:

```text
// Copyright 2021 The casbin Authors. All Rights Reserved.
Expand All @@ -68,8 +68,8 @@ Before opening a pull request, there are a few things you need to know:
// limitations under the License.
```

* When opening a pull request and committing your contribution, it is recommended to use semantic commits with the following format: ```<type>(<scope>): <subject>```. The ```<scope>``` is optional. For more detailed usage, please refer to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
* Use semantic commit messages following the format: ```<type>(<scope>): <subject>```. The ```<scope>``` is optional. For detailed guidelines, see [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).

## License
## Licensing

By contributing to Casbin, you agree that your contributions will be licensed under the Apache License.
All contributions to Casbin are licensed under the Apache License.
10 changes: 5 additions & 5 deletions docs/DataPermissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ keywords: [Data Permissions, implicit]
authors: [ErikQQY]
---

We have two solutions for data permissions (filtering): using implicit assignment APIs or using the `BatchEnforce()` API.
Casbin provides two approaches for implementing data-level permission filtering: querying implicit assignments or using batch enforcement.

### 1. Query Implicit Roles or Permissions
### 1. Querying Implicit Roles and Permissions

When a user inherits a role or permission via an RBAC hierarchy instead of being directly assigned them in a policy rule, we refer to this type of assignment as "implicit". To query such implicit relations, you need to use the following two APIs: `GetImplicitRolesForUser()` and `GetImplicitPermissionsForUser()`, instead of `GetRolesForUser()` and `GetPermissionsForUser()`. For more details, please refer to [this GitHub issue](https://github.com/casbin/casbin/issues/137).
When users inherit roles or permissions through an RBAC hierarchy rather than through direct policy assignments, these are called "implicit" assignments. To retrieve these relationships, use `GetImplicitRolesForUser()` and `GetImplicitPermissionsForUser()` instead of the standard `GetRolesForUser()` and `GetPermissionsForUser()` methods. Additional details are available in [this GitHub issue](https://github.com/casbin/casbin/issues/137).

### 2. Use `BatchEnforce()`
### 2. Using `BatchEnforce()`

`BatchEnforce()` enforces each request and returns the results in a boolean array.
`BatchEnforce()` evaluates multiple access requests simultaneously and returns their results as a boolean array.

For example:

Expand Down
12 changes: 6 additions & 6 deletions docs/Dispatchers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ keywords: [dispatcher]
authors: [dovics]
---

Dispatchers provide a way to synchronize incremental changes of policy. They should be based on consistency algorithms such as Raft to ensure the consistency of all enforcer instances. Through dispatchers, users can easily establish distributed clusters.
Dispatchers enable synchronization of incremental policy changes across distributed Casbin enforcer instances. They rely on consistency algorithms like Raft to maintain uniform policy state across all enforcers, simplifying the creation of distributed authorization clusters.

The dispatcher's method is divided into two parts. The first part is the method combined with Casbin. These methods should be called inside Casbin. Users can use the more complete API provided by Casbin itself.
A dispatcher's functionality is split into two parts. The first consists of methods integrated with Casbin's core. These methods are called internally by Casbin, allowing developers to use Casbin's standard API without modification.

The other part is the method defined by the dispatcher itself, including the dispatcher initialization method, and different functions provided by different algorithms, such as dynamic membership and config changes.
The second part includes the dispatcher's own initialization and algorithm-specific features, such as dynamic membership management and configuration updates.

:::note

We hope dispatchers only ensure the consistency of the Casbin enforcer at runtime. So if the policy is inconsistent during initialization, the dispatchers will not work properly. Users need to ensure that the state of all instances is consistent before using dispatchers.
Dispatchers synchronize runtime policy changes only. They do not resolve pre-existing inconsistencies during initialization. You must ensure all enforcer instances start with identical policy states before enabling dispatchers.

:::

A complete list of Casbin dispatchers is provided below. Any 3rd-party contributions on a new dispatcher are welcomed. Please inform us, and we will add it to this list.
Below is a list of available Casbin dispatchers. Contributions of new dispatchers are welcome—let us know, and we'll include them here.

```mdx-code-block
<Tabs groupId="langs">
Expand All @@ -37,7 +37,7 @@ import {DispatcherGoData} from "@site/src/tableData/DispatcherData/DispatcherGoD

### DistributedEnforcer

DistributedEnforcer wraps SyncedEnforcer for the dispatcher.
`DistributedEnforcer` wraps `SyncedEnforcer` to work with dispatchers.

```mdx-code-block
<Tabs groupId="langs">
Expand Down
Loading