A modern full-stack application demonstrating secure WebSocket communication with token-based authentication using Spring Boot 3.4 and Angular 19.
This application implements a complete token-based security model for both REST API and WebSocket connections:
- JWT Token Authentication - Stateless, token-based auth
- X-AUTH-TOKEN Header - Custom header for token transport
- BCrypt Password Encoding - Secure password storage
- CORS Configuration - Controlled cross-origin access
- Token Validation on CONNECT -
WebSocketTokenInterceptorvalidates JWT tokens passed in STOMP headers - Message-Level Security - CONNECT, MESSAGE, SUBSCRIBE require authentication
- SecurityContext Integration - Authenticated user available in WebSocket handlers
- User-Specific Subscriptions - Secure per-user notification channels
βββββββββββββββββββ HTTP + WebSocket βββββββββββββββββββββββ
β β βββββββββββββββββββββ> β β
β Angular 19 β X-AUTH-TOKEN β Spring Boot 3.4 β
β Frontend β <βββββββββββββββββββββ β Backend β
β β β β
βββββββββββββββββββ βββββββββββββββββββββββ
β β
β STOMP over SockJS β
β X-AUTH-TOKEN in headers β
ββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Version |
|---|---|
| Java | 21 LTS |
| Spring Boot | 3.4.1 |
| Spring Security | 6.4.x |
| Angular | 19.x |
| Node.js | 20+ LTS |
| JWT (jjwt) | 0.12.6 |
| H2 Database | In-memory |
- Java 21+
- Node.js 20+
- Maven 3.9+
cd backend
mvn spring-boot:runThe backend will start on http://localhost:8080
cd frontend
npm install
npm startThe frontend will start on http://localhost:4200 with proxy to backend.
- Email:
user@example.com - Password:
password
- Client sends
POST /api/authentication/loginwithAuthorization: Basic <base64>header - Server validates credentials against database (BCrypt)
- Server generates JWT token signed with HMAC-SHA256
- Server returns token in
X-AUTH-TOKENresponse header - Client stores token in sessionStorage
- All subsequent requests include
X-AUTH-TOKENheader
- Client connects to
/stompendpoint via SockJS - STOMP CONNECT frame includes
X-AUTH-TOKENin headers WebSocketTokenInterceptorextracts and validates token- If valid, sets
AuthenticationinSecurityContext - Subscription requests are authorized against configured rules
- Only authenticated users can subscribe to
/user/notifications
| Class | Purpose |
|---|---|
JwtTokenProvider |
Creates and validates JWT tokens |
JwtAuthenticationFilter |
Validates tokens on HTTP requests |
WebSocketTokenInterceptor |
Validates tokens on WebSocket CONNECT |
WebSocketSecurityConfig |
Configures message-level security rules |
SecurityConfig |
Main Spring Security configuration |
βββ backend/ # Spring Boot application
β βββ src/main/java/au/com/example/
β β βββ config/ # Configuration classes
β β βββ controller/ # REST and WebSocket controllers
β β βββ model/ # JPA entities
β β βββ repository/ # Spring Data repositories
β β βββ security/ # Security components
β βββ src/main/resources/
β βββ application.yml # Application configuration
β βββ data.sql # Initial data
β
βββ frontend/ # Angular application
β βββ src/app/
β βββ core/
β β βββ auth/ # Authentication service & guard
β β βββ interceptors/ # HTTP interceptor
β β βββ websocket/ # WebSocket service
β βββ features/ # Feature components
β
βββ (legacy modules) # Original AngularJS code (deprecated)
cd backend
mvn testcd frontend
npm run buildPOST /api/authentication/login- Login with Basic AuthPOST /api/authentication/logout- Logout
GET /api/user- Get current user details
GET /api/customers- List all customersGET /api/customers/search?query=- Search customersPOST /api/customers- Create customerPUT /api/customers/{id}- Update customerDELETE /api/customers/{id}- Delete customer
CONNECT /stomp- WebSocket endpoint (SockJS)SUBSCRIBE /user/notifications- User notifications (requires auth)
This is a complete rewrite of the original AngularJS + Spring 4 application:
| Original | Modernized |
|---|---|
| AngularJS 1.4 | Angular 19 |
| Spring 4 + Spring Security 4 | Spring Boot 3.4 + Spring Security 6 |
| Gulp 3 | Angular CLI |
| Custom HMAC tokens | JWT (jjwt) |
| WAR deployment | Embedded Tomcat JAR |
| javax.* APIs | jakarta.* APIs |
- β Token-based stateless authentication
- β X-AUTH-TOKEN header convention
- β WebSocket token validation on CONNECT
- β Message-level security for STOMP
- β Per-user notification subscriptions
MIT License