main_java

🔧 JWT Authorization Troubleshooting

❌ PROBLEM: Unauthorized (403) beim ersten Request

Symptome

Server (Liberty):

jakarta.ws.rs.ForbiddenException: Unauthorized
at io.openliberty.restfulWS30.appSecurity.LibertyAuthFilter.handleMessage

Client:

de.ruu.lib.ws.rs.TechnicalException: failed to retrieve task groups: 
{"message":"INTERNAL_ERROR","cause":"Unauthorized","httpStatus":"INTERNAL_SERVER_ERROR"}

🔍 DIAGNOSE-SCHRITTE

1. PrĂŒfe: LĂ€uft automatisches Login?

Im DashAppRunner Log suchen:

✅ Automatic login successful
Access token (first 50 chars): eyJhbGciOi...

Wenn NICHT vorhanden:


2. PrĂŒfe: Wird Authorization Header gesendet?

Im DashAppRunner Log suchen:

=== AuthorizationHeaderFilter called ===
  isLoggedIn(): true
  Token present: true
  ✅ Authorization header added

Wenn “isLoggedIn(): false”:

Wenn “Token present: false”:


3. PrĂŒfe: Hat Liberty das groupNameAttribute?

Command:

cd ~/develop/github/java/main/root/app/jeeeraaah/backend/api/ws_rs
grep "groupNameAttribute" target/liberty/wlp/usr/servers/defaultServer/server.xml

Erwartete Ausgabe:

groupNameAttribute="realm_access/roles">

Wenn NICHT vorhanden:


4. PrĂŒfe: Hat Liberty die Config neu geladen?

In Liberty Logs suchen:

CWWKG0017I: The server configuration was successfully updated

Wenn NICHT vorhanden:

# Force reload
cd ~/develop/github/java/main/root/app/jeeeraaah/backend/api/ws_rs
touch src/main/liberty/config/server.xml

# Warte 10 Sekunden, dann nochmal prĂŒfen

✅ LÖSUNG: VollstĂ€ndiger Fix-Ablauf

Schritt 1: Liberty Config aktualisieren

cd ~/develop/github/java/main/root/app/jeeeraaah/backend/api/ws_rs

# Trigger Config Reload
touch src/main/liberty/config/server.xml

# Warte auf Log-Meldung
# → "CWWKG0017I: The server configuration was successfully updated"

Schritt 2: Frontend neu starten

# In IntelliJ:
# 1. Stoppe DashAppRunner
# 2. Starte DashAppRunner neu
# 3. PrĂŒfe Logs:
#    ✅ Automatic login successful
#    ✅ Authorization header added

Schritt 3: Ersten Request testen

Erwartete Client-Logs:

=== AuthorizationHeaderFilter called ===
  Request: GET http://localhost:9080/jeeeraaah/taskgroup/allFlat
  isLoggedIn(): true
  Token present: true
  Token length: 1386
  ✅ Authorization header added

Erwartete Server-Logs:

✅ KEIN "Unauthorized" Fehler mehr
✅ Request wird verarbeitet
✅ Response: 200 OK

🐛 HÄUFIGE PROBLEME

Problem 1: Token wird nicht gesendet

Symptom:

⚠ User is not logged in - no Authorization header added

Lösung:

  1. DashAppRunner neu starten
  2. PrĂŒfe testing.properties
  3. PrĂŒfe Keycloak lĂ€uft und ist healthy

Problem 2: Token wird gesendet, aber 403

Symptom:

✅ Authorization header added
(aber trotzdem 403 Forbidden)

Lösung:

  1. PrĂŒfe groupNameAttribute in server.xml
  2. Liberty Config Reload (siehe oben)
  3. PrĂŒfe Keycloak Realm hat Rollen konfiguriert:
    ruu-keycloak-setup
    

Problem 3: Liberty erkennt Config-Änderung nicht

Symptom:

CWWKG0018I: The server configuration was not updated. 
No functional changes were detected.

Lösung - Liberty MUSS neu gestartet werden:

cd ~/develop/github/java/main/root/app/jeeeraaah/backend/api/ws_rs

# Stoppe Liberty
pkill -f "liberty:dev"

# Warte 2 Sekunden
sleep 2

# Starte Liberty neu
mvn liberty:dev

# Warte auf: "CWWKF0011I: The defaultServer server is ready"

Problem 4: Alte Config wird verwendet

Symptom:

grep "groupNameAttribute" ... → NICHTS gefunden

Lösung:

cd ~/develop/github/java/main/root/app/jeeeraaah/backend/api/ws_rs

# Lösche target, dann rebuild
mvn clean

# Warte bis liberty:dev neu baut
# Dann: touch src/main/liberty/config/server.xml

📋 QUICK-CHECK CHECKLISTE


🔗 SIEHE AUCH