2
2
3
3
import org .apache .commons .logging .Log ;
4
4
import org .apache .commons .logging .LogFactory ;
5
+ import org .orcid .api .common .analytics .APIEndpointParser ;
5
6
import org .springframework .context .ApplicationContextAware ;
6
7
import org .springframework .context .ApplicationEvent ;
7
8
import org .springframework .context .ApplicationEventPublisher ;
@@ -52,15 +53,15 @@ public class OrcidRedisIndexedSessionRepository implements FindByIndexNameSessio
52
53
private RedisSerializer <Object > defaultSerializer = new JdkSerializationRedisSerializer ();
53
54
private FlushMode flushMode ;
54
55
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" );
64
65
private final Set <String > SKIP_SAVE_SESSION = new HashSet <>(urisToSkip );
65
66
66
67
public OrcidRedisIndexedSessionRepository (RedisOperations <Object , Object > sessionRedisOperations ) {
@@ -129,7 +130,7 @@ public void save(OrcidRedisIndexedSessionRepository.RedisSession session) {
129
130
130
131
if (updateSession ()) {
131
132
//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 () );
133
134
session .save ();
134
135
if (session .isNew ) {
135
136
String sessionCreatedKey = this .getSessionCreatedChannel (session .getId ());
@@ -138,7 +139,7 @@ public void save(OrcidRedisIndexedSessionRepository.RedisSession session) {
138
139
}
139
140
} else {
140
141
//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 () );
142
143
}
143
144
}
144
145
@@ -205,11 +206,11 @@ private MapSession loadSession(String id, Map<Object, Object> entries) {
205
206
///////////////////////////////////////////////
206
207
if (updateSession ()) {
207
208
// 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 () );
209
210
loaded .setLastAccessedTime (Instant .ofEpochMilli ((Long ) entry .getValue ()));
210
211
} else {
211
212
// 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 () );
213
214
}
214
215
} else if (key .startsWith ("sessionAttr:" )) {
215
216
loaded .setAttribute (key .substring ("sessionAttr:" .length ()), entry .getValue ());
@@ -362,7 +363,13 @@ private BoundHashOperations<Object, Object, Object> getSessionBoundHashOperation
362
363
private boolean updateSession () {
363
364
ServletRequestAttributes att = (ServletRequestAttributes )RequestContextHolder .getRequestAttributes ();
364
365
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 ;
366
373
}
367
374
368
375
static String getSessionAttrNameKey (String attributeName ) {
@@ -402,7 +409,7 @@ public void setLastAccessedTime(Instant lastAccessedTime) {
402
409
// TODO: REMOVE THIS BEFORE GOING LIVE!!!!
403
410
ServletRequestAttributes att = (ServletRequestAttributes )RequestContextHolder .getRequestAttributes ();
404
411
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 () );
406
413
407
414
this .cached .setLastAccessedTime (lastAccessedTime );
408
415
this .delta .put ("lastAccessedTime" , this .getLastAccessedTime ().toEpochMilli ());
0 commit comments