This project is a minimal demonstration of issuing JSON Web Tokens (JWTs) using Spring Boot. Each API client is stored in PostgreSQL and has its own RSA key pair for signing tokens. Secrets are encrypted using AES before being persisted.
- API clients –
ApiCliententities are stored in the database. When a new client first requests a token, a RSA key pair is generated and the private key is encrypted before being saved. TheApiClientServicehandles CRUD operations. - Token issuance –
/tokenaccepts aclientIdandclientSecret. When the secret matches the stored client, theTokenServicegenerates an access token (valid for one hour) and a refresh token (valid for seven days) usingJwtUtil. - Token refresh –
/token/refreshtakes a refresh token. If it is valid, a new token pair is produced. - Token validation –
TokenFilterintercepts requests to paths beginning with/secure. It validates the JWT and, if valid, places the authenticated user in theSecurityContextHolderso the controller can access it.
The service requires a running PostgreSQL instance. Update src/main/resources/application.yaml with the correct credentials and run:
sh ./mvnw spring-boot:runTests can be executed with:
sh ./mvnw testNote: tests start the Spring context and will attempt to connect to the configured database.
| Method | Path | Description |
|---|---|---|
| POST | /token |
Issue a new access and refresh token |
| POST | /token/refresh |
Refresh an existing access token |
| GET | /secure/test |
Example secured endpoint (requires Authorization: Bearer <token>) |
| GET | /test |
Public endpoint for basic connectivity checks |
The project uses the Maven wrapper. All dependencies are declared in pom.xml. The build target produces a Spring Boot fat JAR located in target/.
sh ./mvnw packageThis will run the tests and create target/jwt-auth-0.0.1-SNAPSHOT.jar.