Skip to content

Commit

Permalink
Fix websocket exception (OpenIdentityPlatform#52)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maximthomas authored Mar 10, 2023
1 parent 228ce7a commit e7629fe
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -58,8 +47,12 @@ public void start(Session session_client, EndpointConfig config) {
@Override
public void beforeRequest(Map<String, List<String>> headers) {
for (Entry<String,Object> 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());
}
}
}
Expand Down

0 comments on commit e7629fe

Please sign in to comment.