2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2003-03-10 00:06:59 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:53:30 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-03-10 00:06:59 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-03-10 00:06:59 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-09-11 23:58:07 +02:00
|
|
|
package org.jivesoftware.smackx.iqregister;
|
2003-03-09 00:09:48 +01:00
|
|
|
|
2006-08-03 19:04:01 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2014-11-29 13:36:56 +01:00
|
|
|
import java.util.Set;
|
2014-03-17 20:46:08 +01:00
|
|
|
import java.util.WeakHashMap;
|
2003-03-09 00:09:48 +01:00
|
|
|
|
2014-09-11 23:58:07 +02:00
|
|
|
import org.jivesoftware.smack.Manager;
|
|
|
|
import org.jivesoftware.smack.SmackException;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.StanzaCollector;
|
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2015-02-19 14:59:44 +01:00
|
|
|
import org.jivesoftware.smack.filter.StanzaIdFilter;
|
2016-11-27 21:14:44 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2014-02-23 21:08:35 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2015-08-20 19:01:33 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2016-11-27 21:14:44 +01:00
|
|
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
2014-09-11 23:58:07 +02:00
|
|
|
import org.jivesoftware.smackx.iqregister.packet.Registration;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-08-20 19:01:33 +02:00
|
|
|
import org.jxmpp.jid.parts.Localpart;
|
2014-02-23 21:08:35 +01:00
|
|
|
|
2003-03-09 00:09:48 +01:00
|
|
|
/**
|
|
|
|
* Allows creation and management of accounts on an XMPP server.
|
|
|
|
*
|
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
2015-04-06 10:45:12 +02:00
|
|
|
public final class AccountManager extends Manager {
|
2015-02-21 16:55:30 +01:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final Map<XMPPConnection, AccountManager> INSTANCES = new WeakHashMap<>();
|
2014-03-17 20:46:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the AccountManager instance associated with a given XMPPConnection.
|
|
|
|
*
|
|
|
|
* @param connection the connection used to look for the proper ServiceDiscoveryManager.
|
|
|
|
* @return the AccountManager associated with a given XMPPConnection.
|
|
|
|
*/
|
|
|
|
public static synchronized AccountManager getInstance(XMPPConnection connection) {
|
|
|
|
AccountManager accountManager = INSTANCES.get(connection);
|
2014-08-11 21:08:02 +02:00
|
|
|
if (accountManager == null) {
|
2014-03-17 20:46:08 +01:00
|
|
|
accountManager = new AccountManager(connection);
|
2014-08-11 21:08:02 +02:00
|
|
|
INSTANCES.put(connection, accountManager);
|
|
|
|
}
|
2014-03-17 20:46:08 +01:00
|
|
|
return accountManager;
|
|
|
|
}
|
|
|
|
|
2015-02-21 16:55:30 +01:00
|
|
|
private static boolean allowSensitiveOperationOverInsecureConnectionDefault = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value used by new account managers for <code>allowSensitiveOperationOverInsecureConnection</code>.
|
|
|
|
*
|
|
|
|
* @param allow
|
|
|
|
* @see #sensitiveOperationOverInsecureConnection(boolean)
|
|
|
|
* @since 4.1
|
|
|
|
*/
|
|
|
|
public static void sensitiveOperationOverInsecureConnectionDefault(boolean allow) {
|
|
|
|
AccountManager.allowSensitiveOperationOverInsecureConnectionDefault = allow;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean allowSensitiveOperationOverInsecureConnection = allowSensitiveOperationOverInsecureConnectionDefault;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to <code>true</code> to allow sensitive operation over insecure connection.
|
|
|
|
* <p>
|
|
|
|
* Set to true to allow sensitive operations like account creation or password changes over an insecure (e.g.
|
|
|
|
* unencrypted) connections.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param allow
|
|
|
|
* @since 4.1
|
|
|
|
*/
|
|
|
|
public void sensitiveOperationOverInsecureConnection(boolean allow) {
|
|
|
|
this.allowSensitiveOperationOverInsecureConnection = allow;
|
|
|
|
}
|
|
|
|
|
2003-03-09 00:09:48 +01:00
|
|
|
private Registration info = null;
|
|
|
|
|
2006-08-03 19:04:01 +02:00
|
|
|
/**
|
|
|
|
* Flag that indicates whether the server supports In-Band Registration.
|
|
|
|
* In-Band Registration may be advertised as a stream feature. If no stream feature
|
2018-03-31 14:17:30 +02:00
|
|
|
* was advertised from the server then try sending an IQ stanza to discover if In-Band
|
2006-08-03 19:04:01 +02:00
|
|
|
* Registration is available.
|
|
|
|
*/
|
|
|
|
private boolean accountCreationSupported = false;
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Creates a new AccountManager instance.
|
|
|
|
*
|
2015-02-12 12:13:19 +01:00
|
|
|
* @param connection a connection to an XMPP server.
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2014-03-17 20:46:08 +01:00
|
|
|
private AccountManager(XMPPConnection connection) {
|
|
|
|
super(connection);
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2006-08-03 19:04:01 +02:00
|
|
|
/**
|
|
|
|
* Sets whether the server supports In-Band Registration. In-Band Registration may be
|
|
|
|
* advertised as a stream feature. If no stream feature was advertised from the server
|
2018-03-31 14:17:30 +02:00
|
|
|
* then try sending an IQ stanza to discover if In-Band Registration is available.
|
2006-08-03 19:04:01 +02:00
|
|
|
*
|
|
|
|
* @param accountCreationSupported true if the server supports In-Band Registration.
|
|
|
|
*/
|
2016-11-27 21:14:44 +01:00
|
|
|
// TODO: Remove this method and the accountCreationSupported boolean.
|
2006-08-03 19:04:01 +02:00
|
|
|
void setSupportsAccountCreation(boolean accountCreationSupported) {
|
|
|
|
this.accountCreationSupported = accountCreationSupported;
|
|
|
|
}
|
|
|
|
|
2003-03-09 00:09:48 +01:00
|
|
|
/**
|
2003-03-10 00:06:59 +01:00
|
|
|
* Returns true if the server supports creating new accounts. Many servers require
|
|
|
|
* that you not be currently authenticated when creating new accounts, so the safest
|
|
|
|
* behavior is to only create new accounts before having logged in to a server.
|
2003-03-09 00:09:48 +01:00
|
|
|
*
|
|
|
|
* @return true if the server support creating new accounts.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-09 00:09:48 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public boolean supportsAccountCreation() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2016-11-27 21:14:44 +01:00
|
|
|
// TODO: Replace this body with isSupported() and possible deprecate this method.
|
|
|
|
|
2006-08-03 19:04:01 +02:00
|
|
|
// Check if we already know that the server supports creating new accounts
|
|
|
|
if (accountCreationSupported) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// No information is known yet (e.g. no stream feature was received from the server
|
|
|
|
// indicating that it supports creating new accounts) so send an IQ packet as a way
|
|
|
|
// to discover if this feature is supported
|
2014-03-12 11:50:05 +01:00
|
|
|
if (info == null) {
|
|
|
|
getRegistrationInfo();
|
2014-06-06 02:20:45 +02:00
|
|
|
accountCreationSupported = info.getType() != IQ.Type.error;
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
return accountCreationSupported;
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
2006-07-18 08:47:38 +02:00
|
|
|
* Returns an unmodifiable collection of the names of the required account attributes.
|
|
|
|
* All attributes must be set when creating new accounts. The standard set of possible
|
2003-03-10 00:06:59 +01:00
|
|
|
* attributes are as follows: <ul>
|
|
|
|
* <li>name -- the user's name.
|
|
|
|
* <li>first -- the user's first name.
|
|
|
|
* <li>last -- the user's last name.
|
|
|
|
* <li>email -- the user's email address.
|
|
|
|
* <li>city -- the user's city.
|
|
|
|
* <li>state -- the user's state.
|
|
|
|
* <li>zip -- the user's ZIP code.
|
|
|
|
* <li>phone -- the user's phone number.
|
|
|
|
* <li>url -- the user's website.
|
|
|
|
* <li>date -- the date the registration took place.
|
|
|
|
* <li>misc -- other miscellaneous information to associate with the account.
|
|
|
|
* <li>text -- textual information to associate with the account.
|
|
|
|
* <li>remove -- empty flag to remove account.
|
|
|
|
* </ul><p>
|
|
|
|
*
|
|
|
|
* Typically, servers require no attributes when creating new accounts, or just
|
|
|
|
* the user's email address.
|
|
|
|
*
|
|
|
|
* @return the required account attributes.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public Set<String> getAccountAttributes() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-03-12 11:50:05 +01:00
|
|
|
if (info == null) {
|
|
|
|
getRegistrationInfo();
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
Map<String, String> attributes = info.getAttributes();
|
|
|
|
if (attributes != null) {
|
|
|
|
return Collections.unmodifiableSet(attributes.keySet());
|
|
|
|
} else {
|
|
|
|
return Collections.emptySet();
|
2006-07-18 07:14:33 +02:00
|
|
|
}
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2004-10-23 19:10:50 +02:00
|
|
|
/**
|
|
|
|
* Returns the value of a given account attribute or <tt>null</tt> if the account
|
|
|
|
* attribute wasn't found.
|
|
|
|
*
|
|
|
|
* @param name the name of the account attribute to return its value.
|
|
|
|
* @return the value of the account attribute or <tt>null</tt> if an account
|
|
|
|
* attribute wasn't found for the requested name.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2004-10-23 19:10:50 +02:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public String getAccountAttribute(String name) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-03-12 11:50:05 +01:00
|
|
|
if (info == null) {
|
|
|
|
getRegistrationInfo();
|
2004-10-23 19:10:50 +02:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
return info.getAttributes().get(name);
|
2004-10-23 19:10:50 +02:00
|
|
|
}
|
|
|
|
|
2003-09-27 19:26:53 +02:00
|
|
|
/**
|
|
|
|
* Returns the instructions for creating a new account, or <tt>null</tt> if there
|
|
|
|
* are no instructions. If present, instructions should be displayed to the end-user
|
|
|
|
* that will complete the registration process.
|
|
|
|
*
|
|
|
|
* @return the account creation instructions, or <tt>null</tt> if there are none.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-09-27 19:26:53 +02:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public String getAccountInstructions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-03-12 11:50:05 +01:00
|
|
|
if (info == null) {
|
|
|
|
getRegistrationInfo();
|
2003-09-27 19:26:53 +02:00
|
|
|
}
|
2014-03-12 11:50:05 +01:00
|
|
|
return info.getInstructions();
|
2003-09-27 19:26:53 +02:00
|
|
|
}
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Creates a new account using the specified username and password. The server may
|
|
|
|
* require a number of extra account attributes such as an email address and phone
|
|
|
|
* number. In that case, Smack will attempt to automatically set all required
|
|
|
|
* attributes with blank values, which may or may not be accepted by the server.
|
|
|
|
* Therefore, it's recommended to check the required account attributes and to let
|
|
|
|
* the end-user populate them with real values instead.
|
|
|
|
*
|
|
|
|
* @param username the username.
|
|
|
|
* @param password the password.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2015-08-20 19:01:33 +02:00
|
|
|
public void createAccount(Localpart username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2003-03-10 00:06:59 +01:00
|
|
|
// Create a map for all the required attributes, but give them blank values.
|
2017-12-13 23:10:11 +01:00
|
|
|
Map<String, String> attributes = new HashMap<>();
|
2006-07-18 08:47:38 +02:00
|
|
|
for (String attributeName : getAccountAttributes()) {
|
2003-03-10 00:06:59 +01:00
|
|
|
attributes.put(attributeName, "");
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
2003-03-10 00:06:59 +01:00
|
|
|
createAccount(username, password, attributes);
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Creates a new account using the specified username, password and account attributes.
|
|
|
|
* The attributes Map must contain only String name/value pairs and must also have values
|
|
|
|
* for all required attributes.
|
|
|
|
*
|
|
|
|
* @param username the username.
|
|
|
|
* @param password the password.
|
|
|
|
* @param attributes the account attributes.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException if an error occurs creating the account.
|
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
* @see #getAccountAttributes()
|
|
|
|
*/
|
2015-08-20 19:01:33 +02:00
|
|
|
public void createAccount(Localpart username, String password, Map<String, String> attributes)
|
2015-02-14 09:43:44 +01:00
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2015-02-21 16:55:30 +01:00
|
|
|
if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
|
2016-04-14 23:19:55 +02:00
|
|
|
throw new IllegalStateException("Creating account over insecure connection");
|
2015-02-21 16:55:30 +01:00
|
|
|
}
|
2015-08-20 19:01:33 +02:00
|
|
|
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());
|
2014-03-12 11:50:05 +01:00
|
|
|
attributes.put("password", password);
|
2014-09-11 23:58:07 +02:00
|
|
|
Registration reg = new Registration(attributes);
|
|
|
|
reg.setType(IQ.Type.set);
|
2015-05-18 16:48:23 +02:00
|
|
|
reg.setTo(connection().getXMPPServiceDomain());
|
2017-01-03 11:12:34 +01:00
|
|
|
createStanzaCollectorAndSend(reg).nextResultOrThrow();
|
2003-03-10 00:06:59 +01:00
|
|
|
}
|
2003-03-09 00:09:48 +01:00
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Changes the password of the currently logged-in account. This operation can only
|
|
|
|
* be performed after a successful login operation has been completed. Not all servers
|
|
|
|
* support changing passwords; an XMPPException will be thrown when that is the case.
|
|
|
|
*
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param newPassword new password.
|
|
|
|
*
|
2003-03-10 00:06:59 +01:00
|
|
|
* @throws IllegalStateException if not currently logged-in to the server.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException if an error occurs when changing the password.
|
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public void changePassword(String newPassword) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2015-02-21 16:55:30 +01:00
|
|
|
if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
|
2016-04-14 23:19:55 +02:00
|
|
|
throw new IllegalStateException("Changing password over insecure connection.");
|
2015-02-21 16:55:30 +01:00
|
|
|
}
|
2017-12-13 23:10:11 +01:00
|
|
|
Map<String, String> map = new HashMap<>();
|
2015-02-14 17:15:02 +01:00
|
|
|
map.put("username", connection().getUser().getLocalpart().toString());
|
2005-06-18 00:28:12 +02:00
|
|
|
map.put("password",newPassword);
|
2014-09-11 23:58:07 +02:00
|
|
|
Registration reg = new Registration(map);
|
|
|
|
reg.setType(IQ.Type.set);
|
2015-05-18 16:48:23 +02:00
|
|
|
reg.setTo(connection().getXMPPServiceDomain());
|
2017-01-03 11:12:34 +01:00
|
|
|
createStanzaCollectorAndSend(reg).nextResultOrThrow();
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Deletes the currently logged-in account from the server. This operation can only
|
|
|
|
* be performed after a successful login operation has been completed. Not all servers
|
|
|
|
* support deleting accounts; an XMPPException will be thrown when that is the case.
|
|
|
|
*
|
|
|
|
* @throws IllegalStateException if not currently logged-in to the server.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException if an error occurs when deleting the account.
|
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public void deleteAccount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2017-12-13 23:10:11 +01:00
|
|
|
Map<String, String> attributes = new HashMap<>();
|
2003-03-09 00:09:48 +01:00
|
|
|
// To delete an account, we add a single attribute, "remove", that is blank.
|
|
|
|
attributes.put("remove", "");
|
2014-09-11 23:58:07 +02:00
|
|
|
Registration reg = new Registration(attributes);
|
|
|
|
reg.setType(IQ.Type.set);
|
2015-05-18 16:48:23 +02:00
|
|
|
reg.setTo(connection().getXMPPServiceDomain());
|
2017-01-03 11:12:34 +01:00
|
|
|
createStanzaCollectorAndSend(reg).nextResultOrThrow();
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-27 21:14:44 +01:00
|
|
|
public boolean isSupported()
|
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
|
|
|
XMPPConnection connection = connection();
|
|
|
|
|
2017-01-07 10:37:50 +01:00
|
|
|
ExtensionElement extensionElement = connection.getFeature(Registration.Feature.ELEMENT,
|
|
|
|
Registration.Feature.NAMESPACE);
|
2016-11-27 21:14:44 +01:00
|
|
|
if (extensionElement != null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-06 14:49:58 +01:00
|
|
|
// Fallback to disco#info only if this connection is authenticated, as otherwise we won't have an full JID and
|
|
|
|
// won't be able to do IQs.
|
|
|
|
if (connection.isAuthenticated()) {
|
|
|
|
return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(Registration.NAMESPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-11-27 21:14:44 +01:00
|
|
|
}
|
|
|
|
|
2003-03-10 00:06:59 +01:00
|
|
|
/**
|
|
|
|
* Gets the account registration info from the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2003-03-10 00:06:59 +01:00
|
|
|
*
|
|
|
|
* @throws XMPPException if an error occurs.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws SmackException if there was no response from the server.
|
2003-03-10 00:06:59 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
private synchronized void getRegistrationInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2003-03-09 00:09:48 +01:00
|
|
|
Registration reg = new Registration();
|
2015-05-18 16:48:23 +02:00
|
|
|
reg.setTo(connection().getXMPPServiceDomain());
|
2017-01-03 11:12:34 +01:00
|
|
|
info = createStanzaCollectorAndSend(reg).nextResultOrThrow();
|
2014-08-11 21:09:26 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 11:12:34 +01:00
|
|
|
private StanzaCollector createStanzaCollectorAndSend(IQ req) throws NotConnectedException, InterruptedException {
|
2017-12-13 23:10:11 +01:00
|
|
|
return connection().createStanzaCollectorAndSend(new StanzaIdFilter(req.getStanzaId()), req);
|
2003-03-09 00:09:48 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|