From e7629fe20ad4800a3cd720bef5de5770b6201c3c Mon Sep 17 00:00:00 2001 From: Maxim Thomas Date: Fri, 10 Mar 2023 09:09:51 +0300 Subject: [PATCH] Fix websocket exception (#52) * Compact OpenIG docker images * Fix websocket exception: java.lang.ClassCastException: class org.forgerock.http.header.CookieHeader cannot be cast to class org.forgerock.http.header.GenericHeader --- .../openig/websocket/ServerEndPoint.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/openig-core/src/main/java/org/openidentityplatform/openig/websocket/ServerEndPoint.java b/openig-core/src/main/java/org/openidentityplatform/openig/websocket/ServerEndPoint.java index e0b3d10b3..16c824c0e 100644 --- a/openig-core/src/main/java/org/openidentityplatform/openig/websocket/ServerEndPoint.java +++ b/openig-core/src/main/java/org/openidentityplatform/openig/websocket/ServerEndPoint.java @@ -1,29 +1,18 @@ package org.openidentityplatform.openig.websocket; +import org.forgerock.http.protocol.Header; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.websocket.*; +import javax.websocket.ClientEndpointConfig.Builder; +import javax.websocket.server.ServerEndpoint; import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import javax.websocket.ClientEndpointConfig; -import javax.websocket.CloseReason; -import javax.websocket.ContainerProvider; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.MessageHandler; -import javax.websocket.OnClose; -import javax.websocket.OnError; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.ClientEndpointConfig.Builder; -import javax.websocket.server.ServerEndpoint; - -import org.forgerock.http.header.GenericHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - @ServerEndpoint(value = "/{level1}",configurator = Configurator.class) public class ServerEndPoint { @@ -58,8 +47,12 @@ public void start(Session session_client, EndpointConfig config) { @Override public void beforeRequest(Map> headers) { for (Entry entry : principal.request.getHeaders().entrySet()) { - if (entry.getKey().toLowerCase().startsWith("cookie")||entry.getKey().toLowerCase().startsWith("x-")||entry.getKey().equalsIgnoreCase("origin")||entry.getKey().equalsIgnoreCase("Authorization")||entry.getKey().toLowerCase().startsWith("sec-websocket-")) { - headers.put(entry.getKey(), ((GenericHeader)entry.getValue()).getValues()); + if (entry.getKey().toLowerCase().startsWith("cookie") + ||entry.getKey().toLowerCase().startsWith("x-") + ||entry.getKey().equalsIgnoreCase("origin") + ||entry.getKey().equalsIgnoreCase("Authorization") + ||entry.getKey().toLowerCase().startsWith("sec-websocket-")) { + headers.put(entry.getKey(), ((Header)entry.getValue()).getValues()); } } }