DynamoDB adapter for Casbin

Clone this repo:
  1. 9148324 feat: optimize savePolicy with BatchWriteItem and exponential backoff retry (#72) by Zhifan Cui · 3 months ago master v1.4.0
  2. 1246357 feat: fix CI timeout by removing verifyRelease step and using SNAPSHOT version (#70) by Yang Luo · 3 months ago v1.3.0
  3. 0f8b321 fix: fix duplicate CI checks on pull requests (#68) by Yang Luo · 3 months ago
  4. 4026618 feat: fix CI to restrict semantic-release to master branch pushes only (#64) by Yang Luo · 3 months ago
  5. fec836c fix: remove codebeat badge in README by Yang Luo · 3 months ago

DynamoDB Adapter

Build Status codecov javadoc Maven Central Discord

DynamoDB Adapter is the Amazon DynamoDB adapter for jCasbin, which provides interfaces for loading policies from DynamoDB and saving policies to it.

This adapter has been modernized to use AWS SDK v2 and supports zero-dependency testing with Testcontainers + LocalStack.

Features

  • AWS SDK v2: Uses the modern AWS SDK v2 for DynamoDB operations
  • Zero-dependency Testing: Integration tests run with Testcontainers + LocalStack (no AWS credentials required)
  • Java 8+: Compatible with Java 8 and higher

Currently we support the following interfaces:

  • loadPolicy
  • savePolicy

Installation

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>dynamodb-adapter</artifactId>
    <version>0.0.1</version>
</dependency>

Example

package com.company.example;

import org.casbin.jcasbin.main.Enforcer;
import org.casbin.adapter.DynamoDBAdapter;

public class Example {
    
    public static void main(String[] args) {
        Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");

        String endpoint = "http://localhost:8000";
        String region = "cn-north-1";
        DynamoDBAdapter a = new DynamoDBAdapter(endpoint, region);

        // Create table (only needed once)
        a.createTable();

        // Save policy to DB
        a.savePolicy(e.getModel());

        // Load policy from DB
        a.loadPolicy(e.getModel());
    }
}

Testing

This adapter uses Testcontainers with LocalStack for integration testing. To run tests:

mvn test

No AWS credentials or configuration required! Tests automatically start a LocalStack container with DynamoDB support.

Getting Help

License

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