⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiauth.java

📁 java 实现DOMINO远程连接
💻 JAVA
字号:
package com.cjsc.it.auth;

import java.util.Vector;

import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;
import lotus.domino.View;

/**
 *放在AS服务器端程序
 * 
 * @author 张阿强 <br>
 *         <b>功能描述 <b>: <br>
 *         <b>实现思路 <b>: <br>
 *         <b>用例说明 <b>: <br>
 * @email ikhelon@gmail.com <br>
 * @time 2008-12-17
 */
public class UIAuth {

	private static int maxtimes = 10;
	public static String poolName = "主服务器";
	public static String poolName_bak = "备份服务器";

	protected UIAuth() {

	}

	/**
	 * 
	 * 
	 * @param userName
	 * @param password
	 * @return
	 */

	public static String checkUser(String userName, String password) {
		return checkUser(poolName, userName, password);
	}

	/**
	 * 当主DOMINO宕机时,会自动启用备用服务器
	 * 
	 * @param poolName
	 * @param userName
	 * @param password
	 * @return
	 */
	protected static String checkUser(String poolName, String userName,
			String password) {
		String msg = "";
		Session session = null;
		try {
			long i = 0;

			i = System.currentTimeMillis();
			for (int k = 1; k <= maxtimes; k++) {
				session = CjscSessionPoolFactory.getInstance().getSession(
						poolName);
				if (session == null) {
					if (k == maxtimes) {
						// 模拟主服务器宕机
						// CjscSessionPoolFactory.getInstance().getSessionPool(poolName).a
						// =
						// true;
						return "busing";

					}
				} else if (!session.isValid()) {
					CjscSessionPoolFactory.getInstance().releaseSession(
							poolName, session);
					if (k == maxtimes) {
						return "invalid";
					}
				} else {
					break;
				}
				Thread.sleep(600);
			}
			System.out.println(" 获取连接池用时: "+(System.currentTimeMillis()-i));
					
			msg = check(session, userName, password);
			System.out.println(" 认证总共用时: "+(System.currentTimeMillis()-i));
			
			CjscSessionPoolFactory.getInstance().releaseSession(poolName,
					session);

		} catch (Exception e) {
			CjscSessionPoolFactory.getInstance().releaseSession(poolName,
					session);
			System.out.println(e.getMessage());
			try {
				for (int k = 1; k <= maxtimes; k++) {
					session = CjscSessionPoolFactory.getInstance().getSession(
							poolName_bak);
					if (session == null) {
						if (k == maxtimes) {
							return "busing";
						}
					} else if (!session.isValid()) {
						CjscSessionPoolFactory.getInstance().releaseSession(
								poolName_bak, session);
						if (k == maxtimes) {
							return "invalid";
						}
					} else {
						break;
					}
					Thread.sleep(600);

				}

				msg = check(session, userName, password) + poolName_bak;
				CjscSessionPoolFactory.getInstance().releaseSession(
						poolName_bak, session);

			} catch (Exception ee) {
				msg = "DOMINO连接错误" + ee.getMessage();
				CjscSessionPoolFactory.getInstance().releaseSession(
						poolName_bak, session);
				e.printStackTrace();
			}
		}
		return msg;

	}

	private static String check(Session session, String userName,
			String password) throws Exception {

		String msg = "";
		Database db = session.getDatabase(session.getServerName(), "names.nsf",
				false);
		View view = db.getView("people");
		view.FTSearch("[ShortName]=" + userName);
		Document doc = view.getFirstDocument();
		if (null == doc) {
			msg = "无此用户名";
		} else {
			Vector v = session.evaluate("@Password('" + password + "')", null);
			String pass = doc.getItemValueString("HTTPPassword");
			if (pass.equals(v.get(0))) {
				msg = "success";
			} else {
				msg = "密码输入错误";
			}
		}

		view.recycle();
		db.recycle();
		return msg;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -