diff options
-rw-r--r-- | build.gradle | 6 | ||||
-rw-r--r-- | juick-core/build.gradle | 2 | ||||
-rw-r--r-- | juick-notifications/build.gradle | 4 | ||||
-rw-r--r-- | juick-rss/build.gradle | 2 | ||||
-rw-r--r-- | juick-server/build.gradle | 4 | ||||
-rw-r--r-- | juick-spring-www/build.gradle | 2 | ||||
-rw-r--r-- | juick-xmpp/build.gradle | 6 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/XMPPServer.java | 10 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java | 11 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java | 21 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java | 57 |
11 files changed, 63 insertions, 62 deletions
diff --git a/build.gradle b/build.gradle index d3e3af0c..dc7fe80a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,11 +6,11 @@ allprojects { } project.ext { - springFrameworkVersion = '4.3.5.RELEASE' + springFrameworkVersion = '4.3.6.RELEASE' springSecurityVersion = '4.2.1.RELEASE' jacksonVersion = '2.8.6' slf4jVersion = '1.7.22' - logbackVersion = '1.1.8' + logbackVersion = '1.1.9' junitVersion = "4.12" hamcrestVersion= "1.3" } @@ -44,7 +44,7 @@ dependencies { testCompile "org.slf4j:slf4j-api:${slf4jVersion}" testCompile "junit:junit:${junitVersion}" testCompile "org.hamcrest:hamcrest-all:${hamcrestVersion}" - testCompile "org.mockito:mockito-core:2.6.2" + testCompile "org.mockito:mockito-core:2.7.0" testRuntime "mysql:mysql-connector-java:5.1.40" } diff --git a/juick-core/build.gradle b/juick-core/build.gradle index 421025fe..58d8eec3 100644 --- a/juick-core/build.gradle +++ b/juick-core/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'com.github.ben-manes.versions' dependencies { compile "com.fasterxml.jackson.core:jackson-annotations:${rootProject.jacksonVersion}" compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" - compile 'org.apache.httpcomponents:httpclient:4.5.2' + compile 'org.apache.httpcomponents:httpclient:4.5.3' compile 'org.apache.commons:commons-lang3:3.5' compile 'org.apache.commons:commons-collections4:4.1' compile 'commons-io:commons-io:2.5' diff --git a/juick-notifications/build.gradle b/juick-notifications/build.gradle index 6d4cb952..04ff0659 100644 --- a/juick-notifications/build.gradle +++ b/juick-notifications/build.gradle @@ -21,14 +21,14 @@ dependencies { compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" - compile "org.apache.httpcomponents:httpclient:4.5.2" + compile "org.apache.httpcomponents:httpclient:4.5.3" compile "org.apache.commons:commons-lang3:3.5" compile "org.bitbucket.sco0ter.babbler:xmpp-core-client:0ba6c0e2f9" compile "org.bitbucket.sco0ter.babbler:xmpp-extensions-client:0ba6c0e2f9" testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" - testCompile "org.mockito:mockito-core:2.6.2" + testCompile "org.mockito:mockito-core:2.7.0" } compileJava.options.encoding = 'UTF-8' diff --git a/juick-rss/build.gradle b/juick-rss/build.gradle index 0632efb0..7856f39f 100644 --- a/juick-rss/build.gradle +++ b/juick-rss/build.gradle @@ -12,7 +12,7 @@ dependencies { testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" - testCompile "org.mockito:mockito-core:2.6.2" + testCompile "org.mockito:mockito-core:2.7.0" testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" } diff --git a/juick-server/build.gradle b/juick-server/build.gradle index bb962d4b..21e95e05 100644 --- a/juick-server/build.gradle +++ b/juick-server/build.gradle @@ -21,7 +21,7 @@ dependencies { compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" - compile "org.apache.httpcomponents:httpclient:4.5.2" + compile "org.apache.httpcomponents:httpclient:4.5.3" compile "org.apache.commons:commons-lang3:3.5" compile "org.apache.commons:commons-collections4:4.1" compile "commons-io:commons-io:2.5" @@ -49,7 +49,7 @@ dependencies { testCompile "ch.vorburger.mariaDB4j:mariaDB4j:2.2.2" testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" - testCompile "org.mockito:mockito-core:2.6.2" + testCompile "org.mockito:mockito-core:2.7.0" testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" testCompile "org.springframework.security:spring-security-test:${rootProject.springSecurityVersion}" diff --git a/juick-spring-www/build.gradle b/juick-spring-www/build.gradle index 8a8ce6ab..bd00f93f 100644 --- a/juick-spring-www/build.gradle +++ b/juick-spring-www/build.gradle @@ -36,7 +36,7 @@ dependencies { testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" - testCompile "org.mockito:mockito-core:2.6.2" + testCompile "org.mockito:mockito-core:2.7.0" testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" testCompile "ch.vorburger.mariaDB4j:mariaDB4j:2.2.2" diff --git a/juick-xmpp/build.gradle b/juick-xmpp/build.gradle index 268c5e7b..5bd71e64 100644 --- a/juick-xmpp/build.gradle +++ b/juick-xmpp/build.gradle @@ -5,16 +5,16 @@ apply plugin: 'com.github.ben-manes.versions' dependencies { compile project(':juick-server') - compile 'com.github.juick:com.juick.xmpp:dbf603cfff' + compile 'com.github.juick:com.juick.xmpp:43212cf5ac' compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}" compile "com.fasterxml.jackson.core:jackson-core:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.core:jackson-databind:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}" compile 'javax.inject:javax.inject:1' - compile 'org.apache.httpcomponents:httpclient:4.5.2' + compile 'org.apache.httpcomponents:httpclient:4.5.3' compile 'org.apache.commons:commons-dbcp2:2.1.1' - compile 'net.jodah:failsafe:1.0.1' + compile 'net.jodah:failsafe:1.0.3' providedRuntime 'mysql:mysql-connector-java:5.1.40' } diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index 3bfa49e1..4a182cc9 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -2,7 +2,6 @@ package com.juick.components; import com.juick.components.s2s.*; import com.juick.service.*; -import com.juick.xmpp.JID; import com.juick.xmpp.Stanza; import com.juick.xmpp.StanzaChild; import com.juick.xmpp.extensions.JuickMessage; @@ -13,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import org.xmlpull.v1.XmlPullParserException; +import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.io.IOException; @@ -59,7 +59,7 @@ public class XMPPServer implements AutoCloseable { @Inject public SubscriptionService subscriptionService; - private JID jid; + private Jid jid; private ServerSocket listener; @@ -76,7 +76,7 @@ public class XMPPServer implements AutoCloseable { keystorePassword = env.getProperty("keystore_password"); brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", StringUtils.EMPTY).split(",")); bannedHosts = Arrays.asList(env.getProperty("banned_hosts", StringUtils.EMPTY).split(",")); - jid = new JID(env.getProperty("xmppbot_jid")); + jid = Jid.of(env.getProperty("xmppbot_jid")); boolean disabled = BooleanUtils.toBoolean(env.getProperty("xmpp_disabled", "false")); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); @@ -196,7 +196,7 @@ public class XMPPServer implements AutoCloseable { } public void sendOut(Stanza s) { - sendOut(s.to.Host, s.toString()); + sendOut(s.to.getDomain(), s.toString()); } public void sendOut(String hostname, String xml) { @@ -286,7 +286,7 @@ public class XMPPServer implements AutoCloseable { stanzaListeners.forEach(l -> l.stanzaReceived(type, xmlValue)); } - public JID getJid() { + public Jid getJid() { return jid; } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index 882cc2f7..8713aa03 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -2,11 +2,11 @@ package com.juick.components.s2s; import com.juick.components.XMPPServer; import com.juick.xmpp.Iq; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.utils.XmlUtils; import org.xmlpull.v1.XmlPullParser; +import rocks.xmpp.addr.Jid; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSocket; @@ -188,12 +188,13 @@ public class ConnectionIn extends Connection implements Runnable { String cfrom = parser.getAttributeValue(null, "from"); String cto = parser.getAttributeValue(null, "to"); if (cfrom != null && cto != null && !cfrom.isEmpty() && !cto.isEmpty()) { - JID jidto = new JID(cto); - if (jidto.Host != null && jidto.Username != null && jidto.Host.equals(xmpp.HOSTNAME) && jidto.Username.matches("^[a-zA-Z0-9\\-]{2,16}$")) { - JID jidfrom = new JID(cfrom); + Jid jidto = Jid.of(cto); + if (jidto.getDomain() != null && jidto.getLocal() != null && jidto.getDomain().equals(xmpp.HOSTNAME) + && jidto.getLocal().matches("^[a-zA-Z0-9\\-]{2,16}$")) { + Jid jidfrom = Jid.of(cfrom); int size = from.size(); for (int i = 0; i < size; i++) { - if (from.get(i).equals(jidfrom.Host)) { + if (from.get(i).equals(jidfrom.getDomain())) { return true; } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java index 37d3c59f..f0fc3c60 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java @@ -2,7 +2,6 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.Nickname; @@ -15,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import rocks.xmpp.addr.Jid; import java.io.IOException; import java.io.InputStreamReader; @@ -92,15 +92,15 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea String tag = parser.getName(); String to = parser.getAttributeValue(null, "to"); if (to != null && (tag.equals("message") || tag.equals("presence") || tag.equals("iq"))) { - JID jid = new JID(to); - if (jid.Host != null) { - if (jid.Host.equals(componentName)) { + Jid jid = Jid.of(to); + if (jid.getDomain() != null) { + if (jid.getDomain().equals(componentName)) { if (tag.equals("message")) { Message xmsg = Message.parse(parser, xmpp.childParsers); logger.info("stream router (process): {}", xmsg); JuickMessage jmsg = (JuickMessage) xmsg.getChild(JuickMessage.XMLNS); if (jmsg != null) { - if (jid.Username != null && jid.Username.equals("recomm")) { + if (jid.getLocal() != null && jid.getLocal().equals("recomm")) { sendJuickRecommendation(jmsg); } else { if (jmsg.getRid() > 0) { @@ -114,13 +114,14 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea String xml = XmlUtils.parseToString(parser, true); logger.info("stream router (stanza): {}", xml); } - } else if (jid.Host.endsWith(xmpp.HOSTNAME) && (jid.Host.equals(xmpp.HOSTNAME) || jid.Host.endsWith("." + xmpp.HOSTNAME))) { + } else if (jid.getDomain().endsWith(xmpp.HOSTNAME) && (jid.getDomain().equals(xmpp.HOSTNAME) + || jid.getDomain().endsWith("." + xmpp.HOSTNAME))) { String xml = XmlUtils.parseToString(parser, true); logger.info("stream router: {}", xml); } else { String xml = XmlUtils.parseToString(parser, true); logger.info("stream router (out): {}", xml); - xmpp.sendOut(jid.Host, xml); + xmpp.sendOut(jid.getDomain(), xml); } } else { String invalidStanza = XmlUtils.parseToString(parser, true); @@ -183,7 +184,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea } for (String jid : jids) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } @@ -214,7 +215,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea msg.addChild(jmsg); for (User user : users) { for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } @@ -262,7 +263,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea for (User user : users) { for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java index eec9b8e2..f309bd21 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java @@ -2,13 +2,13 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.Stanza; -import com.juick.xmpp.extensions.Error; +import com.juick.xmpp.extensions.XMPPError; import com.juick.xmpp.extensions.JuickMessage; import org.apache.commons.lang3.StringUtils; +import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.util.List; @@ -64,13 +64,13 @@ public class JuickBot implements StanzaListener { + "Read more: http://juick.com/help/"; public boolean incomingPresence(Presence p) { - final String username = p.to.Username.toLowerCase(); + final String username = p.to.getLocal(); final boolean toJuick = username.equals("juick"); if (p.type == null) { Presence reply = new Presence(); - reply.from = new JID(p.to.Username, p.to.Host, null); - reply.to = new JID(p.from.Username, p.from.Host, null); + reply.from = p.to.asBareJid(); + reply.to = p.from.asBareJid(); reply.type = Presence.Type.unsubscribe; xmpp.sendOut(reply); return true; @@ -82,15 +82,14 @@ public class JuickBot implements StanzaListener { if (toJuick || uid_to > 0) { Presence reply = new Presence(); - reply.from = p.to; - reply.from.Resource = "Juick"; + reply.from = p.to.withResource("Juick"); reply.to = p.from; reply.priority = 10; xmpp.sendOut(reply); } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -102,7 +101,7 @@ public class JuickBot implements StanzaListener { } else { int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - xmpp.pmQueriesService.addPMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.addPMinRoster(uid_to, p.from.asBareJid().toEscapedString()); canSubscribe = true; } } @@ -111,7 +110,7 @@ public class JuickBot implements StanzaListener { Presence reply = new Presence(p.to, p.from, Presence.Type.subscribed); xmpp.sendOut(reply); - reply.from.Resource = "Juick"; + reply.from = reply.from.withResource("Juick"); reply.priority = 10; reply.type = null; xmpp.sendOut(reply); @@ -120,7 +119,7 @@ public class JuickBot implements StanzaListener { } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -128,7 +127,7 @@ public class JuickBot implements StanzaListener { if (!toJuick) { int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - xmpp.pmQueriesService.removePMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.removePMinRoster(uid_to, p.from.asBareJid().toEscapedString()); } } @@ -144,13 +143,13 @@ public class JuickBot implements StanzaListener { return false; } - String username = msg.to.Username.toLowerCase(); + String username = msg.to.getLocal(); User user_from; String signuphash = StringUtils.EMPTY; - user_from = xmpp.userService.getUserByJID(msg.from.Bare()); + user_from = xmpp.userService.getUserByJID(msg.from.asBareJid().toEscapedString()); if (user_from == null) { - signuphash = xmpp.userService.getSignUpHashByJID(msg.from.Bare()); + signuphash = xmpp.userService.getSignUpHashByJID(msg.from.asBareJid().toEscapedString()); } if (user_from == null) { @@ -173,7 +172,7 @@ public class JuickBot implements StanzaListener { if (uid_to == 0) { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -185,15 +184,15 @@ public class JuickBot implements StanzaListener { if (success) { Message m = new Message(); - m.from = new JID("juick", "juick.com", null); - m.to = new JID(Integer.toString(uid_to), "push.juick.com", null); + m.from = Jid.of("juick@juick.com"); + m.to = Jid.of(Integer.toString(uid_to), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); jmsg.setUser(user_from); jmsg.setText(msg.body); m.childs.add(jmsg); xmpp.getRouter().sendStanza(m.toString()); - m.to.Host = "ws.juick.com"; + m.to = Jid.of(Integer.toString(uid_to), "ws.juick.com", null); xmpp.getRouter().sendStanza(m.toString()); List<String> jids; @@ -201,14 +200,14 @@ public class JuickBot implements StanzaListener { jids = xmpp.userService.getJIDsbyUID(uid_to); for (String jid : jids) { Message mm = new Message(); - mm.to = new JID(jid); + mm.to = Jid.of(jid); mm.type = Message.Type.chat; inroster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (inroster) { - mm.from = new JID(jmsg.getUser().getName(), "juick.com", "Juick"); + mm.from = Jid.of(jmsg.getUser().getName(), "juick.com", "Juick"); mm.body = msg.body; } else { - mm.from = new JID("juick", "juick.com", "Juick"); + mm.from = Jid.of("juick", "juick.com", "Juick"); mm.body = "Private message from @" + jmsg.getUser().getName() + ":\n" + msg.body; } xmpp.sendOut(mm); @@ -216,7 +215,7 @@ public class JuickBot implements StanzaListener { } else { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; - reply.addChild(new Error(Error.Type.cancel, "not-allowed")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "not-allowed")); xmpp.sendOut(reply); } @@ -313,27 +312,27 @@ public class JuickBot implements StanzaListener { if (ret == 200) { Message msg = new Message(); - msg.from = new JID("juick", "juick.com", null); - msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null); + msg.from = Jid.of("juick", "juick.com", null); + msg.to = Jid.of(Integer.toString(uid_to), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); jmsg.setUser(user_from); jmsg.setText(body); msg.childs.add(jmsg); xmpp.getRouter().sendStanza(msg.toString()); - msg.to.Host = "ws.juick.com"; + msg.to = Jid.of(Integer.toString(uid_to), "ws.juick.com", null); xmpp.getRouter().sendStanza(msg.toString()); for (String jid : jids_to) { Message mm = new Message(); - mm.to = new JID(jid); + mm.to = Jid.of(jid); mm.type = Message.Type.chat; haveInRoster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (haveInRoster) { - mm.from = new JID(user_from.getName(), "juick.com", "Juick"); + mm.from = Jid.of(user_from.getName(), "juick.com", "Juick"); mm.body = body; } else { - mm.from = new JID("juick", "juick.com", "Juick"); + mm.from = Jid.of("juick", "juick.com", "Juick"); mm.body = "Private message from @" + user_from.getName() + ":\n" + body; } xmpp.sendOut(mm); |