List of usage examples for org.apache.commons.lang.time FastDateFormat getTimeInstance
public static FastDateFormat getTimeInstance(int style, TimeZone timeZone)
Gets a time formatter instance using the specified style and time zone in the default locale.
From source file:org.cesecore.audit.impl.queued.QueuedAuditorSessionBean.java
@Override public void delete(AuthenticationToken token, Date timestamp) { // get last signed log before the specified timestamp final AuditLogData lastSigned = AuditLogData.getLastSignedAuditLog(em, timestamp); final boolean delete = lastSigned != null; if (delete) { final Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("timestamp", FastDateFormat .getTimeInstance(FastDateFormat.FULL, TimeZone.getTimeZone("GMT")).format(timestamp)); securityEventsLogger.log(EventTypes.LOG_DELETE, EventStatus.VOID, ModuleTypes.SECURITY_AUDIT, ServiceTypes.CORE, token.toString(), null, null, null, details); if (log.isDebugEnabled()) { log.debug("deleting exported logs"); }/*from w w w. ja va 2 s. com*/ // important to set flushmode to commit (commit only occurs on flush or explicit commit) em.setFlushMode(FlushModeType.COMMIT); // delete till the obtained log. AuditLogData.delete(em, QueryCriteria.create() .add(Criteria.lsr(AuditLogEntry.FIELD_SEQUENCENUMBER, lastSigned.getSequenceNumber()))); em.flush(); } }
From source file:org.cesecore.audit.impl.queued.QueuedAuditorSessionBean.java
@Override public AuditLogExportReport exportAuditLogs(final AuthenticationToken token, final CryptoToken cryptoToken, final Date timestamp, final boolean deleteAfterExport, final Map<String, Object> signatureDetails, final Properties properties, final Class<? extends AuditExporter> c) throws AuditLogExporterException { final AuditLogExportReport report = new AuditLogExportReport(); Connection conn = null;/* ww w. java 2s . c o m*/ EventStatus status = EventStatus.SUCCESS; try { conn = ds.getConnection(); final File exportFile = AuditDevicesConfig.getExportFile(properties, timestamp); report.setExportedFile(exportFile.getCanonicalPath()); final SigningFileOutputStream fos = new SigningFileOutputStream(exportFile, cryptoToken, signatureDetails); final AuditLogDbExporter exporter = new AuditLogDbExporter(em, fos, conn); try { // get logs count till the specified timestamp if (log.isDebugEnabled()) { log.debug("exporting logs to file: " + exportFile.getAbsolutePath()); } exporter.export(timestamp, c, AuditDevicesConfig.getAuditLogExportFetchSize(properties)); } finally { try { fos.flush(); } catch (final IOException e) { log.error("Can not flush output stream: ", e); } fos.close(); } // sign the exported file ... it will write the signature on the side fos.writeSignature(); } catch (final Exception e) { log.warn(e.getMessage(), e); status = EventStatus.FAILURE; throw new AuditLogExporterException(e.getMessage(), e); } finally { if (conn != null) { try { conn.close(); } catch (final SQLException e) { throw new AuditLogExporterException(e.getMessage(), e); } } } final Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("deleted", deleteAfterExport); details.put("timestamp", FastDateFormat.getTimeInstance(FastDateFormat.FULL, TimeZone.getTimeZone("GMT")).format(timestamp)); securityEventsLogger.log(EventTypes.LOG_EXPORT, status, ModuleTypes.SECURITY_AUDIT, ServiceTypes.CORE, token.toString(), null, null, null, details); if (deleteAfterExport) { queuedAuditorSession.delete(token, timestamp); } return report; }
From source file:org.cesecore.audit.impl.queued.QueuedAuditorSessionBean.java
@Override public AuditLogValidationReport verifyLogsIntegrity(final AuthenticationToken token, final Date timestamp, final Properties properties) throws AuditLogValidatorException { Connection conn = null;//ww w . j a v a 2 s. co m try { conn = ds.getConnection(); em.setFlushMode(FlushModeType.COMMIT); final AuditLogValidator validator = new AuditLogDbValidator(em, conn); final AuditLogValidationReport report = validator.validate(timestamp, AuditDevicesConfig.getAuditLogValidationFetchSize(properties)); final Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("timestamp", FastDateFormat .getTimeInstance(FastDateFormat.FULL, TimeZone.getTimeZone("GMT")).format(timestamp)); // Success or failure depending on if verification returns error or not EventStatus status = EventStatus.SUCCESS; if (report.errors().size() > 0) { status = EventStatus.FAILURE; details.put("errors", report.errors().size()); } securityEventsLogger.log(EventTypes.LOG_VERIFY, status, ModuleTypes.SECURITY_AUDIT, ServiceTypes.CORE, token.toString(), null, null, null, details); return report; } catch (final SQLException e) { throw new AuditLogValidatorException(e.getMessage(), e); } finally { em.flush(); if (conn != null) { try { conn.close(); } catch (final SQLException e) { throw new AuditLogValidatorException(e.getMessage(), e); } } } }