diff --git a/build.gradle.kts b/build.gradle.kts index d1c2a307..7912d8b6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -156,4 +156,5 @@ tasks.withType { ) ) } + from(configurations.compileClasspath.get().map { if (it.isDirectory()) it else zipTree(it) }) } \ No newline at end of file diff --git a/doc/1/controllers/auth/check-rights/index.md b/doc/1/controllers/auth/check-rights/index.md new file mode 100644 index 00000000..2ca83155 --- /dev/null +++ b/doc/1/controllers/auth/check-rights/index.md @@ -0,0 +1,74 @@ +--- +code: true +type: page +title: checkRights +description: Using the current authentication information, verify if the network connection can execute the required API request. +--- + +# checkRights + + + + +Using the current authentication information, verify if the network connection can execute the required API request. + +:::: tabs +::: tab Java + +```java +public CompletableFuture checkRights( + ConcurrentHashMap requestPayload) throws NotConnectedException, InternalException +``` + +| Property | Type | Description | +|--- |--- |--- | +| `requestPayload` |
ConcurrentHashMap
| Contains a [RequestPayload](/core/2/api/payloads/request) | + +## `requestPayload` + +The [RequestPayload](/core/2/api/payloads/request) must contain at least the following properties: + +- `controller`: API controller +- `action`: API action + +--- + +## Returns + +Returns a boolean indicating whether the provided request would have been allowed or not + +## Usage + +<<< ./snippets/check-rights-java.java + +::: +::: tab Kotlin + +```kotlin + fun checkRights( + requestPayload: ConcurrentHashMap): CompletableFuture +``` + +| Property | Type | Description | +|--- |--- |--- | +| `requestPayload` |
ConcurrentHashMap
| Contains a [RequestPayload](/core/2/api/payloads/request) | + +## `requestPayload` + +The [RequestPayload](/core/2/api/payloads/request) must contain at least the following properties: + +- `controller`: API controller +- `action`: API action + +--- + +## Returns + +Returns a boolean indicating whether the provided request would have been allowed or not + +## Usage + +<<< ./snippets/check-rights-kotlin.kt + +::: +:::: diff --git a/doc/1/controllers/auth/check-rights/snippets/check-rights-java.java b/doc/1/controllers/auth/check-rights/snippets/check-rights-java.java new file mode 100644 index 00000000..ef610d8d --- /dev/null +++ b/doc/1/controllers/auth/check-rights/snippets/check-rights-java.java @@ -0,0 +1,12 @@ +ConcurrentHashMap body = new ConcurrentHashMap<>(); +body.put("name", "Melis"); + +ConcurrentHashMap requestPayload = new ConcurrentHashMap<>(); +requestPayload.put("controller", "document"); +requestPayload.put("action", "create"); +requestPayload.put("index", "nyc-open-data"); +requestPayload.put("collection", "yellow-taxi"); +requestPayload.put("body", body); + +Boolean result = + kuzzle.getAuthController().checkRights(requestPayload).get(); diff --git a/doc/1/controllers/auth/check-rights/snippets/check-rights-java.test.yml b/doc/1/controllers/auth/check-rights/snippets/check-rights-java.test.yml new file mode 100644 index 00000000..bde01332 --- /dev/null +++ b/doc/1/controllers/auth/check-rights/snippets/check-rights-java.test.yml @@ -0,0 +1,7 @@ +name: java-auth#checkRights +description: Checks if an API action can be executed by the current user +hooks: + before: curl -X POST kuzzle:7512/users/foo/_create -H "Content-Type:application/json" --data '{"content":{"profileIds":["default"]},"credentials":{"local":{"username":"foo","password":"bar"}}}' + after: curl -X DELETE kuzzle:7512/users/foo +template: print-result +expected: true \ No newline at end of file diff --git a/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.kt b/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.kt new file mode 100644 index 00000000..abd112be --- /dev/null +++ b/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.kt @@ -0,0 +1,13 @@ +val body = ConcurrentHashMap().apply { + put("name", "Melis") +} + +val requestPayload = ConcurrentHashMap().apply { + put("controller", "document") + put("action", "create") + put("index", "nyc-open-data") + put("collection", "yellow-taxi") + put("body", body) +} + +val result = kuzzle.authController.checkRights(requestPayload).get() \ No newline at end of file diff --git a/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.test.yml b/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.test.yml new file mode 100644 index 00000000..5ce27aa8 --- /dev/null +++ b/doc/1/controllers/auth/check-rights/snippets/check-rights-kotlin.test.yml @@ -0,0 +1,7 @@ +name: kotlin-auth#checkRights +description: Checks if an API action can be executed by the current user +hooks: + before: curl -X POST kuzzle:7512/users/foo/_create -H "Content-Type:application/json" --data '{"content":{"profileIds":["default"]},"credentials":{"local":{"username":"foo","password":"bar"}}}' + after: curl -X DELETE kuzzle:7512/users/foo +template: print-result +expected: true \ No newline at end of file diff --git a/doc/1/controllers/document/search/snippets/search-java.java b/doc/1/controllers/document/search/snippets/search-java.java index d438e48c..9a0eecdb 100644 --- a/doc/1/controllers/document/search/snippets/search-java.java +++ b/doc/1/controllers/document/search/snippets/search-java.java @@ -1,36 +1,36 @@ - ConcurrentHashMap searchQuery = new ConcurrentHashMap<>(); - ConcurrentHashMap query = new ConcurrentHashMap<>(); - ConcurrentHashMap match = new ConcurrentHashMap<>(); - match.put("category", "suv"); - query.put("match", match); - searchQuery.put("query", query); +ConcurrentHashMap searchQuery = new ConcurrentHashMap<>(); +ConcurrentHashMap query = new ConcurrentHashMap<>(); +ConcurrentHashMap match = new ConcurrentHashMap<>(); +match.put("category", "suv"); +query.put("match", match); +searchQuery.put("query", query); - SearchResult results = kuzzle - .getDocumentController() - .search("nyc-open-data", "yellow-taxi", searchQuery).get(); +SearchResult results = kuzzle + .getDocumentController() + .search("nyc-open-data", "yellow-taxi", searchQuery).get(); - /* +/* +{ + "aggregations"=undefined, + "hits"=[ { - "aggregations"=undefined, - "hits"=[ - { - "_id"="AWgi6A1POQUM6ucJ3q06", - "_score"=0.046520017, - "_source"={ - "category"="suv", - "_kuzzle_info"={ - "author"="-1", - "createdAt"=1546773859655, - "updatedAt"=null, - "updater"=null - } - } - }, - ... - ] + "_id"="AWgi6A1POQUM6ucJ3q06", + "_score"=0.046520017, + "_source"={ + "category"="suv", + "_kuzzle_info"={ + "author"="-1", + "createdAt"=1546773859655, + "updatedAt"=null, + "updater"=null + } + } }, - "total"=5, - "fetched"=5, - "scroll_id"=undefined - */ + ... + ] +}, +"total"=5, +"fetched"=5, +"scroll_id"=undefined +*/ diff --git a/src/main/kotlin/io/kuzzle/sdk/controllers/AuthController.kt b/src/main/kotlin/io/kuzzle/sdk/controllers/AuthController.kt index 8377979f..c9a37c35 100644 --- a/src/main/kotlin/io/kuzzle/sdk/controllers/AuthController.kt +++ b/src/main/kotlin/io/kuzzle/sdk/controllers/AuthController.kt @@ -9,6 +9,21 @@ import java.util.concurrent.ConcurrentHashMap class AuthController(kuzzle: Kuzzle) : BaseController(kuzzle) { + fun checkRights( + requestPayload: ConcurrentHashMap): CompletableFuture { + val query = KuzzleMap().apply { + put("controller", "auth") + put("action", "checkRights") + put("body", requestPayload) + } + return kuzzle + .query(query) + .thenApplyAsync { response -> KuzzleMap + .from(response.result as ConcurrentHashMap) + .getBoolean("allowed") as Boolean + } + } + fun checkToken( token: String): CompletableFuture> { val query = KuzzleMap().apply {