diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc index 4276d94a..d32d6ae2 100644 --- a/docs/src/docs/asciidoc/index.adoc +++ b/docs/src/docs/asciidoc/index.adoc @@ -649,7 +649,7 @@ An expiration is set on the session itself five minutes after it actually expire [NOTE] ==== -The `SessionRepository.getSession(String)` method ensures that no expired sessions will be returned. +The `SessionRepository.findById(String)` method ensures that no expired sessions will be returned. This means there is no need to check the expiration before using a session. ==== diff --git a/docs/src/test/java/docs/IndexDocTests.java b/docs/src/test/java/docs/IndexDocTests.java index 73aba876..a368d3f5 100644 --- a/docs/src/test/java/docs/IndexDocTests.java +++ b/docs/src/test/java/docs/IndexDocTests.java @@ -70,7 +70,7 @@ public class IndexDocTests { this.repository.save(toSave); // <4> - S session = this.repository.getSession(toSave.getId()); // <5> + S session = this.repository.findById(toSave.getId()); // <5> // <6> Optional user = session.getAttribute(ATTR_USER); @@ -100,7 +100,7 @@ public class IndexDocTests { this.repository.save(toSave); // <4> - S session = this.repository.getSession(toSave.getId()); // <5> + S session = this.repository.findById(toSave.getId()); // <5> // ... } diff --git a/docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java b/docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java index 5eb89e5f..d7e11c54 100644 --- a/docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java +++ b/docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java @@ -81,7 +81,7 @@ public class RememberMeSecurityConfigurationTests { Cookie cookie = result.getResponse().getCookie("SESSION"); assertThat(cookie.getMaxAge()).isEqualTo(Integer.MAX_VALUE); T session = this.sessions - .getSession(new String(Base64.getDecoder().decode(cookie.getValue()))); + .findById(new String(Base64.getDecoder().decode(cookie.getValue()))); assertThat(session.getMaxInactiveInterval()) .isEqualTo(Duration.ofDays(30)); diff --git a/docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java b/docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java index 70ed0406..432a54be 100644 --- a/docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java +++ b/docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java @@ -81,7 +81,7 @@ public class RememberMeSecurityConfigurationXmlTests { Cookie cookie = result.getResponse().getCookie("SESSION"); assertThat(cookie.getMaxAge()).isEqualTo(Integer.MAX_VALUE); T session = this.sessions - .getSession(new String(Base64.getDecoder().decode(cookie.getValue()))); + .findById(new String(Base64.getDecoder().decode(cookie.getValue()))); assertThat(session.getMaxInactiveInterval()) .isEqualTo(Duration.ofDays(30)); diff --git a/samples/javaconfig/users/src/main/java/sample/UserAccountsFilter.java b/samples/javaconfig/users/src/main/java/sample/UserAccountsFilter.java index 7acf468b..29f86611 100644 --- a/samples/javaconfig/users/src/main/java/sample/UserAccountsFilter.java +++ b/samples/javaconfig/users/src/main/java/sample/UserAccountsFilter.java @@ -62,7 +62,7 @@ public class UserAccountsFilter implements Filter { String alias = entry.getKey(); String sessionId = entry.getValue(); - Session session = repo.getSession(sessionId); + Session session = repo.findById(sessionId); if (session == null) { continue; } diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java index ef1150f1..b3f1d712 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java @@ -81,7 +81,7 @@ public class MapSessionRepository implements SessionRepository { return session; } - public Session getSession(String id) { + public Session findById(String id) { Session saved = this.sessions.get(id); if (saved == null) { return null; diff --git a/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java index 7e9a1c36..b95cd169 100644 --- a/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java +++ b/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java @@ -62,7 +62,7 @@ public interface SessionRepository { * @return the {@link Session} by the {@link Session#getId()} or null if no * {@link Session} is found. */ - S getSession(String id); + S findById(String id); /** * Deletes the {@link Session} with the given {@link Session#getId()} or does nothing diff --git a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java index 5f25742f..d78aec29 100644 --- a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java +++ b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java @@ -91,7 +91,7 @@ class SpringSessionBackedSessionInformation + "sessions was exceeded"); } super.expireNow(); - S session = this.sessionRepository.getSession(getSessionId()); + S session = this.sessionRepository.findById(getSessionId()); if (session != null) { session.setAttribute(EXPIRED_ATTR, Boolean.TRUE); this.sessionRepository.save(session); diff --git a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionRegistry.java b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionRegistry.java index c424ec12..59d950fa 100644 --- a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionRegistry.java +++ b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionRegistry.java @@ -78,7 +78,7 @@ public class SpringSessionBackedSessionRegistry } public SessionInformation getSessionInformation(String sessionId) { - S session = this.sessionRepository.getSession(sessionId); + S session = this.sessionRepository.findById(sessionId); if (session != null) { return new SpringSessionBackedSessionInformation<>(session, this.sessionRepository); diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java b/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java index a3593c83..32947d82 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java @@ -121,7 +121,7 @@ import org.springframework.util.Assert; * entry.getValue(); * * - * Session session = repo.getSession(sessionId); if(session == null) { continue; } + * Session session = repo.findById(sessionId); if(session == null) { continue; } * * String username = session.getAttribute("username"); if(username == null) { * newSessionAlias = alias; continue; } 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 c3f7acee..41d05f03 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 @@ -324,7 +324,7 @@ public class SessionRepositoryFilter private S getSession(String sessionId) { S session = SessionRepositoryFilter.this.sessionRepository - .getSession(sessionId); + .findById(sessionId); if (session == null) { return null; } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java b/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java index eea7c4c7..bed2a3a9 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java @@ -121,7 +121,7 @@ public final class SessionRepositoryMessageInterceptor String sessionId = sessionHeaders == null ? null : (String) sessionHeaders.get(SPRING_SESSION_ID_ATTR_NAME); if (sessionId != null) { - S session = this.sessionRepository.getSession(sessionId); + S session = this.sessionRepository.findById(sessionId); if (session != null) { // update the last accessed time session.setLastAccessedTime(Instant.now()); diff --git a/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java b/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java index 62f185a3..0149abe2 100644 --- a/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java @@ -42,7 +42,7 @@ public class MapSessionRepositoryTests { this.session.setLastAccessedTime(Instant.now().minus(5, ChronoUnit.MINUTES)); this.repository.save(this.session); - assertThat(this.repository.getSession(this.session.getId())).isNull(); + assertThat(this.repository.findById(this.session.getId())).isNull(); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java b/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java index 694d6bcd..68037b9a 100644 --- a/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java +++ b/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java @@ -69,7 +69,7 @@ public class SpringSessionBackedSessionRegistryTest { @Test public void sessionInformationForExistingSession() { Session session = createSession(SESSION_ID, USER_NAME, NOW); - when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session); + when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session); SessionInformation sessionInfo = this.sessionRegistry .getSessionInformation(SESSION_ID); @@ -85,7 +85,7 @@ public class SpringSessionBackedSessionRegistryTest { Session session = createSession(SESSION_ID, USER_NAME, NOW); session.setAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR, Boolean.TRUE); - when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session); + when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session); SessionInformation sessionInfo = this.sessionRegistry .getSessionInformation(SESSION_ID); @@ -127,7 +127,7 @@ public class SpringSessionBackedSessionRegistryTest { @Test public void expireNow() { Session session = createSession(SESSION_ID, USER_NAME, NOW); - when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session); + when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session); SessionInformation sessionInfo = this.sessionRegistry .getSessionInformation(SESSION_ID); 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 6fe627c0..3f510b54 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 @@ -422,7 +422,7 @@ public class SessionRepositoryFilterTests { public void doFilterSetsCookieIfChanged() throws Exception { this.sessionRepository = new MapSessionRepository() { @Override - public Session getSession(String id) { + public Session findById(String id) { return createSession(); } }; @@ -539,7 +539,7 @@ public class SessionRepositoryFilterTests { // the old session was removed final String changedSessionId = getSessionCookie().getValue(); assertThat(originalSessionId).isNotEqualTo(changedSessionId); - assertThat(this.sessionRepository.getSession(originalSessionId)).isNull(); + assertThat(this.sessionRepository.findById(originalSessionId)).isNull(); nextRequest(); @@ -1051,7 +1051,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1066,7 +1066,7 @@ public class SessionRepositoryFilterTests { wrappedResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error"); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1080,7 +1080,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.sendRedirect("/"); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1094,7 +1094,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.flushBuffer(); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1108,7 +1108,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.getOutputStream().flush(); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1122,7 +1122,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.getOutputStream().close(); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1136,7 +1136,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.getWriter().flush(); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1150,7 +1150,7 @@ public class SessionRepositoryFilterTests { String id = wrappedRequest.getSession().getId(); wrappedResponse.getWriter().close(); assertThat(SessionRepositoryFilterTests.this.sessionRepository - .getSession(id)).isNotNull(); + .findById(id)).isNotNull(); } }); } @@ -1187,7 +1187,7 @@ public class SessionRepositoryFilterTests { }); HttpServletRequest request = (HttpServletRequest) this.chain.getRequest(); - Session session = this.sessionRepository.getSession(request.getSession().getId()); + Session session = this.sessionRepository.findById(request.getSession().getId()); verify(this.strategy).onNewSession(eq(session), any(HttpServletRequest.class), any(HttpServletResponse.class)); } @@ -1363,7 +1363,7 @@ public class SessionRepositoryFilterTests { // will not find the session) HttpSession session = wrappedRequest.getSession(false); verify(SessionRepositoryFilterTests.this.sessionRepository, times(1)) - .getSession(nonExistantSessionId); + .findById(nonExistantSessionId); assertThat(session).isNull(); assertThat(SessionRepositoryFilterTests.this.request .getAttribute(SessionRepositoryFilter.INVALID_SESSION_ID_ATTR)) @@ -1372,7 +1372,7 @@ public class SessionRepositoryFilterTests { // Second call should not reach the sessionRepository session = wrappedRequest.getSession(false); verify(SessionRepositoryFilterTests.this.sessionRepository, times(1)) - .getSession(nonExistantSessionId); // still only called once + .findById(nonExistantSessionId); // still only called once assertThat(session).isNull(); assertThat(SessionRepositoryFilterTests.this.request .getAttribute(SessionRepositoryFilter.INVALID_SESSION_ID_ATTR)) diff --git a/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java b/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java index f4b9f92b..01be92bb 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java @@ -76,7 +76,7 @@ public class SessionRepositoryMessageInterceptorTests { setMessageType(SimpMessageType.MESSAGE); String sessionId = "http-session"; setSessionId(sessionId); - given(this.sessionRepository.getSession(sessionId)).willReturn(this.session); + given(this.sessionRepository.findById(sessionId)).willReturn(this.session); } @Test(expected = IllegalArgumentException.class) @@ -147,7 +147,7 @@ public class SessionRepositoryMessageInterceptorTests { assertThat(this.interceptor.preSend(createMessage(), this.channel)) .isSameAs(this.createMessage); - verify(this.sessionRepository).getSession(anyString()); + verify(this.sessionRepository).findById(anyString()); verify(this.sessionRepository).save(this.session); } diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java index 8bc6c2ec..abeea1d6 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java @@ -83,7 +83,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { assertThat(this.redis.boundSetOps(usernameSessionKey).members()) .contains(toSave.getId()); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); @@ -94,7 +94,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.delete(toSave.getId()); - assertThat(this.repository.getSession(toSave.getId())).isNull(); + assertThat(this.repository.findById(toSave.getId())).isNull(); assertThat(this.registry.getEvent(toSave.getId())) .isInstanceOf(SessionDestroyedEvent.class); assertThat(this.redis.boundSetOps(usernameSessionKey).members()) @@ -111,14 +111,14 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { toSave.setAttribute("a", "b"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("1", "2"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getAttributeNames().size()).isEqualTo(2); assertThat(session.getAttribute("a")).isEqualTo(Optional.of("b")); assertThat(session.getAttribute("1")).isEqualTo(Optional.of("2")); @@ -202,7 +202,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave); @@ -262,7 +262,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - RedisSession getSession = this.repository.getSession(toSave.getId()); + RedisSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -281,7 +281,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - RedisSession getSession = this.repository.getSession(toSave.getId()); + RedisSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, principalNameChanged); this.repository.save(getSession); @@ -367,7 +367,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave); @@ -423,7 +423,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - RedisSession getSession = this.repository.getSession(toSave.getId()); + RedisSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -440,7 +440,7 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests { this.repository.save(toSave); - RedisSession getSession = this.repository.getSession(toSave.getId()); + RedisSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext); this.repository.save(getSession); diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java index daa0ae99..38f3c2f9 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java @@ -76,7 +76,7 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests * *

- * NOTE: The {@link #getSession(String)} method ensures that no expired sessions + * NOTE: The {@link #findById(String)} method ensures that no expired sessions * will be returned. This means there is no need to check the expiration before using a * session *

@@ -401,7 +401,7 @@ public class RedisOperationsSessionRepository implements this.expirationPolicy.cleanExpiredSessions(); } - public RedisSession getSession(String id) { + public RedisSession findById(String id) { return getSession(id, false); } @@ -416,7 +416,7 @@ public class RedisOperationsSessionRepository implements Map sessions = new HashMap<>( sessionIds.size()); for (Object id : sessionIds) { - RedisSession session = getSession((String) id); + RedisSession session = findById((String) id); if (session != null) { sessions.put(session.getId(), session); } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java index 5faf3807..85449223 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java @@ -202,7 +202,7 @@ public class RedisOperationsSessionRepositoryTests { // the actual data in the session expires 5 minutes after expiration so the data // can be accessed in expiration events // if the session is retrieved and expired it will not be returned since - // getSession checks if it is expired + // findById checks if it is expired long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5) .getSeconds(); verify(this.boundHashOperations).expire(fiveMinutesAfterExpires, @@ -232,7 +232,7 @@ public class RedisOperationsSessionRepositoryTests { // the actual data in the session expires 5 minutes after expiration so the data // can be accessed in expiration events // if the session is retrieved and expired it will not be returned since - // getSession checks if it is expired + // findById checks if it is expired verify(this.boundHashOperations).expire( session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); @@ -370,7 +370,7 @@ public class RedisOperationsSessionRepositoryTests { .willReturn(this.boundHashOperations); given(this.boundHashOperations.entries()).willReturn(map()); - assertThat(this.redisRepository.getSession(id)).isNull(); + assertThat(this.redisRepository.findById(id)).isNull(); } @Test @@ -391,7 +391,7 @@ public class RedisOperationsSessionRepositoryTests { expected.getLastAccessedTime().toEpochMilli()); given(this.boundHashOperations.entries()).willReturn(map); - RedisSession session = this.redisRepository.getSession(expected.getId()); + RedisSession session = this.redisRepository.findById(expected.getId()); assertThat(session.getId()).isEqualTo(expected.getId()); assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames()); assertThat(session.getAttribute(attrName)) @@ -414,7 +414,7 @@ public class RedisOperationsSessionRepositoryTests { Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli()); given(this.boundHashOperations.entries()).willReturn(map); - assertThat(this.redisRepository.getSession(expiredId)).isNull(); + assertThat(this.redisRepository.findById(expiredId)).isNull(); } @Test diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java index f71d6bd6..b87e7443 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java @@ -94,7 +94,7 @@ public class EnableHazelcastHttpSessionEventsTests { assertThat(this.registry.getEvent(sessionToSave.getId())) .isInstanceOf(SessionCreatedEvent.class); - Session session = this.repository.getSession(sessionToSave.getId()); + Session session = this.repository.findById(sessionToSave.getId()); assertThat(session.getId()).isEqualTo(sessionToSave.getId()); assertThat(session.getAttributeNames()) @@ -121,7 +121,7 @@ public class EnableHazelcastHttpSessionEventsTests { assertThat(this.registry.getEvent(sessionToSave.getId())) .isInstanceOf(SessionExpiredEvent.class); - assertThat(this.repository.getSession(sessionToSave.getId())).isNull(); + assertThat(this.repository.findById(sessionToSave.getId())).isNull(); } @Test @@ -141,7 +141,7 @@ public class EnableHazelcastHttpSessionEventsTests { assertThat(this.registry.getEvent(sessionToSave.getId())) .isInstanceOf(SessionDeletedEvent.class); - assertThat(this.repository.getSession(sessionToSave.getId())).isNull(); + assertThat(this.repository.findById(sessionToSave.getId())).isNull(); } @Test @@ -157,7 +157,7 @@ public class EnableHazelcastHttpSessionEventsTests { } // Get and save the session like SessionRepositoryFilter would. - S sessionToUpdate = this.repository.getSession(sessionToSave.getId()); + S sessionToUpdate = this.repository.findById(sessionToSave.getId()); sessionToUpdate.setLastAccessedTime(Instant.now()); this.repository.save(sessionToUpdate); @@ -165,7 +165,7 @@ public class EnableHazelcastHttpSessionEventsTests { lock.wait(sessionToUpdate.getMaxInactiveInterval().minusMillis(100).toMillis()); } - assertThat(this.repository.getSession(sessionToUpdate.getId())).isNotNull(); + assertThat(this.repository.findById(sessionToUpdate.getId())).isNotNull(); } @Configuration diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationXmlTests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationXmlTests.java index 0fc7c0ed..37c3b53d 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationXmlTests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationXmlTests.java @@ -61,7 +61,7 @@ public class HazelcastHttpSessionConfigurationXmlTests { this.repository.save(sessionToSave); - S session = this.repository.getSession(sessionToSave.getId()); + S session = this.repository.findById(sessionToSave.getId()); assertThat(session.getId()).isEqualTo(sessionToSave.getId()); assertThat(session.getMaxInactiveInterval()) @@ -99,7 +99,7 @@ public class HazelcastHttpSessionConfigurationXmlTests { this.repository.save(sessionToSave); - S session = this.repository.getSession(sessionToSave.getId()); + S session = this.repository.findById(sessionToSave.getId()); assertThat(session.getId()).isEqualTo(sessionToSave.getId()); assertThat(session.getMaxInactiveInterval()) diff --git a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java index 3abab3d3..70eaa432 100644 --- a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java +++ b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java @@ -211,7 +211,7 @@ public class HazelcastSessionRepository implements return session; } - public HazelcastSession getSession(String id) { + public HazelcastSession findById(String id) { MapSession saved = this.sessions.get(id); if (saved == null) { return null; diff --git a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastSessionRepositoryTests.java b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastSessionRepositoryTests.java index 0badcf57..8a5c5ac6 100644 --- a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastSessionRepositoryTests.java +++ b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastSessionRepositoryTests.java @@ -243,7 +243,7 @@ public class HazelcastSessionRepositoryTests { public void getSessionNotFound() { String sessionId = "testSessionId"; - HazelcastSession session = this.repository.getSession(sessionId); + HazelcastSession session = this.repository.findById(sessionId); assertThat(session).isNull(); verify(this.sessions, times(1)).get(eq(sessionId)); @@ -256,7 +256,7 @@ public class HazelcastSessionRepositoryTests { MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1)); given(this.sessions.get(eq(expired.getId()))).willReturn(expired); - HazelcastSession session = this.repository.getSession(expired.getId()); + HazelcastSession session = this.repository.findById(expired.getId()); assertThat(session).isNull(); verify(this.sessions, times(1)).get(eq(expired.getId())); @@ -269,7 +269,7 @@ public class HazelcastSessionRepositoryTests { saved.setAttribute("savedName", "savedValue"); given(this.sessions.get(eq(saved.getId()))).willReturn(saved); - HazelcastSession session = this.repository.getSession(saved.getId()); + HazelcastSession session = this.repository.findById(saved.getId()); assertThat(session.getId()).isEqualTo(saved.getId()); assertThat(session.getAttribute("savedName").orElse(null)).isEqualTo("savedValue"); diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java index 4866dcd9..6e18f7a9 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java @@ -102,7 +102,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); @@ -111,7 +111,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.delete(toSave.getId()); - assertThat(this.repository.getSession(toSave.getId())).isNull(); + assertThat(this.repository.findById(toSave.getId())).isNull(); } @Test @@ -130,14 +130,14 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { toSave.setAttribute("a", "b"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("1", "2"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getAttributeNames().size()).isEqualTo(2); assertThat(session.getAttribute("a")).isEqualTo(Optional.of("b")); assertThat(session.getAttribute("1")).isEqualTo(Optional.of("2")); @@ -158,7 +158,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { toSave.setLastAccessedTime(lastAccessedTime); this.repository.save(toSave); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session).isNotNull(); assertThat(session.isExpired()).isFalse(); @@ -239,7 +239,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave); @@ -303,7 +303,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); JdbcOperationsSessionRepository.JdbcSession getSession = this.repository - .getSession(toSave.getId()); + .findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -324,7 +324,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); JdbcOperationsSessionRepository.JdbcSession getSession = this.repository - .getSession(toSave.getId()); + .findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, principalNameChanged); this.repository.save(getSession); @@ -408,7 +408,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave); @@ -468,7 +468,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); JdbcOperationsSessionRepository.JdbcSession getSession = this.repository - .getSession(toSave.getId()); + .findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -487,7 +487,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(toSave); JdbcOperationsSessionRepository.JdbcSession getSession = this.repository - .getSession(toSave.getId()); + .findById(toSave.getId()); getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext); this.repository.save(getSession); @@ -510,11 +510,11 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(session); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); Instant now = Instant.now(); @@ -522,13 +522,13 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(session); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); session.setLastAccessedTime(now.minus(30, ChronoUnit.MINUTES)); this.repository.save(session); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNull(); + assertThat(this.repository.findById(session.getId())).isNull(); } // gh-580 @@ -540,11 +540,11 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(session); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); Instant now = Instant.now(); @@ -552,13 +552,13 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { this.repository.save(session); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNotNull(); + assertThat(this.repository.findById(session.getId())).isNotNull(); session.setLastAccessedTime(now.minus(50, ChronoUnit.MINUTES)); this.repository.save(session); this.repository.cleanUpExpiredSessions(); - assertThat(this.repository.getSession(session.getId())).isNull(); + assertThat(this.repository.findById(session.getId())).isNull(); } private String getSecurityName() { diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java index f3e18ea4..86c3c81a 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java @@ -461,7 +461,7 @@ public class JdbcOperationsSessionRepository implements return session; } - public JdbcSession getSession(final String id) { + public JdbcSession findById(final String id) { final Session session = this.transactionOperations.execute(status -> { List sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query( JdbcOperationsSessionRepository.this.getSessionQuery, diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java index 3f0e419a..5675c16a 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java @@ -404,7 +404,7 @@ public class JdbcOperationsSessionRepositoryTests { .willReturn(Collections.emptyList()); JdbcOperationsSessionRepository.JdbcSession session = this.repository - .getSession(sessionId); + .findById(sessionId); assertThat(session).isNull(); assertPropagationRequiresNew(); @@ -422,7 +422,7 @@ public class JdbcOperationsSessionRepositoryTests { .willReturn(Collections.singletonList(expired)); JdbcOperationsSessionRepository.JdbcSession session = this.repository - .getSession(expired.getId()); + .findById(expired.getId()); assertThat(session).isNull(); assertPropagationRequiresNew(); @@ -441,7 +441,7 @@ public class JdbcOperationsSessionRepositoryTests { .willReturn(Collections.singletonList(saved)); JdbcOperationsSessionRepository.JdbcSession session = this.repository - .getSession(saved.getId()); + .findById(saved.getId()); assertThat(session.getId()).isEqualTo(saved.getId()); assertThat(session.isNew()).isFalse();