jdbcauthenticator.java

来自「piweurrrrq i o fhsadhfka fd dskajc zxkjc」· Java 代码 · 共 50 行

JAVA
50
字号
/*
 * Jdbc Authentication Module:
 * By Wayne Hogue <w.hogue@chiphead.net>
 * Last Updated: 04.02.2000 
 * Based on 
 * Mysql Authentication Module:
 * com.lyrisoft.auth.mysql;
 * By Leif Jackson <ljackson@jjcons.com>
 */
package com.lyrisoft.chat.server.remote.auth.jdbc;

import java.sql.SQLException;

import com.lyrisoft.chat.Translator;
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 com.lyrisoft.chat.server.remote.Resources;

/**
 * Authenitcator that reads from server using JDBC<p>
 *
 * If a user if found in the password file, his password is checked.
 * If a user is not found in the password file, the access level IAuthenticator.USER
 * is returned.
 */
public class JdbcAuthenticator implements IAuthenticator {
    private Jdbc _jdbc;

    public JdbcAuthenticator() {
        _jdbc = new Jdbc();
    }

    public Auth authenticate(String userId, String password) throws AccessDenied {
        try {
            JdbcRecord record = _jdbc.getRecord(userId, password);
            if (record == null) {
                return new Auth(userId, USER);
            } else {
                return new Auth(userId, record.access);
            }
        }
        catch (SQLException e) {
            ChatServer.log(e);
            throw new AccessDenied(Translator.getMessage("sql_error", e.toString()));
        }
    }
}

⌨️ 快捷键说明

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