@@ -27,12 +27,12 @@ A Spring Boot microservice that provides proof-of-work CAPTCHA challenges using
27
27
graph TB
28
28
%% External Client
29
29
Client
30
-
30
+
31
31
%% External Services
32
32
subgraph "External Services"
33
33
PostgreSQL[(PostgreSQL<br/>Database)]
34
34
end
35
-
35
+
36
36
%% Main CaptchaService Application
37
37
subgraph "CaptchaService Application"
38
38
@@ -46,7 +46,7 @@ graph TB
46
46
ChallengeEndpoint["**postChallenge()**<br/>Create CAPTCHA Challenge"]
47
47
VerifyEndpoint["**postVerify()**<br/>Verify CAPTCHA Solution"]
48
48
end
49
-
49
+
50
50
%% Service Layer
51
51
subgraph "Service Layer"
52
52
CaptchaService["**CaptchaService**<br/>Core CAPTCHA Logic"]
@@ -55,63 +55,63 @@ graph TB
55
55
SourceAddressService["**SourceAddressService**<br/>IP Address Validation"]
56
56
ExpiredDataService["**ExpiredDataService**<br/>Cleanup Scheduler"]
57
57
end
58
-
58
+
59
59
%% Data Layer
60
60
subgraph "Data Layer"
61
61
CaptchaRequestRepo["**CaptchaRequestRepository**<br/>JPA Repository"]
62
62
InvalidatedPayloadRepo["**InvalidatedPayloadRepository**<br/>JPA Repository"]
63
-
63
+
64
64
subgraph "JPA Entities"
65
65
CaptchaRequestEntity["**CaptchaRequest**<br/>Entity"]
66
66
InvalidatedPayloadEntity["**InvalidatedPayload**<br/>Entity"]
67
67
end
68
68
end
69
-
69
+
70
70
%% Properties/Configuration
71
71
subgraph "Configuration Properties"
72
72
CaptchaProperties["**CaptchaProperties**<br/>HMAC Key, Sites Config"]
73
73
CaptchaSite["**CaptchaSite**<br/>Site-specific Settings"]
74
74
DifficultyItem["**DifficultyItem**<br/>Difficulty Mappings"]
75
75
end
76
76
end
77
-
77
+
78
78
%% Request Flow
79
79
Client -->|POST /api/v1/challenge| ChallengeEndpoint
80
80
Client -->|POST /api/v1/verify| VerifyEndpoint
81
81
Client --> Monitoring
82
-
82
+
83
83
%% Controller to Services
84
84
ChallengeEndpoint --> CaptchaService
85
85
VerifyEndpoint --> CaptchaService
86
86
ChallengeEndpoint --> SiteAuthService
87
87
VerifyEndpoint --> SiteAuthService
88
88
ChallengeEndpoint --> SourceAddressService
89
-
89
+
90
90
%% Service Interactions
91
91
CaptchaService --> DifficultyService
92
92
CaptchaService --> CaptchaRequestRepo
93
93
CaptchaService --> InvalidatedPayloadRepo
94
94
CaptchaService --> AltchaLib
95
-
95
+
96
96
DifficultyService --> CaptchaRequestRepo
97
97
ExpiredDataService -->|Scheduled Cleanup| CaptchaRequestRepo
98
98
ExpiredDataService -->|Scheduled Cleanup| InvalidatedPayloadRepo
99
-
99
+
100
100
%% Data Layer
101
101
CaptchaRequestRepo --> CaptchaRequestEntity
102
102
InvalidatedPayloadRepo --> InvalidatedPayloadEntity
103
103
CaptchaRequestEntity -.->|JPA/Hibernate| PostgreSQL
104
104
InvalidatedPayloadEntity -.->|JPA/Hibernate| PostgreSQL
105
-
105
+
106
106
%% Configuration Dependencies
107
107
CaptchaService -.->|Uses| CaptchaProperties
108
108
SiteAuthService -.->|Uses| CaptchaProperties
109
109
SourceAddressService -.->|Uses| CaptchaProperties
110
110
DifficultyService -.->|Uses| CaptchaProperties
111
-
111
+
112
112
%% Database Migration
113
113
Flyway -.->|Schema Management| PostgreSQL
114
-
114
+
115
115
class CaptchaService,DifficultyService,SiteAuthService,SourceAddressService,ExpiredDataService service
116
116
class CaptchaRequestRepo,InvalidatedPayloadRepo,CaptchaRequestEntity,InvalidatedPayloadEntity data
117
117
class PostgreSQL,Client external
@@ -139,24 +139,28 @@ graph TB
139
139
## Quick Start
140
140
141
141
1 . ** Clone the repository**
142
+
142
143
``` bash
143
144
git clone https://github.com/it-at-m/captchaservice.git
144
145
cd captchaservice
145
146
```
146
147
147
148
2 . ** Start the development stack**
149
+
148
150
``` bash
149
151
cd stack
150
152
docker compose up -d
151
153
```
152
154
153
155
3 . ** Build and run the application**
156
+
154
157
``` bash
155
158
cd captchaservice-backend
156
159
bash runLocal.sh
157
160
```
158
161
159
162
4 . ** Verify the service is running**
163
+
160
164
``` bash
161
165
curl http://localhost:8080/actuator/health
162
166
```
@@ -165,39 +169,39 @@ graph TB
165
169
166
170
### Environment Variables
167
171
168
- | Variable | Description | Default |
169
- | ----------| -------------| ---------|
170
- | ` SPRING_DATASOURCE_URL ` | PostgreSQL connection URL | ` jdbc:postgresql://localhost:5432/captchaservice ` |
171
- | ` SPRING_DATASOURCE_USERNAME ` | Database username | - |
172
- | ` SPRING_DATASOURCE_PASSWORD ` | Database password | - |
173
- | ` CAPTCHA_HMAC_KEY ` | HMAC key for challenge signing | - |
174
- | ` CAPTCHA_CAPTCHA_TIMEOUT_SECONDS ` | Challenge validity period | ` 300 ` |
175
- | ` CAPTCHA_SOURCE_ADDRESS_WINDOW_SECONDS ` | Source address tracking window | ` 3600 ` |
172
+ | Variable | Description | Default |
173
+ | --------------------------------------- | ------------------------------ | ------------------------------------------------- |
174
+ | ` SPRING_DATASOURCE_URL ` | PostgreSQL connection URL | ` jdbc:postgresql://localhost:5432/captchaservice ` |
175
+ | ` SPRING_DATASOURCE_USERNAME ` | Database username | - |
176
+ | ` SPRING_DATASOURCE_PASSWORD ` | Database password | - |
177
+ | ` CAPTCHA_HMAC_KEY ` | HMAC key for challenge signing | - |
178
+ | ` CAPTCHA_CAPTCHA_TIMEOUT_SECONDS ` | Challenge validity period | ` 300 ` |
179
+ | ` CAPTCHA_SOURCE_ADDRESS_WINDOW_SECONDS ` | Source address tracking window | ` 3600 ` |
176
180
177
181
### Site Configuration
178
182
179
183
Configure multiple sites in your ` application.yml ` :
180
184
181
185
``` yaml
182
186
captcha :
183
- hmac-key : secret # HMAC key for signing challenges
184
- captcha-timeout-seconds : 300 # How long a CAPTCHA challenge is valid
185
- source-address-window-seconds : 3600 # How long a source address is stored
187
+ hmac-key : secret # HMAC key for signing challenges
188
+ captcha-timeout-seconds : 300 # How long a CAPTCHA challenge is valid
189
+ source-address-window-seconds : 3600 # How long a source address is stored
186
190
sites :
187
- site1 : # Site key for site1
188
- site-secret : " secret1" # Site secret for site1
189
- max-verifies-per-payload : 1 # How many times a payload can be verified
191
+ site1 : # Site key for site1
192
+ site-secret : " secret1" # Site secret for site1
193
+ max-verifies-per-payload : 1 # How many times a payload can be verified
190
194
whitelisted_source-addresses :
191
- - " 192.0.2.0/24" # Whitelisted IP address range
195
+ - " 192.0.2.0/24" # Whitelisted IP address range
192
196
site2 :
193
197
site-secret : " secret2"
194
198
whitelisted_source-addresses :
195
- - " 192.0.2.0/24" # Whitelisted IP address range
199
+ - " 192.0.2.0/24" # Whitelisted IP address range
196
200
difficulty-map :
197
- - min-visits : 1 # From the first visit on...
198
- max-number : 1000 # ...the difficulty is 1000
199
- - min-visits : 10 # From the 10th visit on...
200
- max-number : 10000 # ...the difficulty is 10000
201
+ - min-visits : 1 # From the first visit on...
202
+ max-number : 1000 # ...the difficulty is 1000
203
+ - min-visits : 10 # From the 10th visit on...
204
+ max-number : 10000 # ...the difficulty is 10000
201
205
` ` `
202
206
203
207
## API Documentation
@@ -209,6 +213,7 @@ captcha:
209
213
Creates a new CAPTCHA challenge for the specified site.
210
214
211
215
**Request Body:**
216
+
212
217
` ` ` json
213
218
{
214
219
"siteKey": "site1",
@@ -218,6 +223,7 @@ Creates a new CAPTCHA challenge for the specified site.
218
223
` ` `
219
224
220
225
**Response:**
226
+
221
227
` ` ` json
222
228
{
223
229
"algorithm": "SHA-256",
@@ -235,6 +241,7 @@ Creates a new CAPTCHA challenge for the specified site.
235
241
Verifies a CAPTCHA solution payload.
236
242
237
243
**Request Body:**
244
+
238
245
` ` ` json
239
246
{
240
247
"siteKey": "site1",
@@ -251,6 +258,7 @@ Verifies a CAPTCHA solution payload.
251
258
` ` `
252
259
253
260
**Response:**
261
+
254
262
` ` ` json
255
263
{
256
264
"valid": true
@@ -266,14 +274,16 @@ Verifies a CAPTCHA solution payload.
266
274
# ## Error Responses
267
275
268
276
**401 Unauthorized** - Invalid site credentials
277
+
269
278
` ` ` json
270
279
{
271
280
"status": 401,
272
- "error": "Authentication Error",
281
+ "error": "Authentication Error"
273
282
}
274
283
` ` `
275
284
276
285
**400 Bad Request** - Invalid request format
286
+
277
287
` ` ` json
278
288
{
279
289
"status": 400,
@@ -334,4 +344,4 @@ Distributed under the MIT License. See [LICENSE][license] file for more informat
334
344
335
345
# # Contact
336
346
337
-
347
+
0 commit comments