Tigase用户登录

src/main/java/tigase/db/jdbc/TigaseCustomAuth.java

/**
	 * Performs user login. Normally used when there is a special SP used for this
	 * purpose. This is an alternative way to a method requiring retrieving user
	 * password. Therefore at least one of those queries must be defined:
	 * <code>user-login-query</code> or <code>get-password-query</code>.
	 *
	 * If both queries are defined then <code>user-login-query</code> is used.
	 * Normally this method should be only used with plain text password
	 * authentication or sasl-plain.
	 *
	 * The Tigase server expects a result set with user_id to be returned from the
	 * query if login is successful and empty results set if the login is
	 * unsuccessful.
	 *
	 * Takes 2 arguments: <code>(user_id (JID), password)</code>
	 *
	 * Example query:
	 *
	 * <pre>
	 * select user_id from tig_users where (user_id = ?) AND (user_pw = ?)
	 * </pre>
	 */
	public static final String DEF_USERLOGIN_KEY = "user-login-query";
/** Field description */
	public static final String DEF_USERLOGIN_QUERY = "{ call TigUserLoginPlainPw(?, ?) }";

// ~--- methods --------------------------------------------------------------

	@Override
	public void initRepository(final String connection_str, Map<String, String> params)
			throws DBInitException {
		try {
			data_repo = RepositoryFactory.getDataRepository(null, connection_str, params);
			initdb_query = getParamWithDef(params, DEF_INITDB_KEY, DEF_INITDB_QUERY);

			if (initdb_query != null) {
				data_repo.initPreparedStatement(initdb_query, initdb_query);
			}

			adduser_query = getParamWithDef(params, DEF_ADDUSER_KEY, DEF_ADDUSER_QUERY);

			if ((adduser_query != null)) {
				data_repo.initPreparedStatement(adduser_query, adduser_query);
			}

			deluser_query = getParamWithDef(params, DEF_DELUSER_KEY, DEF_DELUSER_QUERY);

			if ((deluser_query != null)) {
				data_repo.initPreparedStatement(deluser_query, deluser_query);
			}

			getpassword_query = getParamWithDef(params, DEF_GETPASSWORD_KEY, DEF_GETPASSWORD_QUERY);

			if ((getpassword_query != null)) {
				data_repo.initPreparedStatement(getpassword_query, getpassword_query);
			}

			updatepassword_query =
					getParamWithDef(params, DEF_UPDATEPASSWORD_KEY, DEF_UPDATEPASSWORD_QUERY);

			if ((updatepassword_query != null)) {
				data_repo.initPreparedStatement(updatepassword_query, updatepassword_query);
			}

			userlogin_query = getParamWithDef(params, DEF_USERLOGIN_KEY, DEF_USERLOGIN_QUERY);
			if (userlogin_query  != null) {
				data_repo.initPreparedStatement(userlogin_query, userlogin_query);//查询数据库,调用TigUserLoginPlainPw 方法对账号密码进行校验
				userlogin_active = true;
			}//登录验证位置

			userlogout_query =
					getParamWithDef(params, DEF_USERLOGOUT_KEY, DEF_USERLOGOUT_QUERY);

			if ((userlogout_query != null)) {
				data_repo.initPreparedStatement(userlogout_query, userlogout_query);
			}

			userscount_query =
					getParamWithDef(params, DEF_USERS_COUNT_KEY, DEF_USERS_COUNT_QUERY);

			if ((userscount_query != null)) {
				data_repo.initPreparedStatement(userscount_query, userscount_query);
			}

			userdomaincount_query =
					getParamWithDef(params, DEF_USERS_DOMAIN_COUNT_KEY,
							DEF_USERS_DOMAIN_COUNT_QUERY);

			if ((userdomaincount_query != null)) {
				data_repo.initPreparedStatement(userdomaincount_query, userdomaincount_query);
			}

			nonsasl_mechs =
					getParamWithDef(params, DEF_NONSASL_MECHS_KEY, DEF_NONSASL_MECHS).split(",");
			sasl_mechs = getParamWithDef(params, DEF_SASL_MECHS_KEY, DEF_SASL_MECHS).split(",");

			if ((params != null) && (params.get("init-db") != null)) {
				initDb();
			}
		} catch (Exception e) {
			data_repo = null;

			throw new DBInitException(
					"Problem initializing jdbc connection: " + connection_str, e);
		}
	}

