diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java index 96270e0ed..958a29c84 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java @@ -34,7 +34,9 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.StanzaIdFilter; import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.iqregister.packet.Registration; +import org.jxmpp.jid.parts.Localpart; /** * Allows creation and management of accounts on an XMPP server. @@ -239,7 +241,7 @@ public final class AccountManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void createAccount(String username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void createAccount(Localpart username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Create a map for all the required attributes, but give them blank values. Map attributes = new HashMap(); for (String attributeName : getAccountAttributes()) { @@ -262,14 +264,21 @@ public final class AccountManager extends Manager { * @throws InterruptedException * @see #getAccountAttributes() */ - public void createAccount(String username, String password, Map attributes) + public void createAccount(Localpart username, String password, Map attributes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) { // TODO throw exception in newer Smack versions LOGGER.warning("Creating account over insecure connection. " + "This will throw an exception in future versions of Smack if AccountManager.sensitiveOperationOverInsecureConnection(true) is not set"); } - attributes.put("username", username); + if (username == null) { + throw new IllegalArgumentException("Username must not be null"); + } + if (StringUtils.isNullOrEmpty(password)) { + throw new IllegalArgumentException("Password must not be null"); + } + + attributes.put("username", username.toString()); attributes.put("password", password); Registration reg = new Registration(attributes); reg.setType(IQ.Type.set); diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/IntTestUtil.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/IntTestUtil.java index fe31ef3a6..83ce1dab3 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/IntTestUtil.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/IntTestUtil.java @@ -32,6 +32,8 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.iqregister.AccountManager; +import org.jxmpp.jid.parts.Localpart; +import org.jxmpp.stringprep.XmppStringprepException; public class IntTestUtil { @@ -58,7 +60,14 @@ public class IntTestUtil { Map additionalAttributes = new HashMap<>(); additionalAttributes.put("name", "Smack Integration Test"); additionalAttributes.put("email", "flow@igniterealtime.org"); - accountManager.createAccount(username, password, additionalAttributes); + Localpart usernameLocalpart; + try { + usernameLocalpart = Localpart.from(username); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException("Invalid username: " + username, e); + } + accountManager.createAccount(usernameLocalpart, password, additionalAttributes); return new UsernameAndPassword(username, password); }