diff options
Diffstat (limited to 'juick-server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/WebsocketManager.java | 12 | ||||
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/juick-server/src/main/java/com/juick/server/WebsocketManager.java b/juick-server/src/main/java/com/juick/server/WebsocketManager.java index 85950c2c..5c976416 100644 --- a/juick-server/src/main/java/com/juick/server/WebsocketManager.java +++ b/juick-server/src/main/java/com/juick/server/WebsocketManager.java @@ -156,10 +156,14 @@ public class WebsocketManager extends TextWebSocketHandler { protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { User user = clients.stream().filter(c -> c.session.equals(session)).map(c -> c.visitor) .findFirst().orElse(AnonymousUser.INSTANCE); - String command = message.getPayload().trim(); - if (StringUtils.isNotEmpty(command)) { - CommandResult result = commandsManager.processCommand(user, command, URI.create("")); - session.sendMessage(new TextMessage(result.getText())); + if (!user.isAnonymous()) { + String command = message.getPayload().trim(); + if (StringUtils.isNotEmpty(command)) { + CommandResult result = commandsManager.processCommand(user, command, URI.create("")); + session.sendMessage(new TextMessage(result.getText())); + } + } else { + session.sendMessage(new TextMessage("Authorization required")); } } diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 292020d6..13da55fd 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -850,7 +850,7 @@ public class ServerTests { .run("--spring.main.web_environment=false"); long count = context.getBean(WebsocketClientConfig.class).getLatch().getCount(); WebsocketClientHandler handler = context.getBean(WebsocketClientHandler.class); - assertThat(handler.getLastMessage(), is("PONG")); + assertThat(handler.getLastMessage(), is("Authorization required")); context.close(); Assert.assertThat(count, equalTo(0L)); mockMvc.perform(get("/ws/_all")).andExpect(status().isBadRequest()); |