Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/warrant-dev/warrant-java

Java SDK for Warrant
https://github.com/warrant-dev/warrant-java

abac access-control acl attribute-based-access-control authorization authz java permissions rbac role-based-access-control

Last synced: about 2 months ago
JSON representation

Java SDK for Warrant

Awesome Lists containing this project

README

        

# Warrant Java Library

Use [Warrant](https://warrant.dev/) in server-side Java projects.

[![Maven Central](https://img.shields.io/maven-central/v/dev.warrant/warrant-java)](https://mvnrepository.com/artifact/dev.warrant/warrant-java)

## Installation

### Gradle

```groovy
implementation group: 'dev.warrant', name: 'warrant-java', version: '4.2.0'
```

### Maven

```xml

dev.warrant
warrant-java
4.2.0

```

## Usage

```java
public static void main(String[] args) throws WarrantException, IOException {
String apiKey = "YOUR_KEY";
WarrantClient client = new WarrantClient(WarrantConfig.withApiKey(apiKey));

// Create users, roles, permissions
User user = client.createUser();
Role adminRole = client.createRole(new Role("admin", "Admin", "Admin role"));
Permission createPermission = client.createPermission(new Permission("create-report", "Create Report" "Permission to create reports"));

// RBAC example
client.assignPermissionToRole(createPermission, adminRole);
client.assignRoleToUser(adminRole, user);
client.checkUserHasPermission(user, "create-report"); // returns true
}
```

## Configuring API Endpoints

By default, the SDK makes requests to `api.warrant.dev`. You can override this endpoint, as well as a `check` endpoint (if using Warrant Edge) via a `WarrantConfig` object passed to the client:

```java
public static void main(String[] args) throws WarrantException, IOException {
String apiKey = "YOUR_KEY";
// Initialize api endpoint to https://api.warrant.dev and check endpoint to "http://localhost:3000" (local Edge instance)
WarrantClient client = new WarrantClient(new WarrantConfig(apiKey, "https://api.warrant.dev", "http://localhost:3000"));
}
```

We’ve used a random API key in these code examples. Replace it with your [actual API keys](https://app.warrant.dev) to test this code through your own Warrant account.

For more information on how to use the Warrant API, please refer to the [Warrant API reference](https://docs.warrant.dev).

Note that we may release new [minor and patch](https://semver.org/) versions of this library with small but backwards-incompatible fixes to the type declarations. These changes will not affect Warrant itself.

## Warrant Documentation

- [Warrant Docs](https://docs.warrant.dev/)

## Development

Build and run all checks & tests:

```shell
./gradlew build
```