📄 locallogsessionbean.java
字号:
/************************************************************************* * * * 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.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.DuplicateKeyException;import javax.ejb.EJBException;import javax.ejb.FinderException;import org.apache.commons.lang.StringUtils;import se.anatom.ejbca.BaseSessionBean;import se.anatom.ejbca.JNDINames;import se.anatom.ejbca.util.CertTools;import se.anatom.ejbca.util.JDBCUtil;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. * * * @ejb.bean * display-name="LogSessionSB" * name="LogSession" * jndi-name="LogSession" * local-jndi-name="LogSessionLocal" * view-type="both" * type="Stateless" * transaction-type="Container" * * @ejb.permission role-name="InternalUser" * * @ejb.env-entry * name="DataSource" * type="java.lang.String" * value="java:/${datasource.jndi-name}" * * @ejb.env-entry * description="String representing the log device factories to be used. The different device classes should be separated with semicolons (;)." * name="logDeviceFactories" * type="java.lang.String" * value="se.anatom.ejbca.log.Log4jLogDeviceFactory" * * @ejb.env-entry * description="String representing the property file corresponding to each log device. The property files should be placed in the '/logdeviceproperties' subdirectory. The filenames should be separated with semicolons (;)" * name="logDevicePropertyFiles" * type="java.lang.String" * value="Log4j.properties" * * @ejb.ejb-external-ref * description="The Log Entry Data entity bean" * view-type="local" * ejb-name="LogEntryDataLocal" * type="Entity" * home="se.anatom.ejbca.log.LogEntryDataLocalHome" * business="se.anatom.ejbca.log.LogEntryDataLocal" * link="LogEntryData" * * @ejb.ejb-external-ref * description="The Log Configuration Data Entity bean" * view-type="local" * ejb-name="LogConfigurationDataLocal" * type="Entity" * home="se.anatom.ejbca.log.LogConfigurationDataLocalHome" * business="se.anatom.ejbca.log.LogConfigurationDataLocal" * link="LogConfigurationData" * * @ejb.home * extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome,LogConstants" * local-class="se.anatom.ejbca.log.ILogSessionLocalHome" * remote-class="se.anatom.ejbca.log.ILogSessionHome" * * @ejb.interface * extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject,LogConstants" * local-class="se.anatom.ejbca.log.ILogSessionLocal" * remote-class="se.anatom.ejbca.log.ILogSessionRemote" * * @jonas.bean * ejb-name="LogSession" * */public class LocalLogSessionBean extends BaseSessionBean { /** The home interface of LogEntryData entity bean */ private LogEntryDataLocalHome logentryhome; /** The home interface of LogConfigurationData entity bean */ private LogConfigurationDataLocalHome logconfigurationhome; /** The remote interface of the LogConfigurationData entity bean */ private LogConfigurationDataLocal logconfigurationdata; private static final String LOGDEVICE_FACTORIES = "java:comp/env/logDeviceFactories"; private static final String LOGDEVICE_PROPERTIES = "java:comp/env/logDevicePropertyFiles"; /** Collection of available log devices, i.e Log4j etc */ private ArrayList logdevices; /** Columns in the database used in select */ private final String LOGENTRYDATA_TABLE = "LogEntryData"; private final String LOGENTRYDATA_COL = "adminType, adminData, caid, module, time, username, certificateSNR, event"; // Different column names is an unforturnalte workaround because of Orcale, you cannot have a column named 'comment' in Oracle. // The workaround 'comment_' was spread in the wild in 2005, so we have to use it so far. private final String LOGENTRYDATA_COL_COMMENT_OLD = "comment"; private final String LOGENTRYDATA_COL_COMMENT_ORA = "comment_"; /** * Default create for SessionBean without any creation Arguments. */ public void ejbCreate() { try { logentryhome = (LogEntryDataLocalHome) getLocator().getLocalHome(LogEntryDataLocalHome.COMP_NAME); logconfigurationhome = (LogConfigurationDataLocalHome) getLocator().getLocalHome(LogConfigurationDataLocalHome.COMP_NAME); // Setup Connection to signing devices. logdevices = new ArrayList(); // Get configuration of log device classes from ejb-jar.xml String factoryclassesstring = getLocator().getString(LOGDEVICE_FACTORIES); String propertyfilesstring = getLocator().getString(LOGDEVICE_PROPERTIES); 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())); } String[] factoryclasses = factoryclassesstring.split(";"); for (int i = 0; i < factoryclasses.length; i++) { Class implClass = Class.forName(factoryclasses[i].trim()); Object fact = implClass.newInstance(); Class[] paramTypes = new Class[]{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(method.invoke(fact, params)); } } catch (Exception e) { throw new EJBException(e); } } /** * 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. * * @ejb.interface-method view-type="both" * @ejb.transaction type="RequiresNew" */ public void log(Admin admin, int caid, int module, Date time, String username, X509Certificate certificate, int event, String comment) { doLog(admin, caid, module, time, username, certificate, event, comment, null); } // log /** * Same as above but with the difference of CAid which is taken from the issuerdn of given certificate. * * @ejb.interface-method view-type="both" * @ejb.transaction type="RequiresNew" */ public void log(Admin admin, X509Certificate caid, int module, Date time, String username, X509Certificate certificate, int event, String comment) { log(admin, CertTools.getIssuerDN(caid).hashCode(), module, time, username, certificate, event, comment); } // log
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -