Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 2.77 KB

README_EN.md

File metadata and controls

43 lines (30 loc) · 2.77 KB

jcasbin-nutz-plugin

build Maven Central

jcasbin-nutz-plugin is an authorization middleware for Nutz, it's based on https://github.com/casbin/jcasbin. It is developed under the latest Nutz 1.r.65 and Java 8.

Installation

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>jcasbin-nutz-plugin</artifactId>
    <version>1.0.0</version>
</dependency>

Simple Example

This project itself is a working Nutz project that integrates with jCasbin. The steps to use jCasbin in your own Nutz project are:

  1. Copy the JCasbinAuthzFilter class to your own project.
  2. Copy authz_model.conf and authz_policy.csv to your project. You can modify them to your own jCasbin model and policy (or loading policy from DB), see Model persistence and Policy persistence.
  3. Replace the HttpBasicAuthnFilter class (which provides HTTP basic authentication) with your own authentication like OAuth, Apache Shiro, Spring Security, etc. Rewrite JCasbinAuthzFilter's String getUser(HttpServletRequest request) method to make sure jCasbin can get the authenticated user name.
  4. Make sure the JCasbinAuthzFilter filter is loaded, so it can filter all your requests. To do this, you can use the following code in your MainModule class:
@Filters({@By(type=JCasbinAuthzFilter.class), @By(type=HttpBasicAuthnFilter.class)})
public class MainModule {
    ...
}

Tutorials

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.