Skip to content

Commit 6846137

Browse files
committed
Session events are ignored for public api page calls
1 parent c3910d2 commit 6846137

File tree

2 files changed

+82
-121
lines changed

2 files changed

+82
-121
lines changed

orcid-web/src/main/java/org/orcid/frontend/spring/session/redis/OrcidRedisIndexedSessionRepository.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.commons.logging.Log;
44
import org.apache.commons.logging.LogFactory;
5+
import org.orcid.api.common.analytics.APIEndpointParser;
56
import org.springframework.context.ApplicationContextAware;
67
import org.springframework.context.ApplicationEvent;
78
import org.springframework.context.ApplicationEventPublisher;
@@ -52,15 +53,15 @@ public class OrcidRedisIndexedSessionRepository implements FindByIndexNameSessio
5253
private RedisSerializer<Object> defaultSerializer = new JdkSerializationRedisSerializer();
5354
private FlushMode flushMode;
5455
private SaveMode saveMode;
55-
private final List<String> urisToSkip = List.of("/account/biographyForm.json", "/account/countryForm.json", "/account/emails.json",
56-
"/account/nameForm.json", "/account/preferences.json", "/affiliations/affiliationGroups.json", "/affiliations/affiliationDetails.json",
57-
"/assets/vectors/orcid.logo.icon.svg", "/config.json", "/delegators/delegators-and-me.json", "/fundings/fundingDetails.json",
58-
"/fundings/fundingGroups.json", "/inbox/unreadCount.json", "/my-orcid/externalIdentifiers.json", "/my-orcid/keywordsForms.json",
59-
"/my-orcid/otherNamesForms.json", "/my-orcid/websitesForms.json", "/peer-reviews/peer-reviews-minimized.json",
60-
"/research-resources/researchResourcePage.json", "/research-resources/researchResource.json", "/works/worksExtendedPage.json",
61-
"/works/groupingSuggestions.json", "/works/getWorkInfo.json", "/works/work.json", "/works/idTypes.json", "/orgs/disambiguated/ROR",
62-
"/orgs/disambiguated/GRID", "/orgs/disambiguated/FUNDREF", "/ng-cli-ws", "/not-found", "/peer-reviews/peer-review.json",
63-
"/peer-reviews/peer-reviews-by-group-id.json");
56+
private final String PUBLIC_ORCID_PAGE_REGEX = "/(\\d{4}-){3,}\\d{3}[\\dX](/.+)";
57+
private final List<String> urisToSkip = List.of("/2FA/status.json", "/account/", "/account/biographyForm.json", "/account/countryForm.json", "/account/delegates.json", "/account/emails.json",
58+
"/account/get-trusted-orgs.json", "/account/nameForm.json", "/account/preferences.json", "/account/socialAccounts.json", "/affiliations/affiliationDetails.json", "/affiliations/affiliationGroups.json",
59+
"/assets/vectors/orcid.logo.icon.svg", "/config.json", "/delegators/delegators-and-me.json", "/fundings/fundingDetails.json", "/fundings/fundingGroups.json", "/inbox/notifications.json",
60+
"/inbox/totalCount.json", "/inbox/unreadCount.json", "/my-orcid/externalIdentifiers.json", "/my-orcid/keywordsForms.json", "/my-orcid/otherNamesForms.json", "/my-orcid/websitesForms.json",
61+
"/ng-cli-ws", "/not-found", "/notifications/frequencies/view", "/orgs/disambiguated/FUNDREF", "/orgs/disambiguated/GRID", "/orgs/disambiguated/LEI", "/orgs/disambiguated/RINGGOLD",
62+
"/orgs/disambiguated/ROR", "/peer-reviews/peer-review.json", "/peer-reviews/peer-reviews-by-group-id.json", "/peer-reviews/peer-reviews-minimized.json", "/qr-code.png",
63+
"/research-resources/researchResource.json", "/research-resources/researchResourcePage.json", "/works/getWorkInfo.json", "/works/groupingSuggestions.json", "/works/idTypes.json", "/works/work.json",
64+
"/works/worksExtendedPage.json");
6465
private final Set<String> SKIP_SAVE_SESSION = new HashSet<>(urisToSkip);
6566

