aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
diff options
context:
space:
mode:
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);