https://github.com/jcasbin/play-authz
Play Framework's Authorization Middleware based on Casbin
https://github.com/jcasbin/play-authz
abac acl auth authorization authz casbin java jcasbin middleware play play-framework playframework plugin rbac
Last synced: 6 months ago
JSON representation
Play Framework's Authorization Middleware based on Casbin
- Host: GitHub
- URL: https://github.com/jcasbin/play-authz
- Owner: jcasbin
- License: apache-2.0
- Created: 2022-03-16T00:57:20.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T08:52:13.000Z (7 months ago)
- Last Synced: 2024-11-17T13:04:35.907Z (6 months ago)
- Topics: abac, acl, auth, authorization, authz, casbin, java, jcasbin, middleware, play, play-framework, playframework, plugin, rbac
- Language: Java
- Homepage: https://github.com/casbin/jcasbin
- Size: 30.3 KB
- Stars: 4
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# play-authz
[](https://codebeat.co/projects/github-com-jcasbin-play-authz-master)
[](https://github.com/jcasbin/dynamodb-adapter/actions)
[](https://codecov.io/gh/jcasbin/play-authz)
[](https://javadoc.io/doc/org.casbin/play-authz)
[](https://mvnrepository.com/artifact/org.casbin/play-authz/latest)
[](https://discord.gg/S5UjpzGZjN)Table of Contents
## About The Project
This provides **jcasbin** support to __Play Framework__.
Policy can be defined either in a `.conf` file or through _JDBC_ adapter.
## Getting Started
* [Play framework](https://www.playframework.com/getting-started)
* [Casbin](https://casbin.org/docs/category/the-basics/)## Dependency
* [jcasbin](https://mvnrepository.com/artifact/org.casbin/jcasbin)
* [jdbc-adapter](https://mvnrepository.com/artifact/org.casbin/jdbc-adapter)
* database of your choice (in case you want to use JDBC Adapter)_(versions used for the project -`sbt`)_
```
"org.casbin" % "jcasbin" % "1.24.0",
"org.casbin" % "jdbc-adapter" % "2.3.3",
"org.postgresql" % "postgresql" % "42.5.0"```
## Configuration
1) __Default__:
```
casbin {
model = conf/casbin/model.conf
policy = conf/casbin/policy.csv
storeType = jdbc
...
}
```
2) __To use model, policy files__:
* Make sure to add your model and policy files in `casbin` directory which is under the `conf` directory.
* Set `storeType = file`_Note: If model file is not provided then default model will be used_.
3) __To use JDBC Adapter for defining policy__:
* Add your rules in `casbin_rule` table (will be created by default if not present).Config example:
```
db.default {
driver = org.someDriver.Driver
url = "jdbc:example:example:play"
username = user
password = password
...
}
```## Usage
You can use enforcer by doing dependency injection in your controller.
```
@Inject
public PostResourceHandler(... other params, CasbinEnforcer enforcer) {
...
this.enforcer = enforcer;
}
```Then everything else stays the same.
```
if(enforcer.enforce(role, resource, action)) {
// some logic
}
```