A Spring Boot application demonstrating the integration of Google reCAPTCHA V3 for secure form submissions with full CRUD employee management functionality.
- Google reCAPTCHA V3 Integration: Seamless bot protection without user interaction
- Full Employee CRUD Operations: Create, Read, Update, and Delete employee records
- Edit Functionality: Update employee information with reCAPTCHA validation
- Delete with Confirmation: SweetAlert2 confirmation dialogs for safe deletions
- Responsive UI: Modern Bootstrap-based interface with smooth animations
- Environment Variables: Secure configuration with .env file support
- MySQL Database: Persistent data storage with JPA/Hibernate
- Docker Compose: Easy database setup and management
- Comprehensive Logging: Debug information for reCAPTCHA validation
- Backend: Spring Boot 3.5.6, Spring Data JPA, Thymeleaf
- Database: MySQL 9.4.0
- Frontend: Bootstrap 5.3.0, Font Awesome 6.0.0, SweetAlert2, JavaScript
- Security: Google reCAPTCHA V3
- Build Tool: Maven
- Containerization: Docker Compose
- Environment Management: spring-dotenv
- Java 17 or higher
- Maven 3.6+
- Docker and Docker Compose
- Google reCAPTCHA V3 Site Key and Secret Key
- Visit Google reCAPTCHA Admin Console
- Create a new site with reCAPTCHA v3
- Note down your Site Key and Secret Key
Create a .env file in the project root:
# Google reCAPTCHA v3 Configuration
GOOGLE_RECAPTCHA_SITE_KEY=YOUR_SITE_KEY_HERE
GOOGLE_RECAPTCHA_SECRET_KEY=YOUR_SECRET_KEY_HEREThe application.properties file references these environment variables:
# Google reCAPTCHA v3 Configuration
google.recaptcha.site.key=${GOOGLE_RECAPTCHA_SITE_KEY}
google.recaptcha.secret.key=${GOOGLE_RECAPTCHA_SECRET_KEY}
google.recaptcha.verify.url=https://www.google.com/recaptcha/api/siteverifyNote: A .env.example file is provided as a template.
docker-compose up -d./mvnw spring-boot:runThe application will be available at http://localhost:8080
src/
├── main/
│ ├── java/id/my/hendisantika/recaptchav3/
│ │ ├── config/
│ │ │ └── ReCaptchaConfig.java # reCAPTCHA configuration
│ │ ├── controller/
│ │ │ └── EmployeeController.java # Web controller
│ │ ├── dto/
│ │ │ └── ReCaptchResponseType.java # reCAPTCHA response DTO
│ │ ├── entity/
│ │ │ └── Employee.java # Employee entity
│ │ ├── repository/
│ │ │ └── EmployeeRepository.java # Data repository
│ │ ├── service/
│ │ │ └── ReCaptchaValidationService.java # reCAPTCHA validation
│ │ └── RecaptchaV3Application.java # Main application
│ └── resources/
│ ├── templates/
│ │ ├── register.html # Registration form
│ │ ├── edit.html # Edit employee form
│ │ └── list.html # Employee list view
│ ├── application.properties # Configuration
│ └── .env # Environment variables (not committed)
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List all employees |
| GET | /register |
Show employee registration form |
| POST | /save |
Save employee with reCAPTCHA validation |
| GET | /edit/{id} |
Show edit form for employee |
| POST | /update |
Update employee with reCAPTCHA validation |
| GET | /delete/{id} |
Delete employee by ID |
- Automatically generates reCAPTCHA token on form submission
- Comprehensive validation and error handling
- Debug logging for troubleshooting
- Validates reCAPTCHA token with Google API
- Configurable score threshold (currently 0.3)
- Detailed logging for debugging
- Graceful error handling
The application uses MySQL with the following default configuration:
spring.datasource.url=jdbc:mysql://localhost:3309/recaptcha_db
spring.datasource.username=yu71
spring.datasource.password=53cretDatabase schema is auto-created via Hibernate DDL.
Note: The database port is 3309 to match the Docker Compose mapping.
The project includes test scripts:
test_employee_add.sh- Test employee additiontest_recaptcha_verification.sh- Test reCAPTCHA verificationfinal_verification.sh- Complete verification
chmod +x test_employee_add.sh
./test_employee_add.sh-
reCAPTCHA Token is null
- Check browser console for JavaScript errors
- Verify Site Key is correctly configured
- Ensure reCAPTCHA script is loaded
-
reCAPTCHA Validation Failed
- Verify Secret Key is correct
- Check network connectivity to Google API
- Review server logs for detailed error messages
-
Database Connection Issues
- Ensure Docker containers are running
- Check database credentials in application.properties
- Verify port 3309 is not in use by other applications
-
Environment Variables Not Loaded
- Ensure
.envfile exists in project root - Verify
spring-dotenvdependency is included - Check that environment variable names match exactly
- Ensure
The application includes comprehensive debug logging:
DEBUG: Received reCAPTCHA token: [token]
DEBUG: Validating reCAPTCHA with Google...
DEBUG: reCAPTCHA Response - Success: true, Score: 0.9, Action: submit
Empty state with call-to-action to add first employee
Employee directory showing all records with Edit and Delete actions
Total employee count and management options
Complete employee list with action buttons
Registration form with reCAPTCHA V3 protection
Edit form pre-filled with employee data
Success message after updating employee
Edit page with View All and Cancel buttons
SweetAlert2 confirmation dialog before deletion
- reCAPTCHA V3 uses behavioral analysis instead of challenges
- Score threshold is configurable (currently set to 0.3 for better UX)
- All form submissions (add/edit) are validated server-side
- Environment variables stored in
.env(excluded from git) - Delete operations require user confirmation via SweetAlert2
- Thymeleaf security: Uses
data-*attributes instead of inline event handlers
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is open source and available under the MIT License.
Hendi Santika
- Email: hendisantika@gmail.com
- Telegram: @hendisantika34
- GitHub: hendisantika
Built with ❤️ using Spring Boot and Google reCAPTCHA V3