{"id":21252629,"url":"https://github.com/jcasbin/nutz-authz","last_synced_at":"2025-04-14T03:52:44.704Z","repository":{"id":54145686,"uuid":"134684682","full_name":"jcasbin/nutz-authz","owner":"jcasbin","description":"Java框架Nutz的基于jCasbin的权限管理插件","archived":false,"fork":false,"pushed_at":"2024-10-05T00:23:13.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T17:51:57.580Z","etag":null,"topics":["abac","access-control","authorization","casbin","nutz","plugin","rbac"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/jcasbin","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcasbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-24T08:24:00.000Z","updated_at":"2024-10-05T00:22:01.000Z","dependencies_parsed_at":"2022-08-13T07:31:24.965Z","dependency_job_id":null,"html_url":"https://github.com/jcasbin/nutz-authz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fnutz-authz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fnutz-authz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fnutz-authz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fnutz-authz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcasbin","download_url":"https://codeload.github.com/jcasbin/nutz-authz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819359,"owners_count":21166474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abac","access-control","authorization","casbin","nutz","plugin","rbac"],"created_at":"2024-11-21T03:48:11.466Z","updated_at":"2025-04-14T03:52:44.676Z","avatar_url":"https://github.com/jcasbin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jcasbin-nutz-plugin\n[![build](https://github.com/jcasbin/jcasbin-nutz-plugin/actions/workflows/maven-ci.yml/badge.svg)](https://github.com/jcasbin/jcasbin-nutz-plugin/actions/workflows/maven-ci.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/org.casbin/jcasbin-nutz-plugin.svg)](https://central.sonatype.com/artifact/org.casbin/jcasbin-nutz-plugin)\n\n[(For English version)](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/README_EN.md)\n\njcasbin-nutz-plugin是专门为Java Web框架[Nutz](https://nutzam.com/)打造的权限管理插件, 基于[https://github.com/casbin/jcasbin](https://github.com/casbin/jcasbin)技术实现。基于最新的Nutz ``1.r.65``和Java ``8``版本进行开发。\n\n## 安装\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.casbin\u003c/groupId\u003e\n    \u003cartifactId\u003ejcasbin-nutz-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## 一个简单例子\n\n本项目自身就是一个Nutz项目，演示了如何与jCasbin权限框架集成。如果你要在自己的Nutz项目里使用jCasbin进行权限管理，可以参考如下步骤：\n\n1. 把这个类：[JCasbinAuthzFilter](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/src/main/java/org/jcasbin/plugins/JCasbinAuthzFilter.java)复制到你自己的项目里；\n2. 把jCasbin的模型文件：[authz_model.conf](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/examples/authz_model.conf)和策略文件：[authz_policy.csv](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/examples/authz_policy.csv)复制到你自己的项目里。你可以按自己需求这几个文件（或者直接从数据库读取策略），详情请参考：[如何读写jCasbin模型](https://github.com/casbin/casbin/wiki/Model-persistence)以及[如何读写jCasbin策略](https://github.com/casbin/casbin/wiki/Policy-persistence)；\n3. 把这个类：[HttpBasicAuthnFilter](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/src/main/java/org/jcasbin/plugins/HttpBasicAuthnFilter.java)（实现了[HTTP basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication)）替换成你自己的身份认证机制（用户登录），比如OAuth、Apache Shiro、Spring Security等。重写``JCasbinAuthzFilter``里的这个方法：[String getUser(HttpServletRequest request)](https://github.com/jcasbin/jcasbin-nutz-plugin/blob/master/src/main/java/org/jcasbin/plugins/JCasbinAuthzFilter.java#L42-L56)来保证jCasbin能够得到登录后的用户名；\n4. 保证``JCasbinAuthzFilter``过滤器被加载, 使其可以过滤所有请求。可以参考下面的例子对``MainModule``类进行修改：\n\n```java\n@Filters({@By(type=JCasbinAuthzFilter.class), @By(type=HttpBasicAuthnFilter.class)})\npublic class MainModule {\n    ...\n}\n```\n\n## 教程\n\n- [比Shiro更简单的Nutz权限管理：与jCasbin权限管理框架进行整合](https://nutz.cn/yvr/t/7v1m8jh2qejo7qu5460m2qgmul)\n\n## 帮助\n\n- [jCasbin](https://github.com/casbin/jcasbin)\n\n## 协议\n\n本软件采用``Apache 2.0``授权协议开源，请点击[LICENSE](LICENSE)查看完整授权协议。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fnutz-authz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcasbin%2Fnutz-authz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fnutz-authz/lists"}