From d6b6fdca171a889e93d4bd118e3c15cc0ad3ab7f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 7 Apr 2019 16:44:04 +0200 Subject: [PATCH] Add ConnectionConfiguration.setXmppAddressAndPassword() --- .../smack/ConnectionConfiguration.java | 33 +++++++++++++++++++ .../smack/tcp/XMPPTCPConnection.java | 3 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index 566ede4ae..b87f2ccd2 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -554,6 +554,39 @@ public abstract class ConnectionConfiguration { } } + /** + * Convenience method to configure the username, password and XMPP service domain. + * + * @param jid the XMPP address of the user. + * @param password the password of the user. + * @return a reference to this builder. + * @throws XmppStringprepException in case the XMPP address is not valid. + * @see #setXmppAddressAndPassword(EntityBareJid, String) + * @since 4.4.0 + */ + public B setXmppAddressAndPassword(CharSequence jid, String password) throws XmppStringprepException { + return setXmppAddressAndPassword(JidCreate.entityBareFrom(jid), password); + } + + /** + * Convenience method to configure the username, password and XMPP service domain. The localpart of the provided + * JID is used as username and the domanipart is used as XMPP service domain. + *

+ * Please note that this does and can not configure the client XMPP address. XMPP services are not required to + * assign bound JIDs where the localpart matches the username and the domainpart matches the verified domainpart. + * Although most services will follow that pattern. + *

+ * + * @param jid + * @param password + * @return a reference to this builder. + * @since 4.4.0 + */ + public B setXmppAddressAndPassword(EntityBareJid jid, String password) { + setUsernameAndPassword(jid.getLocalpart(), password); + return setXmppDomain(jid.asDomainBareJid()); + } + /** * Set the XMPP entities username and password. *

diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index e680566d6..dd7b7a30a 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -121,7 +121,6 @@ import org.jivesoftware.smack.util.dns.HostAddress; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.stringprep.XmppStringprepException; -import org.jxmpp.util.XmppStringUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -319,7 +318,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * @throws XmppStringprepException */ public XMPPTCPConnection(CharSequence jid, String password) throws XmppStringprepException { - this(XmppStringUtils.parseLocalpart(jid.toString()), password, XmppStringUtils.parseDomain(jid.toString())); + this(XMPPTCPConnectionConfiguration.builder().setXmppAddressAndPassword(jid, password).build()); } /**