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

📄 sessionauthenticator.java

📁 piweurrrrq i o fhsadhfka fd dskajc zxkjcnkjsahc
💻 JAVA
字号:
/* * Copyright (c) 2000 RUChat.com */package com.ruchat.auth;import java.io.IOException;import java.util.Properties;import com.lyrisoft.util.properties.*;import com.lyrisoft.chat.server.remote.AccessDenied;import com.lyrisoft.chat.server.remote.IAuthenticator;import com.lyrisoft.chat.server.remote.Auth;import com.lyrisoft.chat.server.remote.ChatServer;import java.sql.*;/** */public class SessionAuthenticator implements IAuthenticator {    private Connection _connection = null;    public SessionAuthenticator() {        try {            Properties p = PropertyTool.loadProperties("mysqlauth.conf");            String driver = PropertyTool.getString("mysql.class", p);            String url = PropertyTool.getString("mysql.dburl", p);            Class.forName(driver).newInstance();            _connection = DriverManager.getConnection(url);                        ChatServer.log("Connection to Mysql initialized");        }        catch (Exception e) {            ChatServer.log(e);            throw new RuntimeException(e.toString());        }    }    public Auth authenticate(String userId, String password) throws AccessDenied {        String sessionId = userId;                String query = "SELECT username, access\n" +                "FROM acl\n" +                "WHERE string = '" + sessionId + "'";                        Statement stmt = null;        try {            ChatServer.log("SessionAuthenticator: validating session id " + sessionId);            stmt = _connection.createStatement();            ResultSet rs = stmt.executeQuery(query);            if (rs.next()) {                String username = rs.getString("username");                int access = rs.getInt("access");                return new Auth(username, access);            } else {                ChatServer.log("SessionAuthenticator: session id " + sessionId + " is not authenticated");                throw new AccessDenied("You are not authenticated.");            }        }        catch (SQLException e) {            ChatServer.log(e);            throw new AccessDenied("Database access error");        }        finally {            if (stmt != null) {                try {                    stmt.close();                }                 catch (SQLException e) {}            }        }    }}

⌨️ 快捷键说明

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