@Test public void shouldRespectAttributeAnonymity() { Auditor auditor = new Auditor(); AnonymizedEntity entityState1 = new AnonymizedEntity("uuid-1", "qwertz"); AnonymizedEntity entityState2 = new AnonymizedEntity("uuid-1", "securePwd"); ValueContainer pastState = auditor.inspectEntity(entityState1); ValueContainer futureState = auditor.inspectEntity(entityState2); final SortedMap<String, String> changes = futureState.compare(pastState); assertThat(changes.size(), is(1)); assertThat(changes.get(AnonymizedEntity.PWD), is(AnonymizedEntity.ANONYMIZING)); }
ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; } }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  void register(HasUuid entity); ChangeEvent detectChanges(HasUuid entity); }
Auditor implements Serializable { ValueContainer inspectEntity(HasUuid entity) { DefaultValueContainer result = new DefaultValueContainer(); EntityInspector inspector = new EntityInspector(entity); for (Method currentAttribute : inspector.getAuditedAttributes()) { try { AuditedAttribute auditedAttribute = currentAttribute.getAnnotation(AuditedAttribute.class); AuditedCollection auditedCollection = currentAttribute.getAnnotation(AuditedCollection.class); boolean isCollection = Collection.class.isAssignableFrom(currentAttribute.getReturnType()); if (auditedAttribute != null || !isCollection) { logAttributeChange(result, inspector, currentAttribute, auditedAttribute); } else if (auditedCollection != null || isCollection) { logCollectionChange(result, inspector, currentAttribute, auditedCollection); } } catch (InvocationTargetException | IllegalAccessException e) { throw new AuditlogException(String.format("No changes for entity %s can be detected.", entity.toString()), e); } } return result; }  void register(HasUuid entity); ChangeEvent detectChanges(HasUuid entity);  }