Search in sources :

Example 1 with AccountManager

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

Example 2 with AccountManager

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();
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager)

Example 3 with AccountManager

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);
}
Also used : HashMap(java.util.HashMap) Localpart(org.jxmpp.jid.parts.Localpart) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 4 with AccountManager

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();
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) AccountRegistration(org.igniterealtime.smack.inttest.Configuration.AccountRegistration) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException)

Aggregations

AccountManager (org.jivesoftware.smackx.iqregister.AccountManager)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 AccountRegistration (org.igniterealtime.smack.inttest.Configuration.AccountRegistration)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)1 XMPPTCPConnectionConfiguration (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)1 Localpart (org.jxmpp.jid.parts.Localpart)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1