From 47ca89612bb367ae0a48987e2dc65d77a2b243a4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 10 Apr 2018 10:23:21 +0300 Subject: fix xmpp flow --- juick-common/src/main/java/com/juick/Message.java | 1 + .../main/java/com/juick/server/XMPPConnection.java | 32 ++++++++++------------ .../java/com/juick/server/tests/ServerTests.java | 5 ++++ juick-www/build.gradle | 1 + .../juick/www/configuration/WebSecurityConfig.java | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/juick-common/src/main/java/com/juick/Message.java b/juick-common/src/main/java/com/juick/Message.java index e574e3cc..155c1747 100644 --- a/juick-common/src/main/java/com/juick/Message.java +++ b/juick-common/src/main/java/com/juick/Message.java @@ -283,6 +283,7 @@ public class Message implements Comparable { this.attachment = attachment; } + @XmlTransient public Instant getUpdated() { return updated; } diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java index 77861373..4d1a73a8 100644 --- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java @@ -535,19 +535,20 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } return null; } - User user_from; - if (msg.getFrom().getDomain().equals("uid.juick.com")) { - user_from = userService.getUserByUID(NumberUtils.toInt(msg.getFrom().getLocal(), - 0)).orElse(new User()); - } else { - user_from = userService.getUserByJID(msg.getFrom().asBareJid().toEscapedString()); - } - if ((user_from == null || user_from.getUid() == 0) && !msg.getFrom().equals(jid)) { - String signuphash = userService.getSignUpHashByJID(msg.getFrom().asBareJid().toEscapedString()); - return makeReply(msg.getFrom(), "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account."); - } Jid to = msg.getTo(); if (to.getDomain().equals(router.getDomain().toEscapedString()) || to.equals(this.jid)) { + User user_from; + if (msg.getFrom().getDomain().equals("uid.juick.com")) { + user_from = userService.getUserByUID(NumberUtils.toInt(msg.getFrom().getLocal(), + 0)).orElse(new User()); + } else { + user_from = userService.getUserByJID(msg.getFrom().asBareJid().toEscapedString()); + } + if ((user_from == null || user_from.getUid() == 0) && !msg.getFrom().equals(jid)) { + String signuphash = userService.getSignUpHashByJID(msg.getFrom().asBareJid().toEscapedString()); + return makeReply(msg.getFrom(), "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account."); + } + com.juick.Message jmsg = msg.getExtension(com.juick.Message.class); if (jmsg != null) { if (to.getLocal().equals("pm")) { @@ -570,10 +571,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } try { if (msg.getTo().equals(jid)) { - result = incomingMessageJuick(user_from, msg.getFrom(), StringUtils.defaultString(msg.getBody()), attachment); - if (result != null) { - router.send(result); - } + return incomingMessageJuick(user_from, msg.getFrom(), StringUtils.defaultString(msg.getBody()), attachment); } else { // PM result = incomingMessageJuick(user_from, msg.getFrom(), @@ -583,8 +581,8 @@ public class XMPPConnection implements StanzaListener, NotificationListener { logger.warn("message exception", e1); } } - } else if (jid.getDomain().endsWith(jid.getDomain()) && (jid.getDomain().equals(this.jid.getDomain()) - || jid.getDomain().endsWith("." + jid.getDomain()))) { + } else if (to.getDomain().endsWith(jid.getDomain()) && (to.getDomain().equals(jid.getDomain()) + || to.getDomain().endsWith("." + jid.getDomain()))) { if (logger.isInfoEnabled()) { try { logger.info("unhandled message: {}", stanzaToString(msg)); 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 3e17ebce..a9cb306b 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 @@ -565,6 +565,11 @@ public class ServerTests { xmppMessage.setBody("What's up?"); result = router.incomingMessage(xmppMessage); assertThat(result.getBody(), startsWith("Private message sent")); + String xml = "@yo:\n" + + "343432434\n" + + "\n" + + "#2 http://juick.com/2juick-2343432434@yo"; + result = router.incomingMessage((rocks.xmpp.core.stanza.model.Message)server.parse(xml)); xmppMessage.setFrom(botJid); xmppMessage.setTo(botJid.withLocal("pm")); Message pm = new Message(); diff --git a/juick-www/build.gradle b/juick-www/build.gradle index 9e1ee3e4..2134b57e 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -31,6 +31,7 @@ dependencies { compile("org.springframework.boot:spring-boot-starter-cache") compile("org.springframework.boot:spring-boot-starter-web") compile ('org.springframework.boot:spring-boot-starter-security') + providedRuntime("org.springframework.boot:spring-boot-devtools") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") providedRuntime 'com.h2database:h2:1.4.196' providedRuntime 'mysql:mysql-connector-java:5.1.45' diff --git a/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java b/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java index 4de79363..b13d03f5 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java @@ -135,6 +135,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.debug(false); - web.ignoring().antMatchers("/style.css*", "/scripts.js*", "/h2-console", "/.well-known/**"); + web.ignoring().antMatchers("/style.css*", "/scripts.js*", "/h2-console/**", "/.well-known/**"); } } -- cgit v1.2.3