Redis adapter for Casbin

Clone this repo:
  1. 7b76084 feat: fix pom.xml to fix CI for publishing to https://central.sonatype.com (#21) by Liao Xin · 1 year, 5 months ago master v1.7.0
  2. 2884526 feat: update README.md with Discord badge (#20) by Coki · 1 year, 10 months ago v1.6.0
  3. 5d7d85c docs: add new constructor for Redis username in README by Yang Luo · 2 years ago
  4. 0f92b7b feat: add new constructor to support Redis username (#18) by Angus Lord · 2 years ago v1.5.0
  5. abbf498 feat: upgrade CI Node.js version to 20 by Yang Luo · 2 years ago v1.4.0

Redis Adapter

build codebeat badge codecov Javadocs Maven Central Discord

Redis Adapter is the Redis adapter for jCasbin. With this library, Casbin can load policy from Redis or save policy to it.

Installation

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

Simple Example

package org.casbin.adapter;

import org.casbin.jcasbin.main.Enforcer;

public class Main {
    public static void main(String[] args) {
        // Initialize a Redis adapter and use it in a jCasbin enforcer:
        RedisAdapter a = new RedisAdapter("localhost", 6379);

        // Use the following if Redis has password like "123"
        // RedisAdapter a = new RedisAdapter("localhost", 6379, "123");

        // Use the following if Redis has username like "default" and password like "123"
        // RedisAdapter a = new RedisAdapter("localhost", 6379, "default", "123");

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

        // Load the policy from DB.
        e.loadPolicy();

        // 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.