Skip to content

Commit da9555d

Browse files
committed
docs(gdpr): add GDPR documentation and disable by default
- Change user.gdpr.enabled default to false for backward compatibility - Add GDPR features to README.md Features list - Add comprehensive GDPR Compliance section to README.md with: - Configuration instructions - Data export (Right of Access) documentation - Account deletion (Right to be Forgotten) documentation - Consent management API documentation - GdprDataContributor extensibility guide - GDPR events reference - Add GDPR configuration section to CONFIG.md - Add user.audit.maxQueryResults to CONFIG.md
1 parent fd6dda4 commit da9555d

3 files changed

Lines changed: 212 additions & 1 deletion

File tree

CONFIG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ Welcome to the User Framework SpringBoot Configuration Guide! This document outl
3838

3939
- **Log File Path (`user.audit.logFilePath`)**: The path to the audit log file.
4040
- **Flush on Write (`user.audit.flushOnWrite`)**: Set to `true` for immediate log flushing. Defaults to `false` for performance.
41+
- **Max Query Results (`user.audit.maxQueryResults`)**: Maximum number of audit events returned from queries. Prevents memory issues with large logs. Defaults to `10000`.
42+
43+
## GDPR Compliance
44+
45+
GDPR features are disabled by default and must be explicitly enabled.
46+
47+
- **Enable GDPR (`user.gdpr.enabled`)**: Master toggle for all GDPR features. When `false`, all GDPR endpoints return 404. Defaults to `false`.
48+
- **Export Before Deletion (`user.gdpr.exportBeforeDeletion`)**: When `true`, user data is automatically exported and included in the deletion response. Defaults to `true`.
49+
- **Consent Tracking (`user.gdpr.consentTracking`)**: Enable consent grant/withdrawal tracking via the audit system. Defaults to `true`.
50+
51+
**Example configuration:**
52+
```yaml
53+
user:
54+
gdpr:
55+
enabled: true
56+
exportBeforeDeletion: true
57+
consentTracking: true
58+
```
59+
60+
**Note**: When GDPR is enabled, ensure you have a `UserPreDeleteEvent` listener configured to clean up application-specific user data before deletion. See the README for details.
4161

4262
## Security Settings
4363

