Redis Adapter is the Redis adapter for jCasbin. With this library, Casbin can load policy from Redis or save policy to it.
<dependency>
<groupId>org.casbin</groupId>
<artifactId>redis-adapter</artifactId>
<version>1.0.0</version>
</dependency>
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();
}
}
This project is under Apache 2.0 License. See the LICENSE file for the full license text.