Java Code Examples for org.jivesoftware.smack.XMPPConnection#login()

The following examples show how to use org.jivesoftware.smack.XMPPConnection#login() . 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: XmppLoginRunnable.java    From yiim_v2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public XmppResult execute() {
	XmppResult result = createResult();
	try {
		XMPPConnection connection = XmppConnectionUtils.getInstance()
				.getConnection();
		if (connection.isAuthenticated()) {
			XmppConnectionUtils.getInstance().closeConnection();
			connection = XmppConnectionUtils.getInstance().getConnection();
		}
		connection.login(mUserName, mPasswd);
		Presence presence = new Presence(mType, mStatus, 1, mMode);
		connection.sendPacket(presence);

		FileDownloadListener.setRecieveFilePath(YiFileUtils.getStorePath()
				+ "yiim/" + mUserName + "file_recv/");

		result.status = Status.SUCCESS;
	} catch (Exception e) {
		result.obj = e.getMessage();
	}
	return result;
}
 
Example 2
Source File: MPAuthenticationProvider.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Login to the XMPP server with the credentials specifid in the Identity.xml
 *
 * @param connection
 * @return
 */
public boolean login(XMPPConnection connection) {
    String userName = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_USERNAME);
    String password = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_PASSWORD);
    for (int i = 0; i < 3; i++) {
        try {
            connection.login(userName, password, null);
            return true;
        } catch (XMPPException ex) {
            log.error("login failed. Trying again..", ex);
        }
    }
    return false;
}
 
Example 3
Source File: IMAppender.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
@Override
public void activateOptions() {
    try {
        cb = new CyclicBuffer(bufferSize);

        // Create a connection to the XMPP server
        LogLog.debug("Stablishing connection with XMPP server");
        con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());
        // Most servers require you to login before performing other tasks
        LogLog.debug("About to login as [" + username + "/" + password + "]");
        con.connect();
        con.login(username, password);

        // Start a conversation with IMAddress
        if (chatroom) {
            LogLog.debug("About to create ChatGroup");
            groupchat = new MultiUserChat(con, (String) recipientsList.get(0));
            LogLog.debug("About to join room");
            groupchat.join(nickname != null ? nickname : username);
        } else {
            final Iterator iter = recipientsList.iterator();
            while (iter.hasNext()) {
                chats.add(con.getChatManager().createChat((String) iter.next(), null));
            }
            // chat = con.createChat(recipients);
        }

    } catch (final XMPPException xe) {
        errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: "
                + getUsername(), xe, ErrorCode.GENERIC_FAILURE);
    } catch (final Exception e) {
        errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE);
    }
}
 
Example 4
Source File: IMAppender.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
@Override
public void activateOptions() {
    try {
        cb = new CyclicBuffer(bufferSize);

        // Create a connection to the XMPP server
        LogLog.debug("Stablishing connection with XMPP server");
        con = new XMPPConnection(InstantMessagingModule.getConnectionConfiguration());
        // Most servers require you to login before performing other tasks
        LogLog.debug("About to login as [" + username + "/" + password + "]");
        con.connect();
        con.login(username, password);

        // Start a conversation with IMAddress
        if (chatroom) {
            LogLog.debug("About to create ChatGroup");
            groupchat = new MultiUserChat(con, (String) recipientsList.get(0));
            LogLog.debug("About to join room");
            groupchat.join(nickname != null ? nickname : username);
        } else {
            final Iterator iter = recipientsList.iterator();
            while (iter.hasNext()) {
                chats.add(con.getChatManager().createChat((String) iter.next(), null));
            }
            // chat = con.createChat(recipients);
        }

    } catch (final XMPPException xe) {
        errorHandler.error("Error while activating options for appender named [" + name + "] Could not connect to instant messaging server with user: "
                + getUsername(), xe, ErrorCode.GENERIC_FAILURE);
    } catch (final Exception e) {
        errorHandler.error("Error while activating options for appender named [" + name + "]", e, ErrorCode.GENERIC_FAILURE);
    }
}
 
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: RiotLogin.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
public void login(XMPPConnection connection, String username,
		String password, boolean replaceLeague) {
	try {
		if (replaceLeague) {
			connection.login(username, "AIR_" + password, "xiff");
		} else {
			connection.login(username, "AIR_" + password);
		}
	} catch (XMPPException | SmackException | IOException e) {
		e.printStackTrace();
	}
}
 
Example 7
Source File: GarenaLogin.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
@Override
public void login(XMPPConnection connection, String username,
		String password, boolean replaceLeague) {
	password = username.substring(username.length() - 5);
	try {
		if (replaceLeague) {
			connection.login(username, "AIR_pass" + password, "xiff");
		} else {
			connection.login(username, "AIR_pass" + password);
		}
	} catch (XMPPException | SmackException | IOException e) {
		e.printStackTrace();
	}
}