private XMPPConnection login(final Configuration config) throws IOException, XMPPException, SmackException, KeyManagementException, NoSuchAlgorithmException { final String serviceName = isNullOrEmpty(config.getString(CK_SERVICE_NAME)) ? config.getString(CK_HOSTNAME) : config.getString(CK_SERVICE_NAME); final XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder() .setHost(config.getString(CK_HOSTNAME)) .setPort(config.getInt(CK_PORT)) .setServiceName(serviceName) .setSendPresence(false); if (config.getBoolean(CK_ACCEPT_SELFSIGNED)) { TLSUtils.acceptAllCertificates(configBuilder); } final boolean requireSecurity = config.getBoolean(CK_REQUIRE_SECURITY); configBuilder.setSecurityMode(requireSecurity ? ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.ifpossible); final XMPPTCPConnectionConfiguration connectionConfiguration = configBuilder.build(); if (LOG.isDebugEnabled()) { LOG.debug("Supported SASL authentications: {}", SASLAuthentication.getRegisterdSASLMechanisms()); LOG.debug("require_security: {}", requireSecurity); LOG.debug("Security mode: {}", connectionConfiguration.getSecurityMode()); LOG.debug("Socket factory: {}", connectionConfiguration.getSocketFactory()); LOG.debug("Keystore: {}", connectionConfiguration.getKeystorePath()); LOG.debug("Keystore type: {}", connectionConfiguration.getKeystoreType()); } final XMPPTCPConnection xmppConnection = new XMPPTCPConnection(connectionConfiguration); xmppConnection.connect(); xmppConnection.login(config.getString(CK_USERNAME), config.getString(CK_PASSWORD)); return xmppConnection; }