From c6f081c30b378b9b0c3210bddb653c87059e75c8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 30 Jan 2018 17:39:37 +0300 Subject: web: authenticate websocket client --- .../configuration/JuickServerComponentConfiguration.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'juick-server-web/src') diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java index 7ddda36e..5b0cf178 100644 --- a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java +++ b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java @@ -1,25 +1,34 @@ package com.juick.server.configuration; import com.juick.server.component.JuickServerComponent; +import com.juick.service.UserService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import org.springframework.web.util.UriComponentsBuilder; import javax.inject.Inject; @Configuration @EnableScheduling public class JuickServerComponentConfiguration { - @Value("${websocket_url:ws://localhost:8080/ws/}") - private String WS_URI; + @Value("${websocket_url:ws://localhost:8080/}") + private String baseUri; + @Value("${service_user:juick}") + private String serviceUser; + @Inject + private UserService userService; @Inject private JuickServerComponent juickServerComponent; @Bean public WebSocketConnectionManager connectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), juickServerComponent, WS_URI); + String hash = userService.getHashByUID(userService.getUIDbyName(serviceUser)); + String websocketURI = UriComponentsBuilder.fromUriString(baseUri) + .queryParam("hash", hash).build().toUriString(); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), juickServerComponent, websocketURI); manager.setAutoStartup(true); return manager; } -- cgit v1.2.3