Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consent revocation data not getting published #26

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class CDSConsentEventExecutor implements OBEventExecutor {
private static final String USER_ID_KEY = "userId";
private static final String STATUS_KEY = "status";
private static final String EXPIRY_TIME_KEY = "expiryTime";
private static final ConcurrentLinkedDeque<String> publishedRequestUriKeyQueue = new ConcurrentLinkedDeque<>();
private static final ConcurrentLinkedDeque<String> publishedEventIdentifierQueue = new ConcurrentLinkedDeque<>();

@Override
public void processEvent(OBEvent obEvent) {
Expand Down Expand Up @@ -160,12 +160,13 @@ public void processEvent(OBEvent obEvent) {

log.debug("Publishing consent data for authorisation metrics.");
String consentId = (String) eventData.get(CONSENT_ID);
ConsentStatusEnum consentStatus = getConsentStatusForEventType(obEvent.getEventType());
AuthorisationFlowTypeEnum authFlowType = getAuthFlowTypeForEventType(obEvent.getEventType());
String requestUriKey = getRequestUriKeyFromConsentResource(consentResource, detailedConsentResource);
if (requestUriKey != null && publishedRequestUriKeyQueue.contains(requestUriKey)) {
String eventType = obEvent.getEventType();
ConsentStatusEnum consentStatus = getConsentStatusForEventType(eventType);
AuthorisationFlowTypeEnum authFlowType = getAuthFlowTypeForEventType(eventType);
String eventIdentifier = getEventIdentifier(consentResource, detailedConsentResource, eventType);
if (eventIdentifier != null && publishedEventIdentifierQueue.contains(eventIdentifier)) {
if (log.isDebugEnabled()) {
log.debug("Skipping authorisation data publishing for requestUriKey: " + requestUriKey +
log.debug("Skipping authorisation data publishing for event identifier: " + eventIdentifier +
" as it has already been published.");
}
return;
Expand All @@ -190,7 +191,7 @@ public void processEvent(OBEvent obEvent) {
consentStatus, authFlowType, customerProfile, consentDurationType);

dataPublishingService.publishAuthorisationData(authorisationData);
addToPublishedRequestUriKeyQueue(requestUriKey);
addToPublishedEventIdentifierQueue(eventIdentifier);
}

}
Expand Down Expand Up @@ -390,32 +391,32 @@ private AuthorisationFlowTypeEnum getAuthFlowTypeForEventType(String eventType)
}

/**
* Add the request uri key to the published data queue.
* Add the event identifier to the published data queue.
* If the queue is full, oldest key is removed.
* 20 keys are maintained in the queue to handle simultaneous consent state change events.
*
* @param requestUriKey request uri key coming as a consent attribute
* @param eventIdentifier request uri key coming as a consent attribute + event type to identify a unique event.
*/
private void addToPublishedRequestUriKeyQueue(String requestUriKey) {
private void addToPublishedEventIdentifierQueue(String eventIdentifier) {

if (StringUtils.isBlank(requestUriKey)) {
if (StringUtils.isBlank(eventIdentifier)) {
return;
}
if (publishedRequestUriKeyQueue.size() >= 20) {
publishedRequestUriKeyQueue.pollFirst();
if (publishedEventIdentifierQueue.size() >= 20) {
publishedEventIdentifierQueue.pollFirst();
}
publishedRequestUriKeyQueue.addLast(requestUriKey);
publishedEventIdentifierQueue.addLast(eventIdentifier);
}

private String getRequestUriKeyFromConsentResource(ConsentResource consentResource,
DetailedConsentResource detailedConsentResource) {
private String getEventIdentifier(ConsentResource consentResource, DetailedConsentResource detailedConsentResource,
String eventType) {

Map<String, String> consentAttributes = null;
if (consentResource != null) {
consentAttributes = consentResource.getConsentAttributes();
} else if (detailedConsentResource != null) {
consentAttributes = detailedConsentResource.getConsentAttributes();
}
return consentAttributes != null ? consentAttributes.get(REQUEST_URI_KEY) : null;
return consentAttributes != null ? (consentAttributes.get(REQUEST_URI_KEY) + ":" + eventType) : null;
}
}
Loading