README.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ Check out the [Spring User Framework Demo Application](https://github.com/devond
5151
- [Handling User Account Deletion and Profile Cleanup](#handling-user-account-deletion-and-profile-cleanup)
5252
- [Enabling Actual Deletion](#enabling-actual-deletion)
5353
- [SSO OAuth2 with Google and Facebook](#sso-oauth2-with-google-and-facebook)
54+
- [GDPR Compliance](#gdpr-compliance)
55+
- [Enabling GDPR Features](#enabling-gdpr-features)
56+
- [Data Export (Right of Access)](#data-export-right-of-access)
57+
- [Account Deletion (Right to be Forgotten)](#account-deletion-right-to-be-forgotten)
58+
- [Consent Management](#consent-management)
59+
- [Extending GDPR Exports](#extending-gdpr-exports)
60+
- [GDPR Events](#gdpr-events)
5461
- [Examples](#examples)
5562
- [Contributing](#contributing)
5663
- [Reference Documentation](#reference-documentation)
@@ -92,6 +99,13 @@ Check out the [Spring User Framework Demo Application](https://github.com/devond
9299
- Comprehensive documentation
93100
- Demo application for reference
94101

102+
- **GDPR Compliance** (opt-in)
103+
- Data export (Right of Access - Article 15)
104+
- Account deletion (Right to be Forgotten - Article 17)
105+
- Consent tracking and management (Article 7)
106+
- Extensible data contributor system for custom data
107+
- Audit trail for all GDPR operations
108+
95109
## Installation
96110

97111
Choose the version that matches your Spring Boot version:
@@ -747,6 +761,182 @@ By implementing such a listener, your application ensures data integrity when th
747761
The framework supports SSO OAuth2 with Google, Facebook and Keycloak. To enable this you need to configure the client id and secret for each provider. This is done in the application.yml (or application.properties) file using the [Spring Security OAuth2 properties](https://docs.spring.io/spring-security/reference/servlet/oauth2/login/core.html). You can see the example configuration in the Demo Project's `application.yml` file.
748762

749763

764+
## GDPR Compliance
765+
766+
The framework provides opt-in GDPR compliance features to help your application meet European data protection requirements. These features are **disabled by default** and must be explicitly enabled.
767+
768+
### Enabling GDPR Features
769+
770+
Add the following to your `application.yml`:
771+
772+
```yaml
773+
user:
774+
gdpr:
775+
enabled: true # Master toggle for all GDPR features
776+
exportBeforeDeletion: true # Automatically export data before deletion
777+
consentTracking: true # Enable consent grant/withdrawal tracking
778+
```
779+
780+
When enabled, the following REST endpoints become available (all require authentication):
781+
782+
| Endpoint | Method | Description |
783+
|----------|--------|-------------|
784+
| `/user/gdpr/export` | GET | Export all user data as JSON |
785+
| `/user/gdpr/delete` | POST | Request account deletion |
786+
| `/user/gdpr/consent` | POST | Record consent grant or withdrawal |
787+
| `/user/gdpr/consent/status` | GET | Get current consent status |
788+
789+
### Data Export (Right of Access)
790+
791+
Users can request a complete export of their data via the `/user/gdpr/export` endpoint. The export includes:
792+
793+
- **User account data**: Name, email, registration date, roles
794+
- **Audit history**: Login events, password changes, profile updates
795+
- **Consent records**: All consent grants and withdrawals with timestamps
796+
- **Token metadata**: Verification and password reset token expiry (not actual tokens)
797+
- **Custom data**: Any data contributed by registered `GdprDataContributor` beans
798+
799+
**Example Response:**
800+
```json
801+
{
802+
"success": true,
803+
"data": {
804+
"exportedAt": "2024-01-15T10:30:00Z",
805+
"user": {
806+
"id": 123,
807+
"email": "user@example.com",
808+
"firstName": "John",
809+
"lastName": "Doe",
810+
"createdDate": "2023-06-01T08:00:00Z",
811+
"roles": ["ROLE_USER"]
812+
},
813+
"auditHistory": [...],
814+
"consents": [...],
815+
"customData": {}
816+
}
817+
}
818+
```
819+
820+
### Account Deletion (Right to be Forgotten)
821+
822+
Users can request complete deletion of their account via the `/user/gdpr/delete` endpoint. The deletion process:
823+
824+
1. **Exports data** (if `exportBeforeDeletion=true`) and includes it in the response
825+
2. **Notifies contributors** via `GdprDataContributor.prepareForDeletion()`
826+
3. **Publishes `UserPreDeleteEvent`** for custom cleanup listeners
827+
4. **Deletes framework data**: Verification tokens, password reset tokens, password history
828+
5. **Deletes user entity** from database
829+
6. **Publishes `UserDeletedEvent`** for post-deletion processing
830+
7. **Invalidates all sessions** across all devices
831+
8. **Logs out** the current session
832+
833+
**Important**: This performs a hard delete. Ensure you have the `UserPreDeleteEvent` listener configured (see [Handling User Account Deletion](#handling-user-account-deletion-and-profile-cleanup)) to clean up related data.
834+
835+
### Consent Management
836+
837+
Track user consent for various purposes (marketing, analytics, data processing, etc.):
838+
839+
**Recording Consent:**
840+
```bash
841+
# Grant consent
842+
curl -X POST /user/gdpr/consent \
843+
-H "Content-Type: application/json" \
844+
-d '{"consentType": "MARKETING", "granted": true}'
845+
846+
# Withdraw consent
847+
curl -X POST /user/gdpr/consent \
848+
-H "Content-Type: application/json" \
849+
-d '{"consentType": "MARKETING", "granted": false}'
850+
851+
# Custom consent type
852+
curl -X POST /user/gdpr/consent \
853+
-H "Content-Type: application/json" \
854+
-d '{"consentType": "CUSTOM", "customType": "newsletter_weekly", "granted": true}'
855+
```
856+
857+
**Built-in Consent Types:**
858+
- `MARKETING` - Marketing communications
859+
- `ANALYTICS` - Analytics and tracking
860+
- `THIRD_PARTY` - Third-party data sharing
861+
- `PROFILING` - User profiling
862+
- `CUSTOM` - Application-specific (requires `customType` field)
863+
864+
**Checking Consent Status:**
865+
```bash
866+
curl /user/gdpr/consent/status?type=MARKETING
867+
```
868+
869+
All consent changes are recorded in the audit log with timestamps, IP addresses, and user agent information.
870+
871+
### Extending GDPR Exports
872+
873+
To include your application's custom data in GDPR exports, implement the `GdprDataContributor` interface:
874+
875+
```java
876+
@Component
877+
public class OrderDataContributor implements GdprDataContributor {
878+
879+
private final OrderRepository orderRepository;
880+
881+
public OrderDataContributor(OrderRepository orderRepository) {
882+
this.orderRepository = orderRepository;
883+
}
884+
885+
@Override
886+
public String getDataKey() {
887+
return "orders"; // Key in the export JSON
888+
}
889+
890+
@Override
891+
public Object contributeData(User user) {
892+
// Return data to include in export (will be serialized to JSON)
893+
return orderRepository.findByUserId(user.getId())
894+
.stream()
895+
.map(this::toExportDto)
896+
.toList();
897+
}
898+
899+
@Override
900+
public void prepareForDeletion(User user) {
901+
// Clean up data before user deletion (runs within transaction)
902+
// WARNING: Only delete LOCAL database data here, not external APIs
903+
orderRepository.deleteByUserId(user.getId());
904+
}
905+
906+
private OrderExportDto toExportDto(Order order) {
907+
// Map to DTO for export
908+
}
909+
}
910+
```
911+
912+
**Important**: The `prepareForDeletion()` method runs within the same database transaction as user deletion. Only perform local database operations here. For external API cleanup, use a `UserDeletedEvent` listener instead.
913+
914+
### GDPR Events
915+
916+
The framework publishes Spring events for GDPR operations:
917+
918+
| Event | When Published | Use Case |
919+
|-------|----------------|----------|
920+
| `UserPreDeleteEvent` | Before user deletion (in transaction) | Clean up related database records |
921+
| `UserDeletedEvent` | After successful deletion | External API cleanup, notifications |
922+
| `UserDataExportedEvent` | After data export | Audit logging, analytics |
923+
| `ConsentChangedEvent` | After consent grant/withdrawal | Trigger consent-dependent workflows |
924+
925+
**Example: External Cleanup After Deletion**
926+
```java
927+
@Component
928+
public class ExternalCleanupListener {
929+
930+
@EventListener
931+
@Async // Run asynchronously after transaction commits
932+
public void onUserDeleted(UserDeletedEvent event) {
933+
// Safe to call external APIs here
934+
externalCrmService.deleteCustomer(event.getUserEmail());
935+
analyticsService.anonymizeUser(event.getUserId());
936+
}
937+
}
938+
```
939+
750940
## Examples
751941

752942
For complete working examples, check out the [Spring User Framework Demo Application](https://github.com/devondragon/SpringUserFrameworkDemoApp).

src/main/resources/config/dsspringuserconfig.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ user.roles.role-hierarchy[1]=ROLE_MANAGER > ROLE_USER
160160

161161
# GDPR Configuration
162162
# Master toggle for GDPR features (export, deletion, consent tracking)
163-
user.gdpr.enabled=true
163+
# Disabled by default - enable explicitly to activate GDPR endpoints
164+
user.gdpr.enabled=false
164165
# If true, user data is automatically exported before hard deletion
165166
user.gdpr.exportBeforeDeletion=true
166167
# If true, consent changes are tracked via the audit system

0 commit comments

Comments
 (0)