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

📄 locallogsessionbean.java

📁 一套JAVA的CA证书签发系统.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */        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    /**    * Overloaded function that also logs an exception    * See function above for more documentation.    *    * @param exception the exception that has occured    */    public void log(Admin admin, int caid, int module, Date time, String username, X509Certificate certificate, int event, String comment, Exception exception){      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) + "," + certificate.getIssuerDN().toString();                                       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, exception);            }          }        }      }catch(Exception e){        throw new EJBException(e);      }    }         /**     * Same as above but with the difference of CAid which is taken from the issuerdn of      * given certificate.     */    public void log(Admin admin, X509Certificate caid, int module,  Date time, String username, X509Certificate certificate, int event, String comment, Exception exception){      log(admin, CertTools.getIssuerDN(caid).hashCode(), module, time, username, certificate, event, comment, exception);    } // log            /**     * Method to execute a customized query on the log db data. The parameter query should be a legal Query object.     *     * @param query a number of statments compiled by query class to a SQL 'WHERE'-clause statment.     * @param viewlogprivileges is a sql query string returned by a LogAuthorization object.     * @param authorizedcaids is a collection of integers indicating which CAs the administrator is authorized to view log of.     * @return a collection of LogEntry. Maximum size of Collection is defined i ILogSessionRemote.MAXIMUM_QUERY_ROWCOUNT     * @throws IllegalQueryException when query parameters internal rules isn't fullfilled.     * @see se.anatom.ejbca.util.query.Query     */    public Collection query(Query query, String viewlogprivileges, String capriviledges) throws IllegalQueryException{        debug(">query()");        Connection con = null;        PreparedStatement ps = null;        ResultSet rs = null;        ArrayList returnval = new ArrayList();        if(capriviledges == null || capriviledges.equals(""))          throw new IllegalQueryException();                                 // Check if query is legal.        if(!query.isLegalQuery())          throw new IllegalQueryException();        try{           // Construct SQL query.            con = getConnection();            if(viewlogprivileges.equals("")){                            ps = con.prepareStatement("select " + LOGENTRYDATA_COL + " from LogEntryData where ( " + query.getQueryString() +                                     ") and (" + capriviledges + ")");			                                                     }else{              	                          ps = con.prepareStatement("select " + LOGENTRYDATA_COL + " from LogEntryData where (" + query.getQueryString() + ") and ("                                          + viewlogprivileges + ") and (" + capriviledges + ")");                                                   }            //ps.setFetchDirection(ResultSet.FETCH_REVERSE);            ps.setFetchSize(MAXIMUM_QUERY_ROWCOUNT +1 );            // Execute query.            rs = ps.executeQuery();            // Assemble result.            while(rs.next() && returnval.size() <= MAXIMUM_QUERY_ROWCOUNT){              LogEntry data = new LogEntry(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4),  new java.util.Date(rs.getLong(5)), rs.getString(6), rs.getString(7)                                               , rs.getInt(8), rs.getString(9));              returnval.add(data);            }            debug("<query()");			            return returnval;        }catch(Exception e){          throw new EJBException(e);        }finally{           try{             if(rs != null) rs.close();             if(ps != null) ps.close();             if(con!= null) con.close();           }catch(SQLException se){               error("Fel vid upprensning: ", se);           }        }    } // query    /**     * Loads the log configuration from the database.     *     * @return the logconfiguration     */    public LogConfiguration loadLogConfiguration(int caid){        // Check if log configuration exists, else create one.      LogConfiguration logconfiguration = null;      LogConfigurationDataLocal logconfigdata = null;        try{		logconfigdata = logconfigurationhome.findByPrimaryKey(new Integer(caid));        logconfiguration = logconfigdata.loadLogConfiguration();      }catch(FinderException e){         try{           logconfiguration = new LogConfiguration();		   logconfigdata = logconfigurationhome.create(new Integer(caid),logconfiguration);         }catch(CreateException f){           throw new EJBException(f);         }      }      return logconfiguration;    } // loadLogConfiguration    /**     * Saves the log configuration to the database.     *     * @param logconfiguration the logconfiguration to save.     */    public void saveLogConfiguration(Admin admin, int caid, LogConfiguration logconfiguration){      try{        try{          (logconfigurationhome.findByPrimaryKey(new Integer(caid))).saveLogConfiguration(logconfiguration);          log(admin, caid, LogEntry.MODULE_LOG, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITLOGCONFIGURATION,"");        }catch(FinderException e){           logconfigurationhome.create(new Integer(caid),logconfiguration);           log(admin, caid, LogEntry.MODULE_LOG, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITLOGCONFIGURATION,"");        }      }catch(Exception e){            log(admin, caid, LogEntry.MODULE_LOG, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_EDITLOGCONFIGURATION,"");         throw new EJBException(e);      }    } // saveLogConfiguration	private Integer getAndIncrementRowCount(){		if(this.logconfigurationdata == null){			try{				logconfigurationdata = logconfigurationhome.findByPrimaryKey(new Integer(0));			}catch(FinderException e){			   try{				 LogConfiguration logconfiguration = new LogConfiguration();				 this.logconfigurationdata = logconfigurationhome.create(new Integer(0),logconfiguration);			   }catch(CreateException f){				 throw new EJBException(f);			   }					   }		}				return this.logconfigurationdata.getAndIncrementRowCount();	}} // LocalLogSessionBean

⌨️ 快捷键说明

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