SessionRepository.getSession(String) -> findById(String)

Issue gh-809
This commit is contained in:
Rob Winch
2017-06-22 21:16:51 -05:00
parent cd8686ae9c
commit 0127ef9f9b
28 changed files with 88 additions and 88 deletions

View File

@@ -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.
====

View File

@@ -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> 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>
// ...
}

View File

@@ -81,7 +81,7 @@ public class RememberMeSecurityConfigurationTests<T extends Session> {
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));

View File

@@ -81,7 +81,7 @@ public class RememberMeSecurityConfigurationXmlTests<T extends Session> {
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));

View File

@@ -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;
}

View File

@@ -81,7 +81,7 @@ public class MapSessionRepository implements SessionRepository<Session> {
return session;
}
public Session getSession(String id) {
public Session findById(String id) {
Session saved = this.sessions.get(id);
if (saved == null) {
return null;

View File

@@ -62,7 +62,7 @@ public interface SessionRepository<S extends Session> {
* @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

View File

@@ -91,7 +91,7 @@ class SpringSessionBackedSessionInformation<S extends Session>
+ "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);

View File

@@ -78,7 +78,7 @@ public class SpringSessionBackedSessionRegistry<S extends Session>
}
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);

View File

@@ -121,7 +121,7 @@ import org.springframework.util.Assert;
* entry.getValue();
* </code>
*
* 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; }

View File

@@ -324,7 +324,7 @@ public class SessionRepositoryFilter<S extends Session>
private S getSession(String sessionId) {
S session = SessionRepositoryFilter.this.sessionRepository
.getSession(sessionId);
.findById(sessionId);
if (session == null) {
return null;
}

View File

@@ -121,7 +121,7 @@ public final class SessionRepositoryMessageInterceptor<S extends Session>
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());

View File

@@ -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

View File

@@ -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);

View File

@@ -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))

View File

@@ -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);
}

View File

@@ -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.<SessionDestroyedEvent>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.<String>getAttribute("a")).isEqualTo(Optional.of("b"));
assertThat(session.<String>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);

View File

@@ -76,7 +76,7 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends Session
if (!this.registry.receivedEvent()) {
// Redis makes no guarantees on when an expired event will be fired
// we can ensure it gets fired by trying to get the session
this.repository.getSession(toSave.getId());
this.repository.findById(toSave.getId());
synchronized (this.lock) {
if (!this.registry.receivedEvent()) {
// wait at most a minute

View File

@@ -40,7 +40,7 @@ public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends Se
public void savesOnCreate() throws InterruptedException {
S created = this.sessionRepository.createSession();
S getSession = this.sessionRepository.getSession(created.getId());
S getSession = this.sessionRepository.findById(created.getId());
assertThat(getSession).isNotNull();
}

View File

@@ -170,7 +170,7 @@ import org.springframework.util.Assert;
* </p>
*
* <p>
* <b>NOTE:</b> The {@link #getSession(String)} method ensures that no expired sessions
* <b>NOTE:</b> 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
* </p>
@@ -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<String, RedisSession> 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);
}

View File

@@ -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.<String>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

View File

@@ -94,7 +94,7 @@ public class EnableHazelcastHttpSessionEventsTests<S extends Session> {
assertThat(this.registry.<SessionCreatedEvent>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<S extends Session> {
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionExpiredEvent.class);
assertThat(this.repository.<Session>getSession(sessionToSave.getId())).isNull();
assertThat(this.repository.<Session>findById(sessionToSave.getId())).isNull();
}
@Test
@@ -141,7 +141,7 @@ public class EnableHazelcastHttpSessionEventsTests<S extends Session> {
assertThat(this.registry.<SessionDeletedEvent>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<S extends Session> {
}
// 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<S extends Session> {
lock.wait(sessionToUpdate.getMaxInactiveInterval().minusMillis(100).toMillis());
}
assertThat(this.repository.getSession(sessionToUpdate.getId())).isNotNull();
assertThat(this.repository.findById(sessionToUpdate.getId())).isNotNull();
}
@Configuration

View File

@@ -61,7 +61,7 @@ public class HazelcastHttpSessionConfigurationXmlTests<S extends Session> {
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<S extends Session> {
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())

View File

@@ -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;

View File

@@ -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.<String>getAttribute("savedName").orElse(null)).isEqualTo("savedValue");

View File

@@ -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.<String>getAttribute("a")).isEqualTo(Optional.of("b"));
assertThat(session.<String>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() {

View File

@@ -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<Session> sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query(
JdbcOperationsSessionRepository.this.getSessionQuery,

View File

@@ -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();