From 82db55c3f8ce680b9164cba38103f683bc0085db Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 17 Oct 2022 18:04:10 +0200 Subject: [PATCH] Polish SessionRepositoryFilter This commit polishes SessionRepositoryFilter by simplifying some code paths. --- .../session/web/http/SessionRepositoryFilter.java | 12 ++---------- .../web/http/SessionRepositoryFilterTests.java | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index be5e03203..46af1c4d0 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -267,14 +267,7 @@ public boolean isRequestedSessionIdValid() { if (requestedSession != null) { requestedSession.setLastAccessedTime(Instant.now()); } - return isRequestedSessionIdValid(requestedSession); - } - return this.requestedSessionIdValid; - } - - private boolean isRequestedSessionIdValid(S session) { - if (this.requestedSessionIdValid == null) { - this.requestedSessionIdValid = session != null; + this.requestedSessionIdValid = (requestedSession != null); } return this.requestedSessionIdValid; } @@ -358,7 +351,6 @@ private S getRequestedSession() { S session = SessionRepositoryFilter.this.sessionRepository.findById(sessionId); if (session != null) { this.requestedSession = session; - this.requestedSessionId = sessionId; break; } } diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java index 1042b9489..62fe90c05 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java @@ -1327,7 +1327,7 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap } }); - // 2 invocations expected: initial resolution, after invalidation, after commit + // 2 invocations expected: initial resolution, after invalidation verify(sessionRepository, times(2)).findById(eq(session.getId())); verify(sessionRepository).deleteById(eq(session.getId())); verify(sessionRepository).createSession();