src/main/java/tigaase/db/derby/StoredProcedures.java

/**
	 * Method description
	 *
	 *账号密码MD5解密,客户端传输过来的账号密码是经过MD5加密过的
	 * @param userId
	 * @param userPw
	 * @param data
	 *
	 * @throws SQLException
	 */
	public static void tigUserLoginPlainPw(String userId, String userPw, ResultSet[] data)
			throws SQLException {
		String encMethod = tigGetDBProperty("password-encoding");
		String encp = encodePassword(encMethod, userId, userPw);

		tigUserLogin(userId, encp, data);
	}

数据库查询

/**
	 * Method description
	 *
	 *
	 * @param userId
	 * @param userPw
	 * @param data
	 *
	 * @throws SQLException
	 */
	public static void tigUserLogin(String userId, String userPw, ResultSet[] data)
			throws SQLException {
		Connection conn = DriverManager.getConnection("jdbc:default:connection");

		conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

		try {
			PreparedStatement ps =
				conn.prepareStatement("select user_id from tig_users where (account_status > 0) AND ( lower(user_id) = ?) AND (user_pw = ?)");

			ps.setString(1, userId.toLowerCase());
			ps.setString(2, userPw);

			ResultSet rs = ps.executeQuery();

			if (rs.next()) {
				PreparedStatement x = conn.prepareStatement("values '" + userId + "'");

				data[0] = x.executeQuery();

				PreparedStatement flps =
					conn.prepareStatement("update tig_users set online_status = online_status + 1, last_login = current timestamp where lower(user_id) =  ?");

				flps.setString(1, userId.toLowerCase());
				flps.executeUpdate();
			} else {
				PreparedStatement x = conn.prepareStatement("values '-'");

				data[0] = x.executeQuery();

				PreparedStatement flps =
					conn.prepareStatement("update tig_users set failed_logins = failed_logins + 1 where lower(user_id) = ?");

				flps.setString(1, userId.toLowerCase());
				flps.executeUpdate();
			}
		} catch (SQLException e) {

			// e.printStackTrace();
			// log.log(Level.SEVERE, "SP error", e);
			throw e;
		} finally {
			conn.close();
		}
	}

客户端调用 login方法后
发包
在这里插入图片描述
服务器响应代码
在这里插入图片描述
另:限制问题(发消息或其他发包、不确认)
在这里插入图片描述
https://my.oschina.net/greki/blog/264573?utm_source=debugrun&utm_medium=referral tigase的每个连接消息量限制配置

现象:

一个客户端一次循环发送了10000多条;tigase会断线,断线一段时间后,客户端自动重连;

每个连接限制值:

tigase.server.ConnectionManager里有很多限制值,跟其中有2个限制值有关;

last_minute_packets_limit:一分钟消息数限制

total_packets_limit:总数限制,默认是0,不限制

last_minute_bin_limit:每分钟字节数限制,内容长度超限;默认20000000L bytes;

超限处理:

packet数超限:

第一种丢弃包,不做其他处理;

第二种丢弃包,断开连接;(默认)

字节数超限:

丢弃包,断开连接;

修改配置:

--cm-traffic-throttling = xmpp:2500:0:disc,bin:20m:0:disc


xmpp:报文;2500个每分钟,超了关连接或者drop丢弃

bin:报文总大小(bytes),20m每分钟,超了关连接,或者drop丢弃

更新于2019年10月19日 18:05 sdy 广告产业园
参考
https://blog.csdn.net/huwenfeng_2011/article/details/43413377

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值