A comprehensive enterprise-grade authentication application built with Spring Boot and Angular, supporting multiple authentication methods including JWT, Basic Auth, LDAP, and Keycloak SSO.
- JWT Authentication: Stateless token-based authentication
- Basic Authentication: Simple username/password authentication
- LDAP Integration: Enterprise directory integration (configurable)
- Keycloak SSO: Single Sign-On integration (configurable)
- Multi-factor Authentication Ready: Extensible architecture for MFA
- Role-Based Access Control (RBAC): Dynamic role and privilege system
- Fraud Detection: Real-time monitoring of login attempts
- IP-based tracking
- Failed login attempt monitoring
- Automatic account locking
- Risk score calculation
- Suspicious activity detection
- Security Best Practices:
- CSRF protection
- CORS configuration
- Secure password hashing (BCrypt)
- JWT token expiration
- Security headers
- Audit logging
- Modern responsive design using Bootstrap 5 and Tabler
- Clean and intuitive user interface
- Dashboard with user profile and authentication status
- Multi-auth method selector
- Java 17 or higher
- Maven 3.6+
- (Optional) PostgreSQL for production
- (Optional) LDAP server for LDAP authentication
- (Optional) Keycloak server for SSO
- Node.js 18+ and npm 9+
- Angular CLI 19
- Navigate to the backend directory:
cd backend-
Configure the database and authentication methods in
src/main/resources/application.properties:- For development, H2 in-memory database is pre-configured
- For production, configure PostgreSQL or your preferred database
- Enable LDAP by setting
app.ldap.enabled=trueand configuring LDAP properties - Enable Keycloak by setting
keycloak.enabled=trueand configuring Keycloak properties
-
Build the project:
mvn clean install- Run the application:
mvn spring-boot:runThe backend will start on http://localhost:8080
The application comes with pre-configured users:
| Username | Password | Role | Description |
|---|---|---|---|
| admin | admin123 | ADMIN | Full access |
| user | user123 | USER | Limited access |
- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install- Run the development server:
npm startThe frontend will start on http://localhost:4200
- For production build:
npm run buildEdit backend/src/main/resources/application.properties:
# JWT secret key (change in production!)
app.jwt.secret=your-secret-key-here
# JWT expiration time in milliseconds (24 hours)
app.jwt.expiration=86400000app.ldap.enabled=true
spring.ldap.urls=ldap://your-ldap-server:389
spring.ldap.base=dc=example,dc=com
spring.ldap.username=cn=admin,dc=example,dc=com
spring.ldap.password=your-password
spring.ldap.user-dn-pattern=uid={0},ou=peoplekeycloak.enabled=true
keycloak.realm=your-realm
keycloak.auth-server-url=http://your-keycloak-server:8180/auth
keycloak.resource=your-client-id
keycloak.credentials.secret=your-client-secret# Maximum failed login attempts before locking account
app.security.max-failed-attempts=5
# Account lockout duration in minutes
app.security.lockout-duration-minutes=30
# Time window for fraud detection in minutes
app.security.fraud-detection-window-minutes=60backend/
βββ src/main/java/com/authapp/
β βββ config/ # Configuration classes
β β βββ SecurityConfig.java
β β βββ DataInitializer.java
β βββ controller/ # REST controllers
β β βββ AuthController.java
β βββ dto/ # Data Transfer Objects
β βββ model/ # JPA entities
β β βββ User.java
β β βββ Role.java
β β βββ Privilege.java
β β βββ LoginAttempt.java
β βββ repository/ # Data repositories
β βββ security/ # Security implementations
β β βββ auth/ # Authentication strategies
β β β βββ AuthenticationStrategy.java
β β β βββ BasicAuthenticationStrategy.java
β β β βββ JwtAuthenticationStrategy.java
β β β βββ LdapAuthenticationStrategy.java
β β βββ jwt/ # JWT utilities
β βββ service/ # Business logic
β βββ AuthenticationService.java
β βββ FraudDetectionService.java
β βββ UserDetailsServiceImpl.java
frontend/src/app/
βββ components/
β βββ login/ # Login component
β βββ register/ # Registration component
β βββ dashboard/ # User dashboard
β βββ navbar/ # Navigation bar
βββ services/
β βββ auth.service.ts # Authentication service
β βββ auth.interceptor.ts # HTTP interceptor
βββ guards/
β βββ auth.guard.ts # Route guard
βββ models/
βββ auth.model.ts # TypeScript interfaces
-
POST /api/auth/login- User login{ "username": "user", "password": "password", "authMethod": "JWT|BASIC|LDAP|KEYCLOAK" } -
POST /api/auth/register- User registration{ "username": "newuser", "password": "password", "email": "user@example.com", "fullName": "John Doe" } -
POST /api/auth/logout- User logout
cd backend
mvn testcd frontend
npm test- Build the JAR file:
cd backend
mvn clean package- Run the JAR:
java -jar target/authapp-backend-1.0.0.jar- Build for production:
cd frontend
npm run build- Deploy the
dist/frontenddirectory to your web server (nginx, Apache, etc.)
Create Dockerfile in backend directory:
FROM openjdk:17-jdk-slim
COPY target/authapp-backend-1.0.0.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]Create Dockerfile in frontend directory:
FROM node:18 as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/dist/frontend /usr/share/nginx/html- Change Default Credentials: Always change default admin credentials in production
- Use Strong JWT Secret: Generate a strong secret key for JWT signing
- Enable HTTPS: Always use HTTPS in production
- Database Security: Use strong database passwords and limit access
- Regular Updates: Keep all dependencies up to date
- Monitor Logs: Regularly check security audit logs
- Rate Limiting: Consider adding API rate limiting for production
The application logs important security events:
- Login attempts (successful and failed)
- Account locks
- Suspicious activities
- Authentication method changes
Logs can be configured in application.properties:
logging.level.com.authapp=DEBUG
logging.level.org.springframework.security=DEBUG- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Create an issue in the GitHub repository
- Check the documentation
- Review the API endpoints
- Multi-factor authentication (MFA)
- OAuth2 integration (Google, GitHub, etc.)
- Password reset functionality
- Email verification
- Session management dashboard
- Advanced fraud detection with machine learning
- API rate limiting
- Comprehensive audit trail
- User activity monitoring
- Admin panel for user management
- Spring Boot 3.2.1
- Spring Security
- Spring Data JPA
- JWT (JJWT 0.12.3)
- Keycloak 23.0.3
- H2/PostgreSQL
- Lombok
- Maven
- Angular 19
- TypeScript
- Bootstrap 5
- Tabler UI
- RxJS
- HttpClient