use of org.jivesoftware.smackx.admin.ServiceAdministrationManager in project Smack by igniterealtime.
the class IntTestUtil method deleteViaServiceAdministration.
public static void deleteViaServiceAdministration(XMPPTCPConnection connection, Configuration config) {
EntityBareJid accountToDelete = connection.getUser().asEntityBareJid();
final int maxAttempts = 3;
int attempts;
for (attempts = 0; attempts < maxAttempts; attempts++) {
connection.disconnect();
try {
connection.connect().login(config.adminAccountUsername, config.adminAccountPassword);
} catch (XMPPException | SmackException | IOException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
try {
adminManager.deleteUser(accountToDelete);
} catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
}
if (attempts > maxAttempts) {
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
}
}
use of org.jivesoftware.smackx.admin.ServiceAdministrationManager in project Smack by igniterealtime.
the class IntTestUtil method registerAccountViaAdmin.
// public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection) throws XmppStringprepException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// return registerAccountViaAdmin(connection, StringUtils.insecureRandomString(12),
// StringUtils.insecureRandomString(12));
// }
public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection, String username, String password, String adminAccountUsername, String adminAccountPassword) throws InterruptedException, XMPPException, SmackException, IOException {
connection.login(adminAccountUsername, adminAccountPassword);
ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username), connection.getServiceName());
adminManager.addUser(userJid, password);
connection.disconnect();
connection.connect();
return new UsernameAndPassword(username, password);
}
Aggregations