MyBatis Plus adapter for Casbin

Clone this repo:

Branches

  1. 884b50e feat: Update README.md (#4) by TX · 1 year, 5 months ago master v1.1.0
  2. 994fb07 feat: fix the CI error (#3) by TX · 1 year, 5 months ago v1.0.0
  3. 46b5fd1 feat: add the code (#2) by TX · 1 year, 5 months ago
  4. b9543d0 Initial commit by Yang Luo · 1 year, 5 months ago

mybatisplus-adapter

codebeat badge build codecov javadoc Maven Central Discord

Mybatis-Plus Adapter is the Mybatis-Plus adapter for jCasbin, which provides interfaces for loading policies from Mybatis-Plus and saving policies to it.

Installation

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>mybatisplus-adapter</artifactId>
    <version>1.0.0</version>
</dependency>

Example

package com.company.example;

import org.casbin.jcasbin.main.Enforcer;
import org.casbin.jcasbin.util.Util;
import org.casbin.adapter.MybatisPlusAdapter;

public class Example {
    public void test() {
        Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");
    
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/casbin";
        String username = "YourUsername";
        String password = "YourPassword";
        
        MybatisAdapter a = new MybatisAdapter(driver, url, username, password, true);
    
        // Save policy to DB
        a.savePolicy(e.getModel());
    
        // Load policy from DB
        a.loadPolicy(e.getModel());
    }
}

Getting Help

License

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