if (verifier == null) { throw new IllegalStateException("No HostnameVerifier set. Use connectionConfiguration.setHostnameVerifier() to configure."); } else if (!verifier.verify(getXMPPServiceDomain().toString(), sslSocket.getSession())) { throw new CertificateException("Hostname verification of certificate failed. Certificate does not authenticate " + getXMPPServiceDomain());
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); }
/** * Resets the parser using the latest connection's reader. Resetting the parser is necessary * when the plain connection has been secured or when a new opening stream element is going * to be sent by the server. * * @throws SmackException if the parser could not be reset. * @throws InterruptedException */ void openStream() throws SmackException, InterruptedException { // If possible, provide the receiving entity of the stream open tag, i.e. the server, as much information as // possible. The 'to' attribute is *always* available. The 'from' attribute if set by the user and no external // mechanism is used to determine the local entity (user). And the 'id' attribute is available after the first // response from the server (see e.g. RFC 6120 § 9.1.1 Step 2.) CharSequence to = getXMPPServiceDomain(); CharSequence from = null; CharSequence localpart = config.getUsername(); if (localpart != null) { from = XmppStringUtils.completeJidFrom(localpart, to); } String id = getStreamId(); sendNonza(new StreamOpen(to, from, id)); try { packetReader.parser = PacketParserUtils.newXmppParser(reader); } catch (XmlPullParserException e) { throw new SmackException(e); } }
@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); } } }