An open API service indexing awesome lists of open source software.

https://github.com/jcasbin/redis-adapter

Redis adapter for Casbin
https://github.com/jcasbin/redis-adapter

access-control adapter auth authorization authz casbin java jcasbin redis

Last synced: 6 months ago
JSON representation

Redis adapter for Casbin

Awesome Lists containing this project

README

        

# Redis Adapter

[![build](https://github.com/jcasbin/redis-adapter/actions/workflows/maven-ci.yml/badge.svg)](https://github.com/jcasbin/redis-adapter/actions)
[![codebeat badge](https://codebeat.co/badges/560a67fc-53b6-4a10-8e1b-989f3bb4e5cb)](https://codebeat.co/projects/github-com-jcasbin-redis-adapter-master)
[![codecov](https://codecov.io/gh/jcasbin/redis-adapter/branch/master/graph/badge.svg?token=5wzDaTC9UV)](https://codecov.io/gh/jcasbin/redis-adapter)
[![Javadocs](https://www.javadoc.io/badge/org.casbin/redis-adapter.svg)](https://www.javadoc.io/doc/org.casbin/redis-adapter)
[![Maven Central](https://img.shields.io/maven-central/v/org.casbin/redis-adapter.svg)](https://mvnrepository.com/artifact/org.casbin/redis-adapter/latest)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)

Redis Adapter is the [Redis](https://redis.io/) adapter for [jCasbin](https://github.com/casbin/jcasbin). With this library, Casbin can load policy from Redis or save policy to it.

## Installation

```xml

org.casbin
redis-adapter
1.0.0

```

## Simple Example

```java
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

- [jCasbin](https://github.com/casbin/jcasbin)

## License

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