Awesome Open Source
Awesome Open Source

Warrant Java Library

Use Warrant in server-side Java projects.

Maven Central Slack



implementation group: 'dev.warrant', name: 'warrant-java', version: '0.1.1'




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

    // Create users and sessions
    User user1 = client.createUser();
    System.out.println("Created user with generated id " + user1.getUserId());
    String sessionToken = client.createSession(user1.getUserId());
    System.out.println("Session token for userId " + user1.getUserId() + " : " + sessionToken);

    User user2 = client.createUser("provided_id");
    System.out.println("Created user with provided id " + user2.getUserId());

    // Create and check warrants
    client.createWarrant(Warrant.newUserWarrant("store", "store1", "owner", user1.getUserId()));
    // Should be "true"
    System.out.println(user1.getUserId() + ": " + client.isAuthorized(Warrant.newUserWarrant("store", "store1", "owner", user1.getUserId())));
    // Should be "false"
    System.out.println(user2.getUserId() + ": " + client.isAuthorized(Warrant.newUserWarrant("store", "store1", "owner", user2.getUserId())));


We’ve used a random API key in these code examples. Replace it with your actual publishable API keys 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.

Note that we may release new minor and patch versions of this library with small but backwards-incompatible fixes to the type declarations. These changes will not affect Warrant itself.

Warrant Documentation

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Java (388,172
Permission (11,613
Authorization (5,850
Acl (2,435
Rbac (1,373
Access Control (1,111
Abac (182
Role Based Access Control (82
Authz (78
Attribute Based Access Control (21