|
|
1 månad sedan | |
|---|---|---|
| docker | 2 månader sedan | |
| eurekaServer | 2 månader sedan | |
| front | 2 månader sedan | |
| keycloak-spi | 2 månader sedan | |
| keycloak-theme | 2 månader sedan | |
| notifi-service | 2 månader sedan | |
| order-service | 2 månader sedan | |
| payment-service | 2 månader sedan | |
| springGateway | 2 månader sedan | |
| userService | 2 månader sedan | |
| .gitattributes | 2 månader sedan | |
| .gitignore | 2 månader sedan | |
| BoatDelivery - Prezentacja.pdf | 1 månad sedan | |
| BoatDelivery - raport.pdf | 1 månad sedan | |
| README.md | 2 månader sedan | |
| docker-compose.yml | 2 månader sedan |
git clone https://github.com/TomaszKK/BoatDelivery.git
cd BoatDelivery
docker-compose up -d
Usługi uruchomią się na portach:
| Usługa | Port | URL |
|---|---|---|
| PostgreSQL | 5432 | jdbc:postgresql://localhost:5432/user_service_db |
| Keycloak | 8060 | http://localhost:8060 |
| Eureka | 8761 | http://localhost:8761/eureka/ |
| Gateway | 8080 | http://localhost:8080 |
| User-Service | 8081 | http://localhost:8081 |
| Order-Service | 8082 | http://localhost:8082 |
cd eurekaServer
mvn spring-boot:run
cd userService
mvn spring-boot:run
cd order-service
mvn quarkus:dev
cd springGateway
mvn spring-boot:run
cd front
npm install
npm run dev
# Sprawdź zarejestrowane serwisy
curl http://localhost:8761/eureka/apps
# Sprawdzenie Keycloaka
curl http://localhost:8060/realms/boat-delivery-realm/.well-known/openid-configuration
# Test Gateway
curl http://localhost:8080/api/user
http://localhost:8060http://localhost:8060/adminadminadminboat-delivery-realmKonfiguracja jest automatycznie importowana z pliku:
docker/keycloak/imports/boat-delivery-realm-realm.json
auth-gatewayV5JXUTu8QVsXcRfo6jEdw5qbyjLltI6Khttp://localhost:8080/login/oauth2/code/keycloakhttp://localhost:8080/oauth2/authorization/keycloakopenid profile email phoneRola: Tworzy sesję OAuth2 dla użytkownika
Nowe serwisy NIE tworza sesji. Zamiast tego walidują JWT otrzymany od Gateway'a.
Tworzenie nowego client'a:
http://localhost:8060/admin → Realm boat-delivery-realmnew-serviceSystem waliduje następujące pola:
| Pole | Wymagane | Typ | Walidacja |
|---|---|---|---|
username |
✅ | String | *Unikalny, 3-50 znaków |
email |
✅ | String | Unikalny, format email |
firstName |
✅ | String | *2-100 znaków |
lastName |
✅ | String | *2-100 znaków |
phone |
✅* | String | +48XXXXXXXXX (9 cyfr), Unikalny |
password |
✅ | String | *Min 8 znaków, kompleksowy (rekomendacja) |
*do zrobienia
Keycloak jest skonfigurowany do dodawania w JWT następujących claim'ów:
{
"sub": "3f550330-d932-4547-8946-6a67f0fef0d1",
"email": "user@example.com",
"given_name": "John",
"family_name": "Doe",
"phone_number": "+48511404354",
"preferred_username": "johndoe",
"email_verified": true,
"realm_access": {
"roles": ["CUSTOMER", "COURIER", "ADMIN"]
}
}
1. Frontend wysyła credentials
↓
2. Keycloak waliduje i wydaje JWT
↓
3. Frontend wysyła JWT do Gateway'a
↓
4. Gateway waliduje JWT i przekazuje do serwisu
↓
5. Serwis waliduje JWK (public key z Keycloaka)
↓
6. Serwis przetwarza request
Feature flags są kontrolowane przez property app.security.enabled w każdym serwisie:
application.properties)app.security.enabled=false # Disable JWT validation (DEV mode)
application.yml)app:
security:
enabled: false # Disable OAuth2 (DEV mode)
app.security.enabled=false
app.security.enabled=true
@Configuration
@ConditionalOnProperty(name = "app.security.enabled", havingValue = "true")
public class SecurityConfig {
// JWT validation configuration
}
@Configuration
@ConditionalOnProperty(name = "app.security.enabled", havingValue = "true")
public class OAuth2Config {
// OAuth2 configuration
}
Authorization: Bearer <token>pom.xml<!-- OAuth2 Resource Server -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<!-- Eureka Client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
application.properties# Server
server.port=8083
spring.application.name=new-service
# Feature Flag
app.security.enabled=true
# Eureka
eureka.client.service-url.defaultZone=http://127.0.0.1:8761/eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.prefer-ip-address=true
# Security - JWT Validation
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8060/realms/boat-delivery-realm/protocol/openid-connect/certs
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8060/realms/boat-delivery-realm
# Logging
logging.level.org.springframework.security=DEBUG
logging.level.your.package=DEBUG
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authz -> authz
.requestMatchers("/health", "/metrics").permitAll()
.anyRequest().authenticated()
)
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(jwt -> jwt
.decoder(jwtDecoder())
)
)
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS) // ← WAŻNE!
);
return http.build();
}
@Bean
public JwtDecoder jwtDecoder() {
return JwtDecoders.fromIssuerLocation("http://localhost:8060/realms/boat-delivery-realm");
}
}
W Keycloak Admin Console:
new-serviceapplication.yml)spring:
cloud:
gateway:
routes:
- id: new-service-route
uri: lb://new-service
predicates:
- Path=/api/new-service/**
@SpringBootApplication
@EnableDiscoveryClient
public class NewServiceApplication {
static void main(String[] args) {
SpringApplication.run(NewServiceApplication.class, args);
}
}
| Komponenta | Wersja | Opis |
|---|---|---|
| Java | 21 | JDK |
| Spring Boot | 4.0.3 | Framework |
| Spring Cloud | 2025.1 | Microservices (Gateway, Eureka) |
| Spring Security | 6.x | OAuth2 Resource Server |
| Quarkus | Latest | Order Service (reactive) |
| PostgreSQL | 17 | Database |
| Keycloak | 26.5.6 | Identity & Access Management |
| MapStruct | 1.5.5 | Entity-DTO mapping |
| Lombok | Latest | Boilerplate reduction |
| Flyway | 9.x | Database migrations |
| Komponenta | Wersja | Opis |
|---|---|---|
| React | 18+ | UI Framework |
| Vite | 5+ | Build tool |
| TypeScript | 5+ | Type safety |
| TailwindCSS | Latest | Styling |
| i18n | Latest | Internationalization |
| Komponenta | Wersja | Opis |
|---|---|---|
| Docker | Latest | Containerization |
| Docker Compose | Latest | Orchestration |
| Maven | 3.8+ | Build tool |