Java Code Examples for org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration#Builder

The following examples show how to use org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppLogin.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {

		try {

			DebugUtil.debug("login:" + getUsername() + "--" + getPassword() + "--" + Launcher.HOSTPORT + "--"
					+ Launcher.DOMAIN + "--" + InetAddress.getByName(Launcher.HOSTNAME));

			XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()
					.setUsernameAndPassword(getUsername(), getPassword()).setResource(Launcher.RESOURCE)
					.setPort(Launcher.HOSTPORT).setConnectTimeout(5000).setXmppDomain(Launcher.DOMAIN)
					.setHost(Launcher.HOSTNAME).setHostAddress(InetAddress.getByName(Launcher.HOSTNAME)) .setSecurityMode(SecurityMode.disabled)
					.setDebuggerEnabled(true).setSendPresence(true);
			DebugUtil.debug("builder:" + builder.toString());
			return builder.build();

		} catch (Exception e) {

			e.printStackTrace();
		}
		return null;
	}
 
Example 2
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
private KeyStore configKeyStore(XMPPTCPConnectionConfiguration.Builder builder) throws KeyStoreException {
    KeyStore keyStore;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setKeystorePath(null);
        builder.setKeystoreType("AndroidCAStore");
        keyStore = KeyStore.getInstance("AndroidCAStore");
    } else {
        builder.setKeystoreType("BKS");
        keyStore = KeyStore.getInstance("BKS");

        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                    + File.separator + "security" + File.separator
                    + "cacerts.bks";
        builder.setKeystorePath(path);
    }
    return keyStore;
}
 
Example 3
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 4
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
private void configSSLContext(XMPPTCPConnectionConfiguration.Builder builder, KeyStore keyStore) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    TrustManagerFactory trustManagerFactory = TrustManagerFactory
            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keyStore);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

    builder.setCustomSSLContext(sslContext);
}
 
Example 5
Source File: XMPP.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException {
    XMPPTCPConnectionConfiguration.Builder builder =
            XMPPTCPConnectionConfiguration.builder();


    builder.setHost(HOST1);
    builder.setPort(PORT);
    builder.setCompressionEnabled(false);
    builder.setDebuggerEnabled(true);
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    builder.setSendPresence(true);
    if (Build.VERSION.SDK_INT >= 14) {
        builder.setKeystoreType("AndroidCAStore");
        // config.setTruststorePassword(null);
        builder.setKeystorePath(null);
    } else {
        builder.setKeystoreType("BKS");
        String str = System.getProperty("javax.net.ssl.trustStore");
        if (str == null) {
            str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
                    + File.separator + "cacerts.bks";
        }
        builder.setKeystorePath(str);
    }
    DomainBareJid serviceName = JidCreate.domainBareFrom(HOST);
    builder.setServiceName(serviceName);


    return builder.build();
}
 
Example 6
Source File: XmppTools.java    From Smack with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: SmackIntegrationTestFramework.java    From Smack with Apache License 2.0 3 votes vote down vote up
static XMPPTCPConnectionConfiguration.Builder getConnectionConfigurationBuilder(Configuration config) {
    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();

    config.configurationApplier.applyConfigurationTo(builder);

    return builder;
}