Search in sources :

Example 1 with ServiceAdministrationManager

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);
    }
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 2 with ServiceAdministrationManager

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);
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Aggregations

ServiceAdministrationManager (org.jivesoftware.smackx.admin.ServiceAdministrationManager)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 IOException (java.io.IOException)1 SmackException (org.jivesoftware.smack.SmackException)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1