@Test public void parseWebSocketExtensions() { List<String> extensions = new ArrayList<>(); extensions.add("x-foo-extension, x-bar-extension"); extensions.add("x-test-extension"); this.headers.put(WebSocketHttpHeaders.SEC_WEBSOCKET_EXTENSIONS, extensions); List<WebSocketExtension> parsedExtensions = this.headers.getSecWebSocketExtensions(); assertThat(parsedExtensions, Matchers.hasSize(3)); }
@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 void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) { Authentication authentication = (Authentication) userAgentSession.getPrincipal(); String usernameColonPwd = authentication.getName() + ":" + authentication.getCredentials().toString(); String encodedCredentials = new String( Base64.encode(usernameColonPwd.getBytes())); headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList("Basic " + encodedCredentials)); if (logger.isDebugEnabled()) { logger.debug("Added basic authentication header for user " + authentication.getName() + " to web sockets http headers"); } }
@Override protected void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) { OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) userAgentSession.getPrincipal(); OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails(); String accessToken = details.getTokenValue(); headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList("Bearer " + accessToken)); if (logger.isDebugEnabled()) { logger.debug("Added Oauth2 bearer token authentication header for user " + oAuth2Authentication.getName() + " to web sockets http headers"); } }