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

📄 locallogsessionbean.java

📁 一套JAVA的CA证书签发系统.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/************************************************************************* *                                                                       * *  EJBCA: The OpenSource Certificate Authority                          * *                                                                       * *  This software is free software; you can redistribute it and/or       * *  modify it under the terms of the GNU Lesser General Public           * *  License as published by the Free Software Foundation; either         * *  version 2.1 of the License, or any later version.                    * *                                                                       * *  See terms of license at gnu.org.                                     * *                                                                       * *************************************************************************/ package se.anatom.ejbca.log;import java.lang.reflect.Method;import java.security.cert.X509Certificate;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.Iterator;import java.util.Properties;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.ejb.FinderException;import javax.naming.NamingException;import javax.sql.DataSource;import org.apache.log4j.Logger;import se.anatom.ejbca.BaseSessionBean;import se.anatom.ejbca.util.CertTools;import se.anatom.ejbca.util.query.IllegalQueryException;import se.anatom.ejbca.util.query.Query;/** * Stores data used by web server clients. * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml. * * @version $Id: LocalLogSessionBean.java,v 1.18 2004/04/16 07:38:57 anatom Exp $ */public class LocalLogSessionBean extends BaseSessionBean  {    private static Logger log = Logger.getLogger(LocalLogSessionBean.class);    public static final int MAXIMUM_QUERY_ROWCOUNT = 300;    /** Var holding JNDI name of datasource */    private String dataSource = "";    /** The home interface of  LogEntryData entity bean */    private LogEntryDataLocalHome logentryhome=null;    /** The home interface of  LogConfigurationData entity bean */    private LogConfigurationDataLocalHome logconfigurationhome=null;    /** The remote interface of the LogConfigurationData entity bean */    private LogConfigurationDataLocal logconfigurationdata=null;    /** Collection of available log devices, i.e Log4j etc */    private ArrayList logdevices = null;    /** Columns in the database used in select */    private final String LOGENTRYDATA_COL = "adminType, adminData, caid, module, time, username, certificateSNR, event, comment";    /**     * Default create for SessionBean without any creation Arguments.     * @throws CreateException if bean instance can't be created     */    public void ejbCreate() {      try{          debug(">ejbCreate()");        dataSource = (String)lookup("java:comp/env/DataSource", java.lang.String.class);        debug("DataSource=" + dataSource);        logentryhome = (LogEntryDataLocalHome)lookup("java:comp/env/ejb/LogEntryDataLocal", LogEntryDataLocalHome.class);        logconfigurationhome = (LogConfigurationDataLocalHome)lookup("java:comp/env/ejb/LogConfigurationDataLocal", LogConfigurationDataLocalHome.class);        // Setup Connection to signing devices.        logdevices = new ArrayList();        // Get configuration of log device classes from ejb-jar.xml        String factoryclassesstring = (String)lookup("java:comp/env/logDeviceFactories", java.lang.String.class);        String propertyfilesstring  = (String)lookup("java:comp/env/logDevicePropertyFiles", java.lang.String.class);        String[] factoryclasses = factoryclassesstring.split(";");        String[] propertyfiles  = propertyfilesstring.split(";");        Properties[] properties = new Properties[propertyfiles.length];        for(int i= 0; i < propertyfiles.length; i++){            properties[i] =  new Properties();            if(!(propertyfiles[i] == null || propertyfiles[i].trim().equals("")))              properties[i].load(this.getClass().getResourceAsStream("/logdeviceproperties/" + propertyfiles[i].trim()));        }        for(int i=0; i < factoryclasses.length; i++){            Class implClass = Class.forName( factoryclasses[i].trim() );            Object fact = implClass.newInstance();            Class[] paramTypes = new Class[1];            paramTypes[0] = properties[0].getClass();            Method method = implClass.getMethod("makeInstance", paramTypes);            Object[] params = new Object[1];            if(i < properties.length)              params[0] = properties[i];            else              params[0] = new Properties();            logdevices.add((ILogDevice)method.invoke(fact, params));        }        debug("<ejbCreate()");      }catch(Exception e){        throw new EJBException(e);         }    }    /** Gets connection to Datasource used for manual SQL searches     * @return Connection     */    private Connection getConnection() throws SQLException, NamingException {        DataSource ds = (DataSource)getInitialContext().lookup(dataSource);        return ds.getConnection();    } //getConnection    /**     * Session beans main function. Takes care of the logging functionality.     *     * @param admin the administrator performing the event.     * @param time the time the event occured.     * @param username the name of the user involved or null if no user is involved.     * @param certificate the certificate involved in the event or null if no certificate is involved.     * @param event id of the event, should be one of the se.anatom.ejbca.log.LogEntry.EVENT_ constants.     * @param comment comment of the event.     */    public void log(Admin admin, int caid, int module,  Date time, String username, X509Certificate certificate, int event, String comment){      try{        LogConfiguration logconfiguration = loadLogConfiguration(caid);        		                  // Get logging configuration        if(logconfiguration.logEvent(event)){          if(logconfiguration.useLogDB()){            try{               // Log to the local database.               if(certificate != null){                 String uniquecertificatesnr =certificate.getSerialNumber().toString(16) + "," + CertTools.getIssuerDN(certificate);                    logentryhome.create(this.getAndIncrementRowCount(), admin.getAdminType(), admin.getAdminData(), caid, module, time, username,                                     uniquecertificatesnr, event, comment);               }else                 logentryhome.create(this.getAndIncrementRowCount(), admin.getAdminType(), admin.getAdminData(), caid, module, time, username,                                     null, event, comment);            }catch(javax.ejb.DuplicateKeyException dke){             this.getAndIncrementRowCount();            }          }          if(logconfiguration.useExternalLogDevices()){            // Log to external devices. I.e Log4j etc            Iterator i = logdevices.iterator();            while(i.hasNext()){               ((ILogDevice) i.next()).log(admin, caid, module,  time, username, certificate, event, comment);            }          }        }      }catch(Exception e){        throw new EJBException(e);      }    } // log         /**     * Same as above but with the difference of CAid which is taken from the issuerdn of      * given certificate.

⌨️ 快捷键说明

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