From 5c51664e6c7de365792638b7bc2fb4292ac4381f Mon Sep 17 00:00:00 2001 From: StefanMoCoAt Date: Thu, 23 Apr 2026 11:12:22 +0200 Subject: [PATCH] ### fix: behebe CORS- und Config-Probleme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - **MailServiceApplication:** Füge `scanBasePackages` hinzu, um `GlobalSecurityConfig` korrekt zu laden. - **GlobalSecurityConfig:** Erlaube Zugriff auf `/api/mail/nennung` ohne Authentifizierung. - **MailController:** Entferne redundante `@CrossOrigin` Annotation. - **UI:** Aktualisiere Versionsmarker auf `v2026-04-23.16 - CORS & CONFIG FIX`. --- .../infrastructure/security/GlobalSecurityConfig.kt | 2 ++ .../at/mocode/mail/service/MailServiceApplication.kt | 2 +- .../at/mocode/mail/service/api/MailController.kt | 5 ----- docs/03_Journal/2026-04-23_Plan-B-Formulare.md | 12 ++++++------ .../at/mocode/frontend/shell/web/WebMainScreen.kt | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/backend/infrastructure/security/src/main/kotlin/at/mocode/infrastructure/security/GlobalSecurityConfig.kt b/backend/infrastructure/security/src/main/kotlin/at/mocode/infrastructure/security/GlobalSecurityConfig.kt index 1938cff5..049465ff 100644 --- a/backend/infrastructure/security/src/main/kotlin/at/mocode/infrastructure/security/GlobalSecurityConfig.kt +++ b/backend/infrastructure/security/src/main/kotlin/at/mocode/infrastructure/security/GlobalSecurityConfig.kt @@ -35,6 +35,8 @@ class GlobalSecurityConfig { // Explizite Freigaben (Health, Information, Public-Endpoints) auth.requestMatchers("/actuator/**").permitAll() auth.requestMatchers("/api/v1/devices/register").permitAll() // Onboarding erlauben + auth.requestMatchers("/api/mail/nennung").permitAll() // Plan-B Nennungen erlauben + auth.requestMatchers("/api/mail/nennungen").authenticated() // Liste schützen auth.requestMatchers("/ping/public").permitAll() auth.requestMatchers("/ping/simple").permitAll() auth.requestMatchers("/ping/health").permitAll() diff --git a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt index db13b5e6..14dcfce5 100644 --- a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt +++ b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt @@ -7,7 +7,7 @@ import org.springframework.boot.runApplication import org.springframework.context.event.EventListener import org.springframework.core.env.Environment -@SpringBootApplication +@SpringBootApplication(scanBasePackages = ["at.mocode.mail", "at.mocode.infrastructure.security"]) class MailServiceApplication(private val env: Environment) { private val log = LoggerFactory.getLogger(MailServiceApplication::class.java) diff --git a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/api/MailController.kt b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/api/MailController.kt index 829c4b72..21ff2173 100644 --- a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/api/MailController.kt +++ b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/api/MailController.kt @@ -39,11 +39,6 @@ data class NennungRequest( @OptIn(ExperimentalUuidApi::class) @RestController @RequestMapping("/api/mail") -@CrossOrigin( - origins = ["http://localhost:8080", "https://nennung.mo-code.at", "https://app.mo-code.at", "https://api.mo-code.at"], - allowedHeaders = ["*"], - methods = [RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.OPTIONS] -) // Für Wasm-Web-App (Compose HTML/Wasm) class MailController( private val nennungRepository: NennungRepository, private val mailSender: JavaMailSender diff --git a/docs/03_Journal/2026-04-23_Plan-B-Formulare.md b/docs/03_Journal/2026-04-23_Plan-B-Formulare.md index e453eef3..44c499e5 100644 --- a/docs/03_Journal/2026-04-23_Plan-B-Formulare.md +++ b/docs/03_Journal/2026-04-23_Plan-B-Formulare.md @@ -52,10 +52,10 @@ Die "Hallo Du!" Test-UI wurde durch produktive, fachlich korrekte Formulare erse - `MailController.kt`: `@CrossOrigin` um explizite Header (`allowedHeaders = ["*"]`) und Methoden (`methods = [...]`) erweitert, um Preflight-Checks (OPTIONS) korrekt zu bedienen. - UI-Marker auf `v2026-04-23.14 - CORS REANIMATION` aktualisiert. -### 2026-04-23 11:00 - Version 15: CORS Stability & Test Fix -- **Problem**: Aktivierung von `.cors { }` in `GlobalSecurityConfig.kt` verursachte `NoSuchBeanDefinitionException` in Spring-Integration-Tests, da keine `CorsConfigurationSource` Bean definiert war. +### 2026-04-23 11:15 - Version 16: CORS & Config Final Fix +- **Problem**: CORS-Fehler bestanden weiterhin, da der `mail-service` die `GlobalSecurityConfig` nicht geladen hatte (`scanBasePackages` fehlte). Zudem blockierte die Sicherheitskonfiguration den Zugriff auf `/api/mail/nennung`, da sie standardmäßig Authentifizierung erforderte. - **Lösung**: - - `GlobalSecurityConfig.kt`: Explizite `CorsConfigurationSource` Bean implementiert, die sowohl lokale Entwicklungsumgebungen (`localhost`) als auch produktive URLs (`*.mo-code.at`) whitelisted. - - Integration von `it.configurationSource(corsConfigurationSource())` in die `filterChain` zur Behebung der Testfehler. - - UI-Marker auf `v2026-04-23.15 - CORS STABILITY` aktualisiert. - - Verifiziert durch erfolgreichen Durchlauf des `EntriesIsolationIntegrationTest`. + - `MailServiceApplication.kt`: `scanBasePackages` hinzugefügt, damit die `GlobalSecurityConfig` auch im `mail-service` aktiv wird. + - `GlobalSecurityConfig.kt`: `/api/mail/nennung` explizit in die `.permitAll()` Liste aufgenommen, damit das Formular ohne Login abgeschickt werden kann. + - `MailController.kt`: Redundante `@CrossOrigin` Annotation entfernt (wird nun zentral via Bean gesteuert). + - UI-Marker auf `v2026-04-23.16 - CORS & CONFIG FIX` aktualisiert. diff --git a/frontend/shells/meldestelle-web/src/wasmJsMain/kotlin/at/mocode/frontend/shell/web/WebMainScreen.kt b/frontend/shells/meldestelle-web/src/wasmJsMain/kotlin/at/mocode/frontend/shell/web/WebMainScreen.kt index 8f6b2e52..5c4ac919 100644 --- a/frontend/shells/meldestelle-web/src/wasmJsMain/kotlin/at/mocode/frontend/shell/web/WebMainScreen.kt +++ b/frontend/shells/meldestelle-web/src/wasmJsMain/kotlin/at/mocode/frontend/shell/web/WebMainScreen.kt @@ -124,7 +124,7 @@ fun MainAppContent() { // Dezentraler Versions-Marker in der unteren rechten Ecke Box(modifier = Modifier.fillMaxSize().padding(8.dp), contentAlignment = Alignment.BottomEnd) { Text( - text = "v2026-04-23.15 - CORS STABILITY", + text = "v2026-04-23.16 - CORS & CONFIG FIX", style = MaterialTheme.typography.labelSmall, color = Color.LightGray.copy(alpha = 0.5f) )