use of org.jivesoftware.smack.tcp.XMPPTCPConnection in project Smack by igniterealtime.
the class LoginIntegrationTest method testInvalidLogin.
/**
* 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());
}
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnection in project camel by apache.
the class XmppEndpoint method createConnectionInternal.
private XMPPTCPConnection createConnectionInternal() {
if (connectionConfig != null) {
return new XMPPTCPConnection(connectionConfig);
}
if (port == 0) {
port = 5222;
}
String sName = getServiceName() == null ? host : getServiceName();
ConnectionConfiguration conf = new ConnectionConfiguration(host, port, sName);
return new XMPPTCPConnection(conf);
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnection in project Smack by igniterealtime.
the class TlsTest method tlsTest.
public static boolean tlsTest(EntityBareJid jid, String password, String host, int port, String tlsPin, boolean shouldThrow) throws KeyManagementException, NoSuchAlgorithmException {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
// @formatter:off
builder.setUsernameAndPassword(jid.getLocalpart(), password).setXmppDomain(JidCreate.domainBareFrom(jid.getDomain())).setHost(host).setPort(port).setSecurityMode(SecurityMode.required);
// @formatter:on
builder.setDebuggerEnabled(DEBUG);
if (StringUtils.isNotEmpty(tlsPin)) {
SSLContext sslContext = Java7Pinning.forPin(tlsPin);
builder.setCustomSSLContext(sslContext);
}
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
connection.setReplyTimeout(20000);
try {
connection.connect().login();
if (shouldThrow) {
// Test not success, should have throwed on login().
return false;
}
} catch (SecurityRequiredByClientException e) {
if (!shouldThrow) {
return false;
}
} catch (XMPPException | SmackException | IOException | InterruptedException e) {
throw new IllegalStateException(e);
} finally {
connection.disconnect();
}
return true;
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnection in project Smack by igniterealtime.
the class XmppTools method supportsIbr.
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();
}
}
use of org.jivesoftware.smack.tcp.XMPPTCPConnection 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();
}
}
Aggregations