A REST API to create and return dummy JSON objects for testing and mocking, by Duberly Guarnizo
- Multilingual ( translations easily created adding a translation properties file)
- REST error descriptions (via ProblemDetail specification)
- JSON Web Tokens (JWT: no need for csrf)
- User roles and endpoints permissions.
- Auditable entities
- Multi-session (Tokens with expiration and revoking flags stored on db per session)
- OpenAPI compatible (via SpringDoc)
- Spring Boot 3.1
- Gradle
- Docker (& TestContainers for testing)
- Mapstruct
- OpenAPI (Swagger UI for frontend)
- JJWT
Dummy Json is designed to return a valid JSON object (previously created by the user) or an error description ( implemented with Spring's ProblemDetail interface). The user creates an account, logs in sending a JSON body with username and password, and gets a JSON body with a JWT token. Session is created when such JWT is added to the requests headers, and is validated. With an open session, user creates a new JsonContent entity, and gets an url to query this content. Any internet user can utilize that URL to get the same JsonContent (that endpoint is not secured). Abuse is avoided by IP filtering and limiting number of queries in a space of time.
You need to configure the following environment variables for the program to work properly:
- FIRST_ADMIN_USERNAME: The username for the first admin created.
- FIRST_ADMIN_PASSWORD: The password for the first admin created.
- JWT_KEY: Your key to encode the JSON Web Tokens. Keep this secret!
- HOST_NAME: Your domain name, ie: duberlyguarnizo.com
The environment variables related to the first admin created are only used for the first boot. If any user exists with role ADMIN, the creation is skipped. Still, the presence of those environment variables is required.
A user is either an admin, a supervisor, or a "client" (user who creates an account and uploads new JsonContent).It has a role and permissions associated.
JsonContent is an object that contains a text-formatted JSON object (not validated, yet).
Represents a JWT token saved to validate if the request's token is expired (in case of abuse), revoked (log out), and the associated user, so multiple concurrent tokens can be created per user (i.e.: when using multiple devices).
To be thrown and managed with ProblemDetails API.
You can access the Swagger UI at: http://localhost:8080/swagger-ui/index.html where you will find all API definitions.
Send an AuthenticationRequest body, via POST request to http://localhost:8080/api/v1/auth/authenticate with username and password fields. You will get a JWT token that you must attach in your headers as a bearer token. The body must be formed like this:
{
"username": "your-user-name",
"password": "your-password"
}
And the response, if correct credentials have been submitted:
{
"jwt": "your-long-jwt-auth-token"
}
-[ ] Validate JSON content uploaded by user -[ ] Implement frontend -[ ] Add HATEOAS support -[ ] Manage some ugly Spring RequestFilter exceptions