uk.gov.ida.eventemitter.EventHasher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of verify-event-emitter Show documentation
Show all versions of verify-event-emitter Show documentation
Library providing a Java Service to log Audit Events to a datastore
package uk.gov.ida.eventemitter;
import com.google.inject.Inject;
import java.util.EnumMap;
public class EventHasher {
public static final String PID_REMOVED = "Plaintext pid has been removed.";
private final Sha256Util sha256Util;
@Inject
public EventHasher(final Sha256Util sha256Util) {
this.sha256Util = sha256Util;
}
public Event replacePersistentIdWithHashedPersistentId(final Event event) {
final EnumMap details = event.getDetails();
if (details != null) {
final String pid = details.get(EventDetailsKey.pid);
if (pid != null) {
final String idpEntityId = details.get(EventDetailsKey.idp_entity_id);
final EnumMap newDetails = new EnumMap<>(EventDetailsKey.class);
if (idpEntityId == null) {
newDetails.put(EventDetailsKey.pid, PID_REMOVED);
} else {
final String hashedPid = sha256Util.hash(idpEntityId, pid);
newDetails.put(EventDetailsKey.pid, hashedPid);
}
for (EventDetailsKey e : details.keySet()) {
if (e != EventDetailsKey.pid) {
newDetails.put(e, details.get(e));
}
}
return new EventMessage(
event.getEventId(),
event.getTimestamp(),
event.getEventType(),
event.getOriginatingService(),
event.getSessionId(),
newDetails);
}
}
return event;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy