Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new endpoint checkpermissions #2047

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ entries:
output: web
subfolders:
- title: Checking Permissions for Resources
url: /check-permissions.html
url: /basic-auth-checkpermissions.html
output: web
- title: Messages
url: /basic-messages.html
Expand Down
8 changes: 5 additions & 3 deletions documentation/src/main/resources/openapi/ditto-api-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10466,7 +10466,7 @@ components:
entityId: "org.eclipse.ditto:some-thing-1"
hasPermissions: [ "READ" ]
lamp_toggler:
resource: "message:/features/lamp/inbox/toggle"
resource: "message:/features/lamp/inbox/message/toggle"
entityId: "org.eclipse.ditto:some-thing-1"
hasPermissions: [ "WRITE" ]
PermissionEntityCheck:
Expand All @@ -10475,14 +10475,16 @@ components:
properties:
resource:
type: string
description: "Resource path the permission check applies to."
pattern: "^(thing|message|policy):(/[a-zA-Z0-9._-]+)*$"
description: "Resource key to be checked, beginning with 'thing:', 'message:', or 'policy:', followed by the specific resource path. This defines the scope of the permission request."
entityId:
type: string
description: "ThingId of the entity performing the action."
description: "ID of the entity performing the action, which could be a ThingId or PolicyId, depending on the resource context."
hasPermissions:
type: array
items:
type: string
enum: [ "READ", "WRITE" ]
description: "Required permissions on the resource."
PermissionCheckResponse:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
title: Checking Permissions for Resources
keywords: permissions, authorization, resources, policy, checkPermissions
tags: [model]
permalink: check-permissions.html
permalink: basic-auth-checkpermissions.html
---

The `/checkPermissions` endpoint allows clients to validate permissions for various entities and resources.
The `/checkPermissions` endpoint allows clients to validate permissions for specified entities on various resources, verifying access rights as defined in Ditto's policies.

## Overview

Expand All @@ -18,24 +18,31 @@ Submit a `POST` request with a JSON payload specifying entities, resources, and

```json
{
"entity_name": {
"resource": "resource_path",
"entityId": "thingId",
"hasPermissions": ["READ", "WRITE"]
}
"entity_name": {
"resource": "thing:/features/lamp/properties/on",
"entityId": "org.eclipse.ditto:some-thing-1",
"hasPermissions": ["READ"]
},
"another_entity": {
"resource": "message:/features/lamp/inbox/message/toggle",
"entityId": "org.eclipse.ditto:some-thing-2",
"hasPermissions": ["WRITE"]
}
}
```
- entity_name: Name representing the entity.
- resource: Path of the target resource (e.g., thing:/features/light/properties/on).
- entityId: Unique identifier for the entity (thingId).
- hasPermissions: List of permissions required (READ, WRITE).
-
## Fields
- entity_name: Identifier for the entity performing the action.
- resource: Path of the target resource, starting with thing:, message:, or policy: followed by a valid resource path.
- entityId: Unique identifier for the entity, such as a thingId or policyId, depending on the resource.
- hasPermissions: Array of required permissions, such as READ or WRITE.

## Response Structure
The response indicates permission status for each entity and resource, returning a JSON object mapping entities to true (authorized) or false (unauthorized) values.

```json
{
"entity_name": true
"entity_name": true,
"another_entity": false
}
```
This endpoint is especially useful for applications requiring quick permission validation for multiple entities across various resources.
23 changes: 0 additions & 23 deletions documentation/src/main/resources/pages/ditto/httpapi-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,6 @@ This maps to the following HTTP API endpoints:
* `/policies/{policyId}/entries/{entryLabel-1}/resources`: accessing the resources of a single `Policy` entry with the
label `{entryLabel-1}`

#### `/checkPermissions` in API 2
The checkPermissions endpoint verifies permissions for specified entities on various resources, ensuring they have the necessary access rights as defined in the policies.

```json
{
"lamp_reader": {
"resource": "thing:/features/lamp/properties/on",
"entityId": "org.eclipse.ditto:some-thing-1",
"hasPermissions": [
"READ"
]
},
"lamp_toggler": {
"resource": "message:/features/lamp/inbox/toggle",
"entityId": "org.eclipse.ditto:some-thing-1",
"hasPermissions": [
"WRITE"
]
}
}
```
The response will confirm if each entity has the requested permissions.

#### `/connections` in API 2

The base endpoint for accessing and working with `Connections`.
Expand Down
Loading