Java Code Examples for org.jivesoftware.smack.ConnectionConfiguration#setSASLAuthenticationEnabled()

The following examples show how to use org.jivesoftware.smack.ConnectionConfiguration#setSASLAuthenticationEnabled() . 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: XmppManager.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 与服务器建立连接
 * 
 * @return
 */
public boolean connectServer() {
	ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort));
	//设置安全模式
	connConfig.setSecurityMode(SecurityMode.required);
	//设置SASL认证是否启用
	connConfig.setSASLAuthenticationEnabled(false);
	//设置数据压缩是否启用
	connConfig.setCompressionEnabled(false);
	//是否启用调试模式
	connConfig.setDebuggerEnabled(true);

	/** 创建connection连接 */
	XMPPConnection connection = new XMPPConnection(connConfig);
	this.setConnection(connection);

	try {
		// 连接到服务器
		connection.connect();
		L.i(LOGTAG, "XMPP connected successfully");
		return true;
	} catch (XMPPException e) {
		L.e(LOGTAG, "XMPP connection failed", e);
	}
	return false;
}
 
Example 2
Source File: XmppTool.java    From xmpp with Apache License 2.0 5 votes vote down vote up
/**
 * <b>function:</b> ��ʼSmack��openfire���������ӵĻ�������
 * 
 * @author hoojo
 * @createDate 2012-6-25 ����04:06:42
 */

public static void init() {
	try {
		// connection = new XMPPConnection(server);
		// connection.connect();

		/**
		 * 5222��openfire������Ĭ�ϵ�ͨ�Ŷ˿ڣ�����Ե�¼http://192.168.8.32:9090/
		 * ������Ա����̨�鿴�ͻ��˵��������˿�
		 */
		config = new ConnectionConfiguration(server, 5222);

		/** �Ƿ�����ѹ�� */
		config.setCompressionEnabled(true);
		/** �Ƿ����ð�ȫ��֤ */
		config.setSASLAuthenticationEnabled(false);
		/** �Ƿ����õ��� */
		config.setDebuggerEnabled(false);
		// config.setReconnectionAllowed(true);
		// config.setRosterLoadedAtLogin(true);

		/** ����connection���� */
		connection = new XMPPConnection(config);
		/** �������� */
		connection.connect();
	} catch (XMPPException e) {
		e.printStackTrace();
	}
	// fail(connection);
	// fail(connection.getConnectionID());
}
 
Example 3
Source File: XmppManager.java    From androidpn-client with Apache License 2.0 5 votes vote down vote up
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");
    boolean connected = false;
    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());
            connected = true;

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        if (connected) {
            xmppManager.runTask();
        }

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
 
Example 4
Source File: MPAuthenticationProvider.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection to the XMPP server with the available configuration details given in
 * the identity.xml
 *
 * @return XMPPConnection
 */
private XMPPConnection createConnection() {
    String xmppServer = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_SERVER);
    int xmppPort = Integer.parseInt(IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_PORT));
    String xmppExt = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_EXT);

    ConnectionConfiguration config = new ConnectionConfiguration(xmppServer, xmppPort, xmppExt);
    config.setSASLAuthenticationEnabled(true);
    return new XMPPConnection(config);
}
 
Example 5
Source File: ClientConService.java    From weixin with Apache License 2.0 5 votes vote down vote up
public boolean login(String account, String password) {
	ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort));
	//设置安全模式
	connConfig.setSecurityMode(SecurityMode.required);
	//设置SASL认证是否启用
	connConfig.setSASLAuthenticationEnabled(false);
	//设置数据压缩是否启用
	connConfig.setCompressionEnabled(false);
	//是否启用调试模式
	connConfig.setDebuggerEnabled(true);

	/** 创建connection连接 */
	XMPPConnection connection = new XMPPConnection(connConfig);
	setConnection(connection);

	try {
		// 连接到服务器
		connection.connect();
		L.i(LOGTAG, "XMPP connected successfully");

		//登陆
		connection.login(account, password);

		/** 开启读写线程,并加入到管理类中 */
		//ClientSendThread cst = new ClientSendThread(connection);
		//cst.start();
		//ManageClientThread.addClientSendThread(account,cst);

		return true;
	} catch (XMPPException e) {
		L.e(LOGTAG, "XMPP connection failed", e);
	}
	return false;
}
 
Example 6
Source File: XmppManager.java    From android-demo-xmpp-androidpn with Apache License 2.0 4 votes vote down vote up
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {		//未连接到XMPP服务器
        // Create the configuration for this new connection
    	/**
    	 * 设置连接的一些参数
    	 */
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            /** 
             * 这个就是对于通信的xml文本进行解析的解析器,再把信息转换成IQ,这个相当于QQ的聊天信息 
             * 如果要用这个协议,其IQ的子类(NotificationIQ)
             * 和IQProvider的子类(NotificationIQProvider)要进行重写 
             */
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
            running = false;
        }
        //执行任务
        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        //执行任务
        xmppManager.runTask();
    }
}