use of org.jivesoftware.smackx.iqregister.AccountManager in project Smack by igniterealtime.
the class IntTestUtil method deleteViaIbr.
public static void deleteViaIbr(XMPPTCPConnection connection) throws InterruptedException {
// mechanisms
if (!connection.isConnected()) {
try {
connection.connect().login();
} catch (XMPPException | SmackException | IOException e) {
LOGGER.log(Level.WARNING, "Exception reconnection account for deletion", e);
}
}
final int maxAttempts = 3;
AccountManager am = AccountManager.getInstance(connection);
int attempts;
for (attempts = 0; attempts < maxAttempts; attempts++) {
try {
am.deleteAccount();
} catch (XMPPErrorException | NoResponseException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
} catch (NotConnectedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
try {
connection.connect().login();
} catch (XMPPException | SmackException | IOException e2) {
LOGGER.log(Level.WARNING, "Exception while trying to re-connect " + connection, e);
}
continue;
}
LOGGER.info("Successfully deleted account of " + connection);
break;
}
if (attempts > maxAttempts) {
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
}
}
use of org.jivesoftware.smackx.iqregister.AccountManager in project Smack by igniterealtime.
the class XmppTools method createAccount.
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password) throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException {
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder().setXmppDomain(xmppDomain);
TLSUtils.acceptAllCertificates(configBuilder);
XMPPTCPConnectionConfiguration config = configBuilder.build();
XMPPTCPConnection connection = new XMPPTCPConnection(config);
connection.connect();
try {
if (!supportsIbr(connection))
return false;
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(username, password);
return true;
} finally {
connection.disconnect();
}
}
use of org.jivesoftware.smackx.iqregister.AccountManager in project Smack by igniterealtime.
the class IntTestUtil method registerAccountViaIbr.
public static UsernameAndPassword registerAccountViaIbr(XMPPConnection connection, String username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
AccountManager accountManager = AccountManager.getInstance(connection);
if (!accountManager.supportsAccountCreation()) {
throw new UnsupportedOperationException("Account creation/registation is not supported");
}
Set<String> requiredAttributes = accountManager.getAccountAttributes();
if (requiredAttributes.size() > 4) {
throw new IllegalStateException("Unkown required attributes");
}
Map<String, String> additionalAttributes = new HashMap<>();
additionalAttributes.put("name", "Smack Integration Test");
additionalAttributes.put("email", "flow@igniterealtime.org");
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);
}
use of org.jivesoftware.smackx.iqregister.AccountManager in project Smack by igniterealtime.
the class IntTestUtil method disconnectAndMaybeDelete.
public static void disconnectAndMaybeDelete(XMPPTCPConnection connection, Configuration config) throws InterruptedException {
try {
if (!config.isAccountRegistrationPossible()) {
return;
}
Configuration.AccountRegistration accountDeletionMethod = config.accountRegistration;
AccountManager accountManager = AccountManager.getInstance(connection);
try {
if (accountManager.isSupported()) {
accountDeletionMethod = AccountRegistration.inBandRegistration;
}
} catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could not test if XEP-0077 account deletion is possible", e);
}
switch(accountDeletionMethod) {
case inBandRegistration:
deleteViaIbr(connection);
break;
case serviceAdministration:
deleteViaServiceAdministration(connection, config);
break;
default:
throw new AssertionError();
}
} finally {
connection.disconnect();
}
}
Aggregations