Environment Variables
The Authorization Service requires several environment variables to be configured before deployment. These variables control database connectivity, JWT security, and logging behavior.Required Variables
Database Configuration
America/Lima by default. Modify application.properties if you need a different timezone.
JWT Configuration
- JWT_SECRET: Must be a strong secret key. For HS256 algorithm, use at least 256 bits (32 bytes). Consider using a Base64-encoded random string.
- JWT_EXPIRATION_MS: Token expiration time in milliseconds. Default is 3600000 (1 hour).
Setting Environment Variables
PowerShell (Windows)
Bash (Linux/macOS)
Docker Environment
Application Properties
The service usesapplication.properties for Spring Boot configuration. Key properties include:
Database Settings
JPA/Hibernate Settings
- ddl-auto=update: Automatically updates the database schema. For production, consider using
validateor managing migrations with Flyway/Liquibase. - show-sql=true: Logs SQL statements. Disable in production for better performance.
Logging Configuration
Database Setup
Prerequisites
- PostgreSQL 12 or higher
- Database user with CREATE, ALTER, and SELECT privileges
Initial Setup
- Create the database:
- Create a dedicated user (recommended for production):
- Configure timezone (if needed):
Schema Management
The application uses Hibernate’sddl-auto=update mode, which automatically creates and updates tables based on JPA entities. On first run, the following tables will be created:
users- User accountsroles- User roles (ADMIN, USER, etc.)permissions- Fine-grained permissionsmodules- System modules for permission groupinguser_roles- Many-to-many relationshiprole_permissions- Many-to-many relationshipactivity_logs- Audit trail
Security Configuration
The service implements Spring Security 6 with JWT-based authentication. Key security features:Session Management
The application is stateless and does not use HTTP sessions:Public Endpoints
The following endpoints are publicly accessible:POST /api/users- User registrationPOST /api/auth/**- Authentication endpoints (login, token refresh)/swagger-ui/**- API documentation/v3/api-docs/**- OpenAPI specification
Password Encoding
Passwords are hashed using BCrypt with default strength (10 rounds):Running the Application
Development Mode
Production Build
Verifying Configuration
After starting the service, verify the configuration:- Check application logs for successful database connection
- Access Swagger UI at
http://localhost:8080/swagger-ui.html - Test the health endpoint (if configured)
- Verify JWT token generation by calling
/api/auth/login
Troubleshooting
Database Connection Issues
Problem:Connection refused or Authentication failed
Solution:
- Verify PostgreSQL is running:
pg_isready - Check database credentials in environment variables
- Ensure PostgreSQL accepts connections on port 5432
- Check
pg_hba.conffor authentication settings
JWT Token Issues
Problem:Invalid JWT signature or JWT expired
Solution:
- Verify
JWT_SECRETis set correctly and matches across all service instances - Ensure
JWT_SECRETis at least 256 bits for HS256 algorithm - Check system time synchronization (JWT validation is time-sensitive)
- Adjust
JWT_EXPIRATION_MSif tokens expire too quickly
Schema Update Failures
Problem: Hibernate fails to update schema Solution:- Check database user has ALTER privileges
- Review logs for specific SQL errors
- Consider using
validatemode and manual migrations for production
Performance Tuning
Database Connection Pool
For production deployments, configure HikariCP (default in Spring Boot):JPA Optimization
Next Steps
Security Best Practices
Learn about JWT secrets, password policies, and HTTPS configuration
Error Handling
Understand the error response format and common error scenarios