@Test public void saveAuditRecord() { AuditActionContext audit = new AuditActionContext("principal", "resourceOperatedUpon", "actionPerformed", "applicationCode", new Date(), "clientIpAddress", "serverIpAddress"); SyncopeWAAuditTrailManager auditTrailManager = new SyncopeWAAuditTrailManager(getWaRestClient()); auditTrailManager.saveAuditRecord(audit); verify(loggerService).create(any(AuditEntry.class)); }
@Override protected void saveAuditRecord(final AuditActionContext audit) { SyncopeClient syncopeClient = waRestClient.getSyncopeClient(); if (syncopeClient == null) { LOG.debug("Syncope client is not yet ready to store audit record"); return; } LOG.info("Loading application definitions"); try { String output = OBJECT_MAPPER.writeValueAsString(Map.of("resource", audit.getResourceOperatedUpon(), "clientIpAddress", audit.getClientIpAddress(), "serverIpAddress", audit.getServerIpAddress())); AuditEntry auditEntry = new AuditEntry(); auditEntry.setWho(audit.getPrincipal()); auditEntry.setDate(audit.getWhenActionWasPerformed()); auditEntry.setOutput(output); AuditElements.Result result = StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail") ? AuditElements.Result.FAILURE : AuditElements.Result.SUCCESS; AuditLoggerName auditLogger = new AuditLoggerName(AuditElements.EventCategoryType.WA, "LoggerLogic", AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(), audit.getActionPerformed(), result); auditEntry.setLogger(auditLogger); syncopeClient.getService(LoggerService.class).create(auditEntry); } catch (JsonProcessingException e) { LOG.error("During serialization", e); } }
SyncopeWAAuditTrailManager extends AbstractAuditTrailManager { @Override protected void saveAuditRecord(final AuditActionContext audit) { SyncopeClient syncopeClient = waRestClient.getSyncopeClient(); if (syncopeClient == null) { LOG.debug("Syncope client is not yet ready to store audit record"); return; } LOG.info("Loading application definitions"); try { String output = OBJECT_MAPPER.writeValueAsString(Map.of("resource", audit.getResourceOperatedUpon(), "clientIpAddress", audit.getClientIpAddress(), "serverIpAddress", audit.getServerIpAddress())); AuditEntry auditEntry = new AuditEntry(); auditEntry.setWho(audit.getPrincipal()); auditEntry.setDate(audit.getWhenActionWasPerformed()); auditEntry.setOutput(output); AuditElements.Result result = StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail") ? AuditElements.Result.FAILURE : AuditElements.Result.SUCCESS; AuditLoggerName auditLogger = new AuditLoggerName(AuditElements.EventCategoryType.WA, "LoggerLogic", AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(), audit.getActionPerformed(), result); auditEntry.setLogger(auditLogger); syncopeClient.getService(LoggerService.class).create(auditEntry); } catch (JsonProcessingException e) { LOG.error("During serialization", e); } } }
SyncopeWAAuditTrailManager extends AbstractAuditTrailManager { @Override protected void saveAuditRecord(final AuditActionContext audit) { SyncopeClient syncopeClient = waRestClient.getSyncopeClient(); if (syncopeClient == null) { LOG.debug("Syncope client is not yet ready to store audit record"); return; } LOG.info("Loading application definitions"); try { String output = OBJECT_MAPPER.writeValueAsString(Map.of("resource", audit.getResourceOperatedUpon(), "clientIpAddress", audit.getClientIpAddress(), "serverIpAddress", audit.getServerIpAddress())); AuditEntry auditEntry = new AuditEntry(); auditEntry.setWho(audit.getPrincipal()); auditEntry.setDate(audit.getWhenActionWasPerformed()); auditEntry.setOutput(output); AuditElements.Result result = StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail") ? AuditElements.Result.FAILURE : AuditElements.Result.SUCCESS; AuditLoggerName auditLogger = new AuditLoggerName(AuditElements.EventCategoryType.WA, "LoggerLogic", AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(), audit.getActionPerformed(), result); auditEntry.setLogger(auditLogger); syncopeClient.getService(LoggerService.class).create(auditEntry); } catch (JsonProcessingException e) { LOG.error("During serialization", e); } } SyncopeWAAuditTrailManager(final WARestClient restClient); }
SyncopeWAAuditTrailManager extends AbstractAuditTrailManager { @Override protected void saveAuditRecord(final AuditActionContext audit) { SyncopeClient syncopeClient = waRestClient.getSyncopeClient(); if (syncopeClient == null) { LOG.debug("Syncope client is not yet ready to store audit record"); return; } LOG.info("Loading application definitions"); try { String output = OBJECT_MAPPER.writeValueAsString(Map.of("resource", audit.getResourceOperatedUpon(), "clientIpAddress", audit.getClientIpAddress(), "serverIpAddress", audit.getServerIpAddress())); AuditEntry auditEntry = new AuditEntry(); auditEntry.setWho(audit.getPrincipal()); auditEntry.setDate(audit.getWhenActionWasPerformed()); auditEntry.setOutput(output); AuditElements.Result result = StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail") ? AuditElements.Result.FAILURE : AuditElements.Result.SUCCESS; AuditLoggerName auditLogger = new AuditLoggerName(AuditElements.EventCategoryType.WA, "LoggerLogic", AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(), audit.getActionPerformed(), result); auditEntry.setLogger(auditLogger); syncopeClient.getService(LoggerService.class).create(auditEntry); } catch (JsonProcessingException e) { LOG.error("During serialization", e); } } SyncopeWAAuditTrailManager(final WARestClient restClient); @Override Set<? extends AuditActionContext> getAuditRecordsSince(final LocalDate sinceDate); @Override void removeAll(); }
SyncopeWAAuditTrailManager extends AbstractAuditTrailManager { @Override protected void saveAuditRecord(final AuditActionContext audit) { SyncopeClient syncopeClient = waRestClient.getSyncopeClient(); if (syncopeClient == null) { LOG.debug("Syncope client is not yet ready to store audit record"); return; } LOG.info("Loading application definitions"); try { String output = OBJECT_MAPPER.writeValueAsString(Map.of("resource", audit.getResourceOperatedUpon(), "clientIpAddress", audit.getClientIpAddress(), "serverIpAddress", audit.getServerIpAddress())); AuditEntry auditEntry = new AuditEntry(); auditEntry.setWho(audit.getPrincipal()); auditEntry.setDate(audit.getWhenActionWasPerformed()); auditEntry.setOutput(output); AuditElements.Result result = StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail") ? AuditElements.Result.FAILURE : AuditElements.Result.SUCCESS; AuditLoggerName auditLogger = new AuditLoggerName(AuditElements.EventCategoryType.WA, "LoggerLogic", AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(), audit.getActionPerformed(), result); auditEntry.setLogger(auditLogger); syncopeClient.getService(LoggerService.class).create(auditEntry); } catch (JsonProcessingException e) { LOG.error("During serialization", e); } } SyncopeWAAuditTrailManager(final WARestClient restClient); @Override Set<? extends AuditActionContext> getAuditRecordsSince(final LocalDate sinceDate); @Override void removeAll();  }