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

Fix #180: Document specific errors in REST API responses #185

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
34 changes: 17 additions & 17 deletions docs/Database-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ In our case, the authentication tables are prefixed by `uds_`.

This chapter explains individual tables and their columns. The column types are used from PostgreSQL dialect, other databases use types that are equivalent (mapping is usually straight-forward).

<!-- begin database table uds_user_claims -->
### User Claims Table

Stores user claims.

#### Schema

| Name | Type | Info | Note |
|--------------------------|-------------------------------|---------------------------|----------------------------------------------------------------------------------------------------------------|
| `user_id` | `VARCHAR(255)` | `NOT NULL PRIMARY KEY` | Record identifier taken over from the creator. |
| `claims` | `TEXT` | `NOT NULL PRIMARY KEY` | JSON with claims. Format depends on value of `encryption_mode`. |
| `encryption_mode` | `VARCHAR(255)` | `DEFAULT 'NO_ENCRYPTION'` | Drives format of claims. `NO_ENCRYPTION` means plaintext, `AES_HMAC` for AES encryption with HMAC-based index. |
| `timestamp_created` | `TIMESTAMP WITHOUT TIME ZONE` | `DEFAULT NOW()'` | Timestamp of creation. |
| `timestamp_last_updated` | `TIMESTAMP WITHOUT TIME ZONE` | | Timestamp of last update if any. |

<!-- end -->

<!-- begin database table uds_document -->
### Documents Table

Expand Down Expand Up @@ -128,3 +111,20 @@ Stores attachments.
| `timestamp_last_updated` | `TIMESTAMP WITHOUT TIME ZONE` | | Optional timestamp of last update of the attachment. |

<!-- end -->

<!-- begin database table uds_user_claims -->
### User Claims Table

Stores user claims.

#### Schema

| Name | Type | Info | Note |
|--------------------------|-------------------------------|---------------------------|----------------------------------------------------------------------------------------------------------------|
| `user_id` | `VARCHAR(255)` | `NOT NULL PRIMARY KEY` | Record identifier taken over from the creator. |
| `claims` | `TEXT` | `NOT NULL PRIMARY KEY` | JSON with claims. Format depends on value of `encryption_mode`. |
| `encryption_mode` | `VARCHAR(255)` | `DEFAULT 'NO_ENCRYPTION'` | Drives format of claims. `NO_ENCRYPTION` means plaintext, `AES_HMAC` for AES encryption with HMAC-based index. |
| `timestamp_created` | `TIMESTAMP WITHOUT TIME ZONE` | `DEFAULT NOW()'` | Timestamp of creation. |
| `timestamp_last_updated` | `TIMESTAMP WITHOUT TIME ZONE` | | Timestamp of last update if any. |

<!-- end -->
1 change: 1 addition & 0 deletions docs/Deploying-User-Data-Store.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The deployed application is accessible on `http://localhost:8080/user-data-store
## Supported Java Runtime Versions

The following Java runtime versions are supported:
- Java 21 (LTS release)
- Java 17 (LTS release)

The User Data Store may run on other Java versions, however we do not perform extensive testing with non-LTS releases.
170 changes: 169 additions & 1 deletion docs/User-Data-Store-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ Fetch documents for a user.
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: 'e6eea62b-274b-4c6a-81a8-5bbc75811863'"
}
}
```
<!-- end -->

<!-- begin api POST /admin/documents -->
Expand Down Expand Up @@ -311,6 +323,18 @@ Update a document.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '8ab06a8d-b850-4259-9756-52ed44514b1'"
}
}
```
<!-- end -->

<!-- begin api DELETE /admin/documents -->
Expand Down Expand Up @@ -405,6 +429,18 @@ Fetch photos for a user.
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '8ab06a8d-b850-4259-9756-52ed44514b1'"
}
}
```
<!-- end -->

<!-- begin api POST /admin/photos -->
Expand Down Expand Up @@ -464,6 +500,30 @@ Create a photo.
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '49c6e850-900e-4d90-bdc8-d9bb47e44384'"
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "User reference not valid, ID: 'user1'"
}
}
```
<!-- end -->

<!-- begin api PUT /admin/photos/{photoId} -->
Expand Down Expand Up @@ -521,6 +581,18 @@ Update a photo.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Photo not found, ID: 'e42c8432-6971-419d-9a23-1c4042d91e24'"
}
}
```
<!-- end -->

<!-- begin api DELETE /admin/photos -->
Expand Down Expand Up @@ -561,6 +633,18 @@ Delete photos.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '49c6e850-900e-4d90-bdc8-d9bb47e44384'"
}
}
```
<!-- end -->

<!-- begin api GET /attachments -->
Expand Down Expand Up @@ -615,6 +699,18 @@ Fetch attachments for a user.
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '8ab06a8d-b850-4259-9756-52ed44514b1'"
}
}
```
<!-- end -->

<!-- begin api POST /admin/attachments -->
Expand Down Expand Up @@ -674,6 +770,30 @@ Create an attachment.
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '49c6e850-900e-4d90-bdc8-d9bb47e44384'"
}
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "User reference not valid, ID: 'user1'"
}
}
```
<!-- end -->

<!-- begin api PUT /admin/attachments/{attachmentId} -->
Expand Down Expand Up @@ -731,6 +851,18 @@ Update an attachment.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Attachment not found, ID: '7ae0eef7-d266-4662-9c20-749e42f69f1b'"
}
}
```
<!-- end -->

<!-- begin api DELETE /admin/attachments -->
Expand Down Expand Up @@ -771,6 +903,18 @@ Delete attachments.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Document not found, ID: '49c6e850-900e-4d90-bdc8-d9bb47e44384'"
}
}
```
<!-- end -->

<!-- begin api GET /claims -->
Expand Down Expand Up @@ -816,7 +960,7 @@ Fetch claims for a user.
```
<!-- end -->

<!-- begin api POST /admin/attachments -->
<!-- begin api POST /admin/claims -->
### Create Claims

Create a claim.
Expand Down Expand Up @@ -859,6 +1003,18 @@ Create a claim.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "ALREADY_EXISTS",
"message": "Claims for user 'user1' already exist"
}
}
```
<!-- end -->

<!-- begin api PUT /admin/claims -->
Expand Down Expand Up @@ -904,6 +1060,18 @@ Create a claim.
"status": "OK"
}
```

#### Response 400

```json
{
"status": "ERROR",
"responseObject": {
"code": "NOT_FOUND",
"message": "Claims for user 'user1' do not exist"
}
}
```
<!-- end -->

<!-- begin api DELETE /admin/claims -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.wultra.security.userdatastore.model.error.EncryptionException;
import com.wultra.security.userdatastore.model.error.InvalidRequestException;
import com.wultra.security.userdatastore.model.error.ResourceAlreadyExistsException;
import com.wultra.security.userdatastore.model.error.ResourceNotFoundException;
import io.getlime.core.rest.model.base.response.ErrorResponse;
import jakarta.validation.ConstraintViolationException;
Expand Down Expand Up @@ -94,4 +95,17 @@ public ErrorResponse handleNotFoundException(final ResourceNotFoundException e)
return new ErrorResponse("NOT_FOUND", e.getMessage());
}

/**
* Exception handler for {@link ResourceAlreadyExistsException}.
*
* @param e Exception.
* @return Response with error details.
*/
@ExceptionHandler(ResourceAlreadyExistsException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleAlreadyExistsException(final ResourceAlreadyExistsException e) {
logger.warn("Error occurred when processing request object.", e);
return new ErrorResponse("ALREADY_EXISTS", e.getMessage());
}

}
Loading
Loading