6667
public OrcidRedisIndexedSessionRepository(RedisOperations<Object, Object> sessionRedisOperations) {
@@ -129,7 +130,7 @@ public void save(OrcidRedisIndexedSessionRepository.RedisSession session) {
129130

130131
if(updateSession()) {
131132
//TODO: REMOVE THIS LOG ENTRY BEFORE GOING LIVE!!!!
132-
logger.info("Saving session for " + request.getRequestURI());
133+
logger.info("Saving session for " + request.getRequestURI() + " - " + request.getMethod());
133134
session.save();
134135
if (session.isNew) {
135136
String sessionCreatedKey = this.getSessionCreatedChannel(session.getId());
@@ -138,7 +139,7 @@ public void save(OrcidRedisIndexedSessionRepository.RedisSession session) {
138139
}
139140
} else {
140141
//TODO: REMOVE THIS LOG ENTRY BEFORE GOING LIVE!!!!
141-
logger.info("Skip save session id " + request.getRequestURI());
142+
logger.info("Skip save session id " + request.getRequestURI() + " - " + request.getMethod());
142143
}
143144
}
144145

@@ -205,11 +206,11 @@ private MapSession loadSession(String id, Map<Object, Object> entries) {
205206
///////////////////////////////////////////////
206207
if(updateSession()) {
207208
// TODO: REMOVE THIS LOG ENTRY BEFORE GOING LIVE!!!
208-
logger.info("Updating last accessed time for " + request.getRequestURI());
209+
logger.info("Updating last accessed time for " + request.getRequestURI() + " - " + request.getMethod());
209210
loaded.setLastAccessedTime(Instant.ofEpochMilli((Long) entry.getValue()));
210211
} else {
211212
// TODO: REMOVE THIS LOG ENTRY BEFORE GOING LIVE!!!
212-
logger.info("Ignoring last accessed time for " + request.getRequestURI());
213+
logger.info("Ignoring last accessed time for " + request.getRequestURI() + " - " + request.getMethod());
213214
}
214215
} else if (key.startsWith("sessionAttr:")) {
215216
loaded.setAttribute(key.substring("sessionAttr:".length()), entry.getValue());
@@ -362,7 +363,13 @@ private BoundHashOperations<Object, Object, Object> getSessionBoundHashOperation
362363
private boolean updateSession() {
363364
ServletRequestAttributes att = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
364365
HttpServletRequest request = att.getRequest();
365-
return (!SKIP_SAVE_SESSION.contains(request.getRequestURI().substring(request.getContextPath().length())));
366+
if(request.getMethod().equals("GET")) {
367+
String url = request.getRequestURI().substring(request.getContextPath().length());
368+
if(SKIP_SAVE_SESSION.contains(url) || url.matches(PUBLIC_ORCID_PAGE_REGEX)) {
369+
return false;
370+
}
371+
}
372+
return true;
366373
}
367374

368375
static String getSessionAttrNameKey(String attributeName) {
@@ -402,7 +409,7 @@ public void setLastAccessedTime(Instant lastAccessedTime) {
402409
// TODO: REMOVE THIS BEFORE GOING LIVE!!!!
403410
ServletRequestAttributes att = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
404411
HttpServletRequest request = att.getRequest();
405-
System.out.println("REDIS_SESSION: setLastAccessedTime: " + request.getRequestURI().toString());
412+
System.out.println("REDIS_SESSION: setLastAccessedTime: " + request.getRequestURI().toString() + " - " + request.getMethod());
406413

407414
this.cached.setLastAccessedTime(lastAccessedTime);
408415
this.delta.put("lastAccessedTime", this.getLastAccessedTime().toEpochMilli());

0 commit comments

Comments
 (0)