Coder Social home page Coder Social logo

jdbc-adapter's Introduction

JDBC Adapter

codebeat badge Build Status Coverage Status Javadocs Maven Central Gitter

JDBC Adapter is the JDBC adapter for jCasbin. With this library, jCasbin can load policy from JDBC supported database or save policy to it.

Based on Supported JDBC Drivers and Databases, The current supported databases are:

  • MySQL
  • Java DB
  • Oracle
  • PostgreSQL
  • DB2
  • Sybase
  • Microsoft SQL Server

Verified Database

  • MySQL
  • PostgreSQL
  • Microsoft SQL Server

We need more developers to help us verify.

Installation

For Maven:

<dependency>
  <groupId>org.casbin</groupId>
  <artifactId>jdbc-adapter</artifactId>
  <version>2.0.0</version>
</dependency>

Simple Example

package com.company.test;

import org.casbin.jcasbin.main.Enforcer;
import org.casbin.jcasbin.util.Util;
import org.casbin.adapter.JDBCAdapter;
import com.mysql.cj.jdbc.MysqlDataSource;

public class Test {
    public static void main() {
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/db_name";
        String username = "root";
        String password = "123456";

        // The adapter will use the table named "casbin_rule".
        // Use driver, url, username and password to initialize a JDBC adapter.
        JDBCAdapter a = new JDBCAdapter(driver, url, username, password); 
        
        // Recommend use DataSource to initialize a JDBC adapter.
        // Implementer of DataSource interface, such as hikari, c3p0, durid, etc.
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setURL(url);
        dataSource.setUser(username);
        dataSource.setPassword(password);

        a = JDBCAdapter(dataSource);        

        Enforcer e = new Enforcer("examples/rbac_model.conf", a);

        // Check the permission.
        e.enforce("alice", "data1", "read");

        // Modify the policy.
        // e.addPolicy(...);
        // e.removePolicy(...);

        // Save the policy back to DB.
        e.savePolicy();
    }
}

Getting Help

License

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

jdbc-adapter's People

Contributors

cathysha avatar fengxq2014 avatar hsluoyz avatar lixuanbin avatar nodece avatar yl-yue avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.