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

📄 sqlauthenticator.java

📁 使用工具jublider开发的一个聊天室实现基本功能,
💻 JAVA
字号:
/**
 * Copyright (C) 2003  Manfred Andres
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package freecs.auth;

import freecs.core.CanceledRequestException;
import freecs.core.User;
import freecs.Server;
import freecs.auth.sqlConnectionPool.*;
import freecs.interfaces.IRequest;
import java.util.Properties;

public class SQLAuthenticator extends AbstractAuthenticator {
	String          data = null;
    ConnectionPool  conPool = null;
    ThreadGroup     threadGroup;

    public SQLAuthenticator () {
    }
    
	public void init(Properties allProps, String additionalPrefix) {
        super.init (allProps, additionalPrefix);
		Properties mapping = filterProperties(props, "mapping.");
		Server.log (this, "parsing db-config", Server.MSG_STATE, Server.LVL_MINOR);
        try {
        	DbProperties dbProps = new DbProperties(props, mapping);
        	conPool = new ConnectionPool (this, dbProps);
			data = null;   // causes the next login-attempt to update the cached column-list of columns to retrieve from the db
            threadGroup = new ThreadGroup ("[SqlRunnerGroup " + dbProps.url + "(" + dbProps.table + ")");
		} catch (Exception e) {
			Server.debug (this, "error parsing db-config: ", e, Server.MSG_STATE, Server.LVL_MAJOR);
		}
	}


	/**
	 * server is shutting down. Close all connections to jdbc-source
	 */
    public void shutdown () throws Exception {
       conPool.shutdown ();
    }

    public User loginUser(String username, String password, String cookie, IRequest request) throws Exception {
        SqlRunner runner = new SqlRunner (username, password, cookie, request, conPool);
        Thread t = startThread(runner);
        try {
            t.join();
        } catch (InterruptedException ie) {
            t.interrupt();
            throw new CanceledRequestException("Login timed out for user " + username, true);
        }
        if (runner.catchedException!=null)
            throw runner.catchedException;
        return runner.result;
    }

    public User loginUser(User u, String username, String password, IRequest request) throws Exception {
        SqlRunner runner = new SqlRunner (u, username, password, request, conPool);
        Thread t = startThread(runner);
        try {
            t.join();
        } catch (InterruptedException ie) {
            t.interrupt();
            throw new CanceledRequestException("Login timed out for user " + u.getName(), true);
        }
        if (runner.catchedException!=null)
            throw runner.catchedException;
        return runner.result;
	}
    
    public void logoutUser(User u) throws Exception {
        if (u==null || u.isUnregistered)
            return;
        SqlRunner runner = new SqlRunner (u, conPool);
        startThread(runner);
    }
    
    private Thread startThread(SqlRunner sr) throws Exception {
        if (threadGroup.activeCount() >= conPool.size())
            throw new Exception ("All connections are currently used");
        Thread t = new Thread(threadGroup, sr);
        t.start();
        return t;
    }
}

⌨️ 快捷键说明

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