Search in sources :

Example 6 with XMPPTCPConnection

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());
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SASLErrorException(org.jivesoftware.smack.sasl.SASLErrorException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 7 with XMPPTCPConnection

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

Example 8 with XMPPTCPConnection

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;
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SmackException(org.jivesoftware.smack.SmackException) SecurityRequiredByClientException(org.jivesoftware.smack.SmackException.SecurityRequiredByClientException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 9 with XMPPTCPConnection

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

Example 10 with XMPPTCPConnection

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

Aggregations

XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)13 XMPPTCPConnectionConfiguration (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)6 KeyManagementException (java.security.KeyManagementException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 SmackException (org.jivesoftware.smack.SmackException)4 XMPPException (org.jivesoftware.smack.XMPPException)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SSLContext (javax.net.ssl.SSLContext)3 UsernameAndPassword (org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword)2 ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 Builder (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder)2 AccountRosterListener (com.xabber.android.data.roster.AccountRosterListener)1 MemorizingTrustManager (de.duenndns.ssl.MemorizingTrustManager)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 SmackConfiguration (org.jivesoftware.smack.SmackConfiguration)1