{"id":28028393,"url":"https://github.com/permitio/permit-java","last_synced_at":"2026-01-04T17:13:38.445Z","repository":{"id":57736035,"uuid":"452094719","full_name":"permitio/permit-java","owner":"permitio","description":"Java SDK for Permit.io: Plug \u0026 Play Application Level Authorization","archived":false,"fork":false,"pushed_at":"2025-03-31T17:30:09.000Z","size":1631,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-11T07:12:55.224Z","etag":null,"topics":["access-control","attribute-based-access-control","authorization","java","permissions","rbac","role-based-access-control","sdk"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/permitio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-26T00:56:46.000Z","updated_at":"2025-03-31T12:52:26.000Z","dependencies_parsed_at":"2024-04-15T17:11:01.205Z","dependency_job_id":"872690e3-92a1-4d53-af98-c03f27105131","html_url":"https://github.com/permitio/permit-java","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permitio","download_url":"https://codeload.github.com/permitio/permit-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253528978,"owners_count":21922637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["access-control","attribute-based-access-control","authorization","java","permissions","rbac","role-based-access-control","sdk"],"created_at":"2025-05-11T07:13:04.626Z","updated_at":"2026-01-04T17:13:38.410Z","avatar_url":"https://github.com/permitio.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Java.png](imgs/Java.png)\n# Java SDK for Permit.io\n\nJava SDK for interacting with the Permit.io full-stack permissions platform.\n\n## Overview\n\nThis guide will walk you through the steps of installing the Permit.io Java SDK and integrating it into your code.\n\n## Installation\n\nFor [Maven](https://maven.apache.org/) projects, use:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.permit\u003c/groupId\u003e\n  \u003cartifactId\u003epermit-sdk-java\u003c/artifactId\u003e\n  \u003cversion\u003e2.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nFor [Gradle](https://gradle.org/) projects, configure `permit-sdk-java` as a dependency in your `build.gradle` file:\n\n```groovy\ndependencies {\n    // ...\n\n    implementation 'io.permit:permit-sdk-java:2.0.0'\n}\n```\n\n## Usage\n\n### Initializing the SDK\n\nTo init the SDK, you need to create a new Permit client with the API key you got from the Permit.io dashboard.\n\nFirst we will create a new `PermitConfig` object so we can pass it to the Permit client.\n\nSecond, we will create a new `Permit` client with the `PermitConfig` object we created.\n\n```java\nimport io.permit.sdk.Permit;\nimport io.permit.sdk.PermitConfig;\n\n// This line initializes the SDK and connects your Java app\n// to the Permit.io PDP container you've set up in the previous step.\nPermit permit = new Permit(\n    new PermitConfig.Builder(\"[YOUR_API_KEY]\")\n        // in production, you might need to change this url to fit your deployment\n        .withPdpAddress(\"http://localhost:7766\")\n        // optionally, if you wish to get more debug messages to your log, set this to true\n        .withDebugMode(false)\n        .build()\n    );\n```\n\n### Checking permissions\n\nTo check permissions using our `permit.check()` method, you will have to create User and Resource models as input to the permission check.\nThe models are located in ``\n\nFollow the example below:\n\n```java\nimport io.permit.sdk.enforcement.Resource;\nimport io.permit.sdk.enforcement.User;\nimport io.permit.sdk.Permit;\n\nboolean permitted = permit.check(\n    // building the user object using User.fromString()\n    // the user key (this is the unique identifier of the user in the permission system).\n    User.fromString(\"[USER KEY]\"),\n    // the action key (string)\n    \"create\",\n    // the resource object, can be initialized from string if the \"default\" tenant is used.\n    Resource.fromString(\"document\")\n);\n\nif (permitted) {\n  System.out.println(\"User is PERMITTED to create a document in the 'default' tenant\");\n} else {\n  System.out.println(\"User is NOT PERMITTED to create a document in the 'default' tenant\");\n}\n```\n\nA more complicated example (passing attributes on the user object, using an explicit tenant in the resource):\n\n```java\nimport io.permit.sdk.enforcement.Resource;\nimport io.permit.sdk.enforcement.User;\nimport java.util.HashMap;\n\n\nHashMap\u003cString, Object\u003e userAttributes = new HashMap\u003c\u003e();\nuserAttributes.put(\"age\", Integer.valueOf(20));\nuserAttributes.put(\"favorite_color\", \"yellow\");\n\nboolean permitted = permit.check(\n    // building the user object using the User.Builder class\n    new User.Builder(\"[USER KEY]\").withAttributes(userAttributes).build(),\n    // the action key (string)\n    \"create\",\n    // building the resource object using the Resource.Builder in order to pass an explicit tenant key: \"awesome-inc\"\n    new Resource.Builder(\"document\").withTenant(\"awesome-inc\").build()\n);\n\nif (permitted) {\n  System.out.println(\"User is PERMITTED to create a document in the 'awesome-inc' tenant\");\n} else {\n  System.out.println(\"User is NOT PERMITTED to create a document in the 'awesome-inc' tenant\");\n}\n```\n\n### Syncing users\n\nWhen the user first logins, and after you check if he authenticated successfully (i.e: **by checking the JWT access token**) -\nyou need to declare the user in the permission system so you can run `permit.check()` on that user.\n\nTo declare (or \"sync\") a user in the Permit.io API, use the `permit.api.users.sync()` method.\n\nFollow the example below:\n\n```java\nimport io.permit.sdk.api.models.CreateOrUpdateResult;\nimport io.permit.sdk.enforcement.User;\n\nHashMap\u003cString, Object\u003e userAttributes = new HashMap\u003c\u003e();\nuserAttributes.put(\"age\", Integer.valueOf(50));\nuserAttributes.put(\"fav_color\", \"red\");\n\nCreateOrUpdateResult\u003cUserRead\u003e result = permit.api.users.sync(\n    (new User.Builder(\"auth0|elon\"))\n        .withEmail(\"elonmusk@tesla.com\")\n        .withFirstName(\"Elon\")\n        .withLastName(\"Musk\")\n        .withAttributes(userAttributes)\n        .build()\n);\nUserRead user = result.getResult();\nassertTrue(result.wasCreated());\n```\n\nMost params to UserCreates are optional, and only the unique user key is needed. This is valid:\n\n```java\nCreateOrUpdateResult\u003cUserRead\u003e result = permit.api.users.sync(new UserCreate(\"[USER KEY]\"));\n```\n\n## Javadoc reference\n\nTo view the javadoc reference, [click here](https://javadoc.io/doc/io.permit/permit-sdk-java/2.0.0/index.html).\n\nIt's easiest to start with the root [Permit](https://javadoc.io/static/io.permit/permit-sdk-java/2.0.0/io/permit/sdk/Permit.html) class.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermitio%2Fpermit-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-java/lists"}