001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.login;
021:
022: import java.sql.Timestamp;
023:
024: import javax.servlet.ServletConfig;
025: import javax.servlet.ServletException;
026:
027: import com.nabhinc.core.Defaults;
028: import com.nabhinc.portal.core.LoginInterceptor;
029: import com.nabhinc.util.db.DBUtil;
030:
031: /**
032: * Log log-in/out events to a database table.
033: *
034: * @author Padmanabh Dabke
035: * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
036: */
037: public class LoginDBLogger extends BaseLogger implements
038: LoginInterceptor {
039:
040: /**
041: * Name of the datasource used to log login data
042: */
043: private String ldlDataSource = null;
044:
045: /**
046: * SQL corresponding to login record.
047: */
048: private String ldlSQL = "INSERT INTO SB_LOGIN_LOGS (logtime, logtype, sessionid, username, remoteaddress, remotehost ) VALUES (?,?,?,?,?,?)";
049:
050: /**
051: * This method is invoked on each interceptor that is attached to a portlet
052: * before the request is sent to the portlet.
053: * @param userName Name of the current user
054: * @param req HttpServletRequest object
055: */
056: public void intercept(String sessionID, String userName,
057: int logType, String remoteHost, String remoteAddr)
058: throws ServletException {
059:
060: try {
061: DBUtil.execute(ldlDataSource, ldlSQL, new Object[] {
062: new Timestamp(System.currentTimeMillis()),
063: new Integer(logType), sessionID, userName,
064: remoteAddr, remoteHost });
065:
066: } catch (Throwable ex) {
067: throw new ServletException(
068: "Couldn't log log-in event to the database.", ex);
069: }
070: }
071:
072: public void init(ServletConfig config) throws ServletException {
073:
074: if (blParams == null) {
075: blParams = new int[] { LOG_TIMESTAMP, LOG_EVENT_TYPE,
076: LOG_SESSION_ID, LOG_REMOTE_USER, LOG_REMOTE_ADDR,
077: LOG_REMOTE_HOST };
078: blNumParams = 6;
079: }
080: if (ldlDataSource == null)
081: ldlDataSource = Defaults.getDataSourceName();
082:
083: }
084:
085: public String getDataSource() {
086: return ldlDataSource;
087: }
088:
089: public void setDataSource(String ldlDataSource) {
090: this .ldlDataSource = ldlDataSource;
091: }
092:
093: public String getSql() {
094: return ldlSQL;
095: }
096:
097: public void setSql(String ldlSQL) {
098: this.ldlSQL = ldlSQL;
099: }
100:
101: }
|