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); break; } 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); } }
static XMPPTCPConnection getConnectedConnection(SmackIntegrationTestEnvironment environment, int connectionId) throws KeyManagementException, NoSuchAlgorithmException, InterruptedException, SmackException, IOException, XMPPException { Configuration config = environment.configuration; XMPPTCPConnectionConfiguration.Builder builder = getConnectionConfigurationBuilder(config); XMPPTCPConnection connection = new XMPPTCPConnection(builder.build()); connection.connect(); UsernameAndPassword uap = IntTestUtil.registerAccount(connection, environment, connectionId); connection.login(uap.username, uap.password); return connection; }
public static boolean supportsIbr(DomainBareJid xmppDomain) throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException { XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder() .setXmppDomain(xmppDomain); TLSUtils.acceptAllCertificates(configBuilder); XMPPTCPConnectionConfiguration config = configBuilder.build(); XMPPTCPConnection connection = new XMPPTCPConnection(config); connection.connect(); try { return supportsIbr(connection); } finally { connection.disconnect(); } }
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.getXMPPServiceDomain()); adminManager.addUser(userJid, password); connection.disconnect(); connection.connect(); return new UsernameAndPassword(username, password); }
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(); } } }
/** * Check that the server is returning the correct error when trying to login using an invalid * (i.e. non-existent) user. * * @throws InterruptedException * @throws XMPPException * @throws IOException * @throws SmackException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ @SmackIntegrationTest public void testInvalidLogin() throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException { final String nonExistentUserString = StringUtils.insecureRandomString(24); XMPPTCPConnectionConfiguration conf = getConnectionConfiguration().setUsernameAndPassword( nonExistentUserString, "invalidPassword").build(); XMPPTCPConnection connection = new XMPPTCPConnection(conf); connection.connect(); try { connection.login(); fail("Exception expected"); } catch (SASLErrorException e) { assertEquals(SASLError.not_authorized, e.getSASLFailure().getSASLError()); } }
@SmackIntegrationTest public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException { final String body1 = "Hi, what's up? " + testRunId; final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId; final String body3 = "Hi, what's up? I've been just resumed" + testRunId; final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter( MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser()))); try { send(body1, conOne, conTwo); assertMessageWithBodyReceived(body1, collector); conOne.instantShutdown(); send(body2, conOne, conTwo); // Reconnect with xep198 conOne.connect().login(); assertMessageWithBodyReceived(body2, collector); send(body3, conOne, conTwo); assertMessageWithBodyReceived(body3, collector); } finally { collector.cancel(); } }
/*Example solution. The exact settings would have to be adjusted outside of practice*/ XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration .builder() .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) .setServiceName("192.168.2.14") .setHost("192.168.2.14") .setPort(5222) .setCompressionEnabled(false).build(); XMPPTCPConnection connection = new XMPPTCPConnection(conf); try { connection.connect(); connection.login("john","123"); ...
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString, String readingThingPassword, IotScenario scenario) throws Exception { final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString); final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString); final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder() .setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword) .setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled) .enableDefaultDebugger().build(); final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration .builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword) .setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled) .enableDefaultDebugger().build(); final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration); final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration); dataThingConnection.setReplyTimeout(TIMEOUT); readingThingConnection.setReplyTimeout(TIMEOUT); dataThingConnection.setUseStreamManagement(false); readingThingConnection.setUseStreamManagement(false); try { dataThingConnection.connect().login(); readingThingConnection.connect().login(); scenario.iotScenario(dataThingConnection, readingThingConnection); } finally { dataThingConnection.disconnect(); readingThingConnection.disconnect(); } }
connection.connect().login(); if (shouldThrow) {
@SmackIntegrationTest public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException { final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection); if (!bookmarkManager.isSupported()) { throw new TestNotPossibleException("Private data storage not supported"); } final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection); final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6)); final String randomMucName = StringUtils.randomString(6); final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0); final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom( Localpart.from(randomMucName), mucComponent)); MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname); if (handle != null) { handle.makeInstant(); } muc.leave(); bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null); connection.disconnect(); connection.connect().login(); // MucBookmarkAutojoinManager is also able to do its task automatically // after every login, it's not deterministic when this will be finished. // So we trigger it manually here. MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences(); assertTrue(muc.isJoined()); // If the test went well, leave the MUC muc.leave(); }
@Override public void start() { synchronized (this.lifecycleMonitor) { if (this.running) { return; } XMPPTCPConnection connection = getConnection(); try { connection.connect(); connection.addConnectionListener(new LoggingConnectionListener()); Roster roster = Roster.getInstanceFor(connection); if (this.subscriptionMode != null) { roster.setSubscriptionMode(this.subscriptionMode); } else { roster.setRosterLoadedAtLogin(false); } connection.login(); this.running = true; } catch (Exception e) { throw new BeanInitializationException("failed to connect to XMPP service for " + connection.getXMPPServiceDomain(), e); } } }
@Override protected void onActivate() throws XMPPException, IOException, SmackException { if (!connection.isConnected()) { try { connection.connect(); } catch (InterruptedException e) { throw new IOException(e); } } }
@Override protected void onActivate() throws XMPPException, IOException, SmackException { if (!connection.isConnected()) { try { connection.connect(); } catch (InterruptedException e) { throw new IOException(e); } } }
@Override public void connect() throws SmackException, IOException, XMPPException { super.connect(); login(username, "AIR_" + pass, "xiff"); }
@Override protected void onActivate() throws XMPPException, IOException, SmackException { if (!connection.isConnected()) { try { connection.connect(); } catch (InterruptedException e) { throw new IOException(e); } } }
XMPPTCPConnection connection = new XMPPTCPConnection(config); connection.connect(); connection.login(ID1, password1); Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence);
ConnectionConfiguration config = new ConnectionConfiguration(server, port); //... any other stuff you need //very basic security stuff just to get you going... config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); XMPPTCPConnection connection = new XMPPTCPConnection(config); SASLAuthentication.supportSASLMechanism("DIGEST-MD5", 0); connection.connect(); //... any other stuff you want connection.login(user, passw);