Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 2.35 KB

README.md

File metadata and controls

64 lines (45 loc) · 2.35 KB

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.