private static void updateFingerPrint(final AbstractEntity entity) { if (entity.getClass().isAnnotationPresent(Fingerprintable.class)) { ((FingerprintableBaseEntity) entity).setFingerPrint(((FingerprintableBaseEntity) entity).generateFingerPrint()); } }
private StringBuilder getFingerPrintableString() { final StringBuilder sb = new StringBuilder(); for (final String value : getSortedFingerprintableValues()) { if (value != null) { sb.append(value); } } return sb; }
private List<String> getSortedFingerprintableValues() { final List<String> fingerPrintableValues = new ArrayList<>(); fingerPrintableValues.add(String.valueOf(getId())); fingerPrintableValues.add(String.valueOf(fingerPrintVersion)); fingerPrintableValues.add(getFingerprintKey()); for (final Object value : getFingerprintableValues()) { if (value != null) { final String formattedValue; if (value instanceof Date) { formattedValue = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format((Date) value); } else { formattedValue = String.valueOf(value); } fingerPrintableValues.add(formattedValue); } } // Sort the values to avoid unnecessary ordering issues while // calculating the hash. Collections.sort(fingerPrintableValues); return Collections.unmodifiableList(fingerPrintableValues); }
protected void validateFingerPrint(final T entity) { if ((entity != null) && entity.getClass().isAnnotationPresent(Fingerprintable.class)) { final FingerprintableBaseEntity fe = (FingerprintableBaseEntity) entity; if (!fe.generateFingerPrint().equals(fe.getFingerPrint())) { throw new InvalidFingerPrintException( "Fingerprint mismatch for the given id:" + entity.getId() + ". Make sure the fingerprint value is not altered outside of the application."); } } }
final String generateFingerPrint() { final StringBuilder sb = getFingerPrintableString(); return DigestUtils.sha512Hex(sb.toString()); }
private String getFingerprintKey() { return String.valueOf(Math.abs(String.valueOf(getId()).hashCode())); }
@SuppressWarnings("unchecked") private List<Object> getFingerprintableValues() { final List<Object> fieldValues = new ArrayList<>(); try { final Set<Field> fields = ReflectionUtils.getFields(getClass()); for (final Field field : fields) { field.setAccessible(true); final Object value = field.get(this); if ((value != null) && !isAnnotationPresent(field, IgnoreFingerprint.class, Version.class, Transient.class)) { fieldValues.add(value); } } return fieldValues; } catch (final Exception e) { throw new RuntimeException(e); } }
private List<String> getSortedFingerprintableValues() { final List<String> fingerPrintableValues = new ArrayList<>(); fingerPrintableValues.add(String.valueOf(getId())); fingerPrintableValues.add(String.valueOf(fingerPrintVersion)); fingerPrintableValues.add(getFingerprintKey()); for (final Object value : getFingerprintableValues()) { if (value != null) { final String formattedValue; if (value instanceof Date) { formattedValue = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format((Date) value); } else { formattedValue = String.valueOf(value); } fingerPrintableValues.add(formattedValue); } } // Sort the values to avoid unnecessary ordering issues while // calculating the hash. Collections.sort(fingerPrintableValues); return Collections.unmodifiableList(fingerPrintableValues); }
protected void validateFingerPrint(final T entity) { if ((entity != null) && entity.getClass().isAnnotationPresent(Fingerprintable.class)) { final FingerprintableBaseEntity fe = (FingerprintableBaseEntity) entity; if (!fe.generateFingerPrint().equals(fe.getFingerPrint())) { throw new InvalidFingerPrintException( "Fingerprint mismatch for the given id:" + entity.getId() + ". Make sure the fingerprint value is not altered outside of the application."); } } }
final String generateFingerPrint() { final StringBuilder sb = getFingerPrintableString(); return DigestUtils.sha512Hex(sb.toString()); }
private String getFingerprintKey() { return String.valueOf(Math.abs(String.valueOf(getId()).hashCode())); }
@SuppressWarnings("unchecked") private List<Object> getFingerprintableValues() { final List<Object> fieldValues = new ArrayList<>(); try { final Set<Field> fields = ReflectionUtils.getFields(getClass()); for (final Field field : fields) { field.setAccessible(true); final Object value = field.get(this); if ((value != null) && !isAnnotationPresent(field, IgnoreFingerprint.class, Version.class, Transient.class)) { fieldValues.add(value); } } return fieldValues; } catch (final Exception e) { throw new RuntimeException(e); } }
private static void updateFingerPrint(final AbstractEntity entity) { if (entity.getClass().isAnnotationPresent(Fingerprintable.class)) { ((FingerprintableBaseEntity) entity).setFingerPrint(((FingerprintableBaseEntity) entity).generateFingerPrint()); } }
protected void validateFingerPrint(final T entity) { if ((entity != null) && entity.getClass().isAnnotationPresent(Fingerprintable.class)) { final FingerprintableBaseEntity fe = (FingerprintableBaseEntity) entity; if (!fe.generateFingerPrint().equals(fe.getFingerPrint())) { throw new InvalidFingerPrintException( "Fingerprint mismatch for the given id:" + entity.getId() + ". Make sure the fingerprint value is not altered outside of the application."); } } }
private StringBuilder getFingerPrintableString() { final StringBuilder sb = new StringBuilder(); for (final String value : getSortedFingerprintableValues()) { if (value != null) { sb.append(value); } } return sb; }
private static void updateFingerPrint(final AbstractEntity entity) { if (entity.getClass().isAnnotationPresent(Fingerprintable.class)) { ((FingerprintableBaseEntity) entity).setFingerPrint(((FingerprintableBaseEntity) entity).generateFingerPrint()); } }
protected void validateFingerPrint(final T entity) { if ((entity != null) && entity.getClass().isAnnotationPresent(Fingerprintable.class)) { final FingerprintableBaseEntity fe = (FingerprintableBaseEntity) entity; if (!fe.generateFingerPrint().equals(fe.getFingerPrint())) { throw new InvalidFingerPrintException( "Fingerprint mismatch for the given id:" + entity.getId() + ". Make sure the fingerprint value is not altered outside of the application."); } } }
private static void updateFingerPrint(final AbstractEntity entity) { if (entity.getClass().isAnnotationPresent(Fingerprintable.class)) { ((FingerprintableBaseEntity) entity).setFingerPrint(((FingerprintableBaseEntity) entity).generateFingerPrint()); } }