@Override public HttpHeaders getHandshakeHeaders() { return this.delegate.getHandshakeHeaders(); }
@Override public HttpHeaders getHandshakeHeaders() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getHandshakeHeaders(); }
@Test public void handshakeHeaders() throws Exception { URI uri = new URI("ws://localhost/abc"); List<String> protocols = Collections.singletonList("abc"); this.headers.setSecWebSocketProtocol(protocols); this.headers.add("foo", "bar"); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertEquals(1, session.getHandshakeHeaders().size()); assertEquals("bar", session.getHandshakeHeaders().getFirst("foo")); }
@Override public HttpHeaders getHandshakeHeaders() { return this.delegate.getHandshakeHeaders(); }
@Override public HttpHeaders getHandshakeHeaders() { return this.delegate.getHandshakeHeaders(); }
@Override public HttpHeaders getHandshakeHeaders() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getHandshakeHeaders(); }
@Override public HttpHeaders getHandshakeHeaders() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getHandshakeHeaders(); }
public HiveAuthentication.HiveAuthDetails getDetails(WebSocketSession session) { List<String> originList = session.getHandshakeHeaders().get(HttpHeaders.ORIGIN); List<String> authList = session.getHandshakeHeaders().get(HttpHeaders.AUTHORIZATION); String origin = originList == null || originList.isEmpty() ? null : originList.get(0); String auth = authList == null || authList.isEmpty() ? null : authList.get(0); return new HiveAuthentication.HiveAuthDetails(session.getRemoteAddress().getAddress(), origin, auth); } }
@Override protected void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) { List<String> sessionCookies = userAgentSession.getHandshakeHeaders().get(HttpHeaders.COOKIE); headers.put(HttpHeaders.COOKIE, sessionCookies); if (logger.isDebugEnabled()) { logger.debug("Added cookie authentication header to web sockets http headers"); } }
@Override protected boolean shouldApplyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) { return !headers.containsKey(HttpHeaders.COOKIE) && userAgentSession.getHandshakeHeaders().containsKey(HttpHeaders.COOKIE); } }
@HiveWebsocketAuth @PreAuthorize("permitAll") public void processServerInfo(JsonObject request, WebSocketSession session) { logger.debug("server/info action started. Session " + session.getId()); ApiInfoVO apiInfo = new ApiInfoVO(); apiInfo.setApiVersion(Constants.class.getPackage().getImplementationVersion()); session.getHandshakeHeaders().get("Host").stream() .findFirst() .ifPresent(host -> apiInfo.setRestServerUrl("http://" + host + contextPath + "/rest")); apiInfo.setServerTimestamp(timestampService.getDate()); WebSocketResponse response = new WebSocketResponse(); response.addValue(INFO, apiInfo, WEBSOCKET_SERVER_INFO); logger.debug("server/info action completed. Session {}", session.getId()); clientHandler.sendMessage(request, response, session); }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { try { incNumConnectionsIfAllowed(); } catch (MaxNumberWsConnectionsReachedException e) { log.warn("Closed a WS connection because MAX_WS_CONNECTIONS={} limit reached", MAX_WS_CONNECTIONS); session.close(); } try { // We send this notification to the JsonRpcHandler when the JsonRpc // session is established, not when websocket session is established log.debug( "{} Client connection established from session={} uri={} headers={} acceptedProtocol={} attributes={}", label, session.getRemoteAddress(), session.getUri(), session.getHandshakeHeaders(), session.getAcceptedProtocol(), session.getAttributes()); } catch (Throwable t) { log.error("{} Exception processing afterConnectionEstablished in session={}", label, session.getId(), t); } }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { try { incNumConnectionsIfAllowed(); } catch (MaxNumberWsConnectionsReachedException e) { log.warn("Closed a WS connection because MAX_WS_CONNECTIONS={} limit reached", MAX_WS_CONNECTIONS); session.close(); } try { // We send this notification to the JsonRpcHandler when the JsonRpc // session is established, not when websocket session is established log.debug( "{} Client connection established from session={} uri={} headers={} acceptedProtocol={} attributes={}", label, session.getRemoteAddress(), session.getUri(), session.getHandshakeHeaders(), session.getAcceptedProtocol(), session.getAttributes()); } catch (Throwable t) { log.error("{} Exception processing afterConnectionEstablished in session={}", label, session.getId(), t); } }