aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-10-18 17:52:08 +0300
committerGravatar Vitaly Takmazov2017-10-18 17:52:08 +0300
commitab1107c209edc34180397db4614ac3c185d6a52a (patch)
treeac0dfcfdf53369859950f48c756278e7261e9afe /juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
parent0b9d212606984602445437e919075ff2d790e256 (diff)
ws: httpclient -> RestTemplate
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java25
1 files changed, 10 insertions, 15 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
index 24304494..550067b7 100644
--- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
@@ -19,6 +19,7 @@ package com.juick.ws;
import com.juick.Message;
import com.juick.User;
+import com.juick.server.helpers.AnonymousUser;
import com.juick.server.protocol.JuickProtocol;
import com.juick.server.protocol.ProtocolListener;
import com.juick.service.MessagesService;
@@ -26,8 +27,6 @@ import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.utils.URLEncodedUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
@@ -37,13 +36,14 @@ import org.springframework.web.socket.PingMessage;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
+import org.springframework.web.util.UriComponents;
+import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -81,18 +81,13 @@ public class WebsocketComponent extends TextWebSocketHandler implements Protocol
Collections.singletonList(session.getRemoteAddress().toString())).get(0);
// Auth
- User visitor = new User();
- List<NameValuePair> params = URLEncodedUtils.parse(hLocation, StandardCharsets.UTF_8);
- for (NameValuePair param : params) {
- if (param.getName().equals("hash")) {
- String hash = param.getValue();
- if (hash.length() == 16) {
- visitor = userService.getUserByHash(hash);
- } else {
- logger.info("wrong hash for {} from {}", visitor.getUid(), hXRealIP);
- }
- break;
- }
+ User visitor = AnonymousUser.INSTANCE;
+ UriComponents uriComponents = UriComponentsBuilder.fromUri(hLocation).build();
+ List<String> hash = uriComponents.getQueryParams().get("hash");
+ if (hash != null && hash.get(0).length() == 16) {
+ visitor = userService.getUserByHash(hash.get(0));
+ } else {
+ logger.info("wrong hash for {} from {}", visitor.getUid(), hXRealIP);
}
logger.info("user {} connected to {} from {}", visitor.getUid(), hLocation.getPath(), hXRealIP);