use of org.jxmpp.jid.parts.Localpart in project Smack by igniterealtime.
the class XmppConnectionManager method registerAccount.
private void registerAccount(String username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, XmppStringprepException {
if (accountRegistrationConnection == null) {
throw new IllegalStateException("Account registration not configured");
}
switch(sinttestConfiguration.accountRegistration) {
case serviceAdministration:
EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username), accountRegistrationConnection.getXMPPServiceDomain());
adminManager.addUser(userJid, password);
break;
case inBandRegistration:
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 = Localpart.from(username);
accountManager.createAccount(usernameLocalpart, password, additionalAttributes);
break;
case disabled:
throw new IllegalStateException("Account creation no possible");
}
}
use of org.jxmpp.jid.parts.Localpart 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.jxmpp.jid.parts.Localpart in project Smack by igniterealtime.
the class XmppConnectionManager method disconnectAndCleanup.
void disconnectAndCleanup() throws InterruptedException {
int successfullyDeletedAccountsCount = 0;
for (AbstractXMPPConnection connection : connections.keySet()) {
if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {
// Note that we use the account manager from the to-be-deleted connection.
AccountManager accountManager = AccountManager.getInstance(connection);
try {
accountManager.deleteAccount();
successfullyDeletedAccountsCount++;
} catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
}
}
connection.disconnect();
if (sinttestConfiguration.accountRegistration == AccountRegistration.serviceAdministration) {
String username = connection.getConfiguration().getUsername().toString();
Localpart usernameAsLocalpart;
try {
usernameAsLocalpart = Localpart.from(username);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
EntityBareJid connectionAddress = JidCreate.entityBareFrom(usernameAsLocalpart, sinttestConfiguration.service);
try {
adminManager.deleteUser(connectionAddress);
successfullyDeletedAccountsCount++;
} catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
}
}
}
if (sinttestConfiguration.isAccountRegistrationPossible()) {
int unsuccessfullyDeletedAccountsCount = connections.size() - successfullyDeletedAccountsCount;
if (unsuccessfullyDeletedAccountsCount == 0) {
LOGGER.info("Successfully deleted all created accounts ✔");
} else {
LOGGER.warning("Could not delete all created accounts, " + unsuccessfullyDeletedAccountsCount + " remainaing");
}
}
connections.clear();
if (accountRegistrationConnection != null) {
accountRegistrationConnection.disconnect();
}
}
use of org.jxmpp.jid.parts.Localpart in project Smack by igniterealtime.
the class XmppTools method createAccount.
public static boolean createAccount(String xmppDomain, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException {
DomainBareJid xmppDomainJid = JidCreate.domainBareFrom(xmppDomain);
Localpart localpart = Localpart.from(username);
return createAccount(xmppDomainJid, localpart, password);
}
Aggregations