Quick Setup¶
Get the Spring Security Reference Project running on your local machine in just a few minutes.
๐ Prerequisites¶
Before you begin, ensure you have the following installed:
| Tool | Version | Purpose |
|---|---|---|
| Java | 17+ | Runtime environment |
| Maven | 3.6+ | Build and dependency management |
| Git | Latest | Version control |
| IDE | IntelliJ IDEA, Eclipse, or VS Code | Development environment |
Verify Prerequisites¶
# Check Java version
java -version
# Check Maven version
mvn -version
# Check Git version
git --version
๐ Installation¶
1. Clone the Repository¶
2. Build the Project¶
# Clean install all modules
mvn clean install
# Verify build success
echo "Build completed successfully!"
3. Run the Application¶
The application will start on http://localhost:8080
โ Verify Installation¶
Test Public Endpoint¶
Expected response:
Test Authentication¶
# Get JWT token
curl -X POST http://localhost:8080/api/auth/login \
-d "username=admin&password=password"
Expected response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"username": "admin",
"role": "ROLE_ADMIN",
"message": "Login successful - use this JWT token for authenticated requests",
"usage": "Add header: Authorization: Bearer <token>"
}
Test Secured Endpoint¶
# Use the token from previous step
curl -H "Authorization: Bearer <your-jwt-token>" \
http://localhost:8080/api/admin/secure
Expected response:
{
"message": "Hello, Admin! (secured endpoint)",
"user": "admin",
"authorities": ["ROLE_ADMIN"],
"authType": "JWT"
}
๐ง Development Setup¶
IDE Configuration¶
IntelliJ IDEA¶
- Import Project: File โ Open โ Select
pom.xml - Enable Annotation Processing: Settings โ Build โ Compiler โ Annotation Processors
- Set JDK: File โ Project Structure โ Project โ SDK: Java 17+
Eclipse¶
- Import Project: File โ Import โ Existing Maven Projects
- Select Root Directory: Browse to project folder
- Configure JDK: Right-click project โ Properties โ Java Build Path
VS Code¶
- Open Folder: File โ Open Folder โ Select project directory
- Install Extensions:
- Extension Pack for Java
- Spring Boot Extension Pack
- Configure Java: Ctrl+Shift+P โ "Java: Configure Runtime"
Environment Variables¶
Set up optional environment variables for customization:
# Application port (default: 8080)
export SERVER_PORT=8080
# Active profiles (default: default)
export SPRING_PROFILES_ACTIVE=default
# Log level (default: INFO)
export LOGGING_LEVEL_ROOT=INFO
๐งช Testing Setup¶
Run All Tests¶
Module-Specific Testing¶
# Test specific authentication modules
mvn test -pl jdbc-auth
mvn test -pl ldap-auth
mvn test -pl oauth2-auth
HTTP Testing¶
Use the provided api-testing.http file with your IDE's HTTP client:
- IntelliJ IDEA: Open
api-testing.httpโ Click play buttons - VS Code: Install REST Client extension โ Open file โ Send requests
- Postman: Import the collection (export available)
๐ณ Docker Setup (Optional)¶
For containerized development:
Build Docker Image¶
Run with Docker Compose¶
Services Available¶
- Application:
http://localhost:8080 - Database:
localhost:5432(PostgreSQL) - LDAP:
localhost:8389(Embedded)
๐ Application Profiles¶
The application supports multiple profiles for different scenarios:
| Profile | Description | Modules Active |
|---|---|---|
default |
All authentication methods | All modules |
jdbc-only |
Database authentication only | jdbc-auth, common-* |
ldap-only |
LDAP authentication only | ldap-auth, common-* |
oauth2-only |
OAuth2 authentication only | oauth2-auth, common-* |
Activate Specific Profile¶
# JDBC authentication only
mvn spring-boot:run -pl rest-api -Dspring-boot.run.profiles=jdbc-only
# LDAP authentication only
mvn spring-boot:run -pl rest-api -Dspring-boot.run.profiles=ldap-only
๐ Troubleshooting¶
Common Issues¶
Port Already in Use¶
# Find process using port 8080
netstat -ano | findstr :8080 # Windows
lsof -i :8080 # macOS/Linux
# Kill the process or use different port
mvn spring-boot:run -pl rest-api -Dspring-boot.run.arguments=--server.port=8081
Java Version Issues¶
# Set JAVA_HOME
export JAVA_HOME=/path/to/java17 # macOS/Linux
set JAVA_HOME=C:\path\to\java17 # Windows
# Verify Maven uses correct Java
mvn -version
Build Failures¶
Getting Help¶
- ๐ Documentation: Browse the troubleshooting guide
- ๐ Logs: Check application logs for detailed error messages
- ๐ฌ Community: Ask questions in project discussions
๐ Success!¶
You now have the Spring Security Reference Project running locally!
What's Next?¶
- Project Structure โ Explore the codebase organization
- Authentication Methods โ Learn about different auth strategies
- API Testing โ Try out the endpoints
๐ก Pro Tips¶
- Use HTTP files: The
api-testing.httpfile contains all example requests - Check logs: Educational logging explains every security operation
- Try different profiles: Each profile demonstrates specific authentication methods
- Explore modules: Each authentication method is in its own independent module