Java Code Examples for org.springframework.web.server.WebSession#getId()
The following examples show how to use
org.springframework.web.server.WebSession#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryWebSessionStoreTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void retrieveExpiredSession() { WebSession session = this.store.createWebSession().block(); assertNotNull(session); session.getAttributes().put("foo", "bar"); session.save().block(); String id = session.getId(); WebSession retrieved = this.store.retrieveSession(id).block(); assertNotNull(retrieved); assertSame(session, retrieved); // Fast-forward 31 minutes this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofMinutes(31))); WebSession retrievedAgain = this.store.retrieveSession(id).block(); assertNull(retrievedAgain); }
Example 2
Source File: InMemoryWebSessionStoreTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void lastAccessTimeIsUpdatedOnRetrieve() { WebSession session1 = this.store.createWebSession().block(); assertNotNull(session1); String id = session1.getId(); Instant time1 = session1.getLastAccessTime(); session1.start(); session1.save().block(); // Fast-forward a few seconds this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofSeconds(5))); WebSession session2 = this.store.retrieveSession(id).block(); assertNotNull(session2); assertSame(session1, session2); Instant time2 = session2.getLastAccessTime(); assertTrue(time1.isBefore(time2)); }
Example 3
Source File: InMemoryWebSessionStoreTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void retrieveExpiredSession() { WebSession session = this.store.createWebSession().block(); assertNotNull(session); session.getAttributes().put("foo", "bar"); session.save().block(); String id = session.getId(); WebSession retrieved = this.store.retrieveSession(id).block(); assertNotNull(retrieved); assertSame(session, retrieved); // Fast-forward 31 minutes this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofMinutes(31))); WebSession retrievedAgain = this.store.retrieveSession(id).block(); assertNull(retrievedAgain); }
Example 4
Source File: InMemoryWebSessionStoreTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void lastAccessTimeIsUpdatedOnRetrieve() { WebSession session1 = this.store.createWebSession().block(); assertNotNull(session1); String id = session1.getId(); Instant time1 = session1.getLastAccessTime(); session1.start(); session1.save().block(); // Fast-forward a few seconds this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofSeconds(5))); WebSession session2 = this.store.retrieveSession(id).block(); assertNotNull(session2); assertSame(session1, session2); Instant time2 = session2.getLastAccessTime(); assertTrue(time1.isBefore(time2)); }
Example 5
Source File: InMemoryWebSessionStoreTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-17051 public void sessionInvalidatedBeforeSave() { // Request 1 creates session WebSession session1 = this.store.createWebSession().block(); assertNotNull(session1); String id = session1.getId(); session1.start(); session1.save().block(); // Request 2 retrieves session WebSession session2 = this.store.retrieveSession(id).block(); assertNotNull(session2); assertSame(session1, session2); // Request 3 retrieves and invalidates WebSession session3 = this.store.retrieveSession(id).block(); assertNotNull(session3); assertSame(session1, session3); session3.invalidate().block(); // Request 2 saves session after invalidated session2.save().block(); // Session should not be present WebSession session4 = this.store.retrieveSession(id).block(); assertNull(session4); }
Example 6
Source File: InMemoryWebSessionStoreTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-17051 public void sessionInvalidatedBeforeSave() { // Request 1 creates session WebSession session1 = this.store.createWebSession().block(); assertNotNull(session1); String id = session1.getId(); session1.start(); session1.save().block(); // Request 2 retrieves session WebSession session2 = this.store.retrieveSession(id).block(); assertNotNull(session2); assertSame(session1, session2); // Request 3 retrieves and invalidates WebSession session3 = this.store.retrieveSession(id).block(); assertNotNull(session3); assertSame(session1, session3); session3.invalidate().block(); // Request 2 saves session after invalidated session2.save().block(); // Session should not be present WebSession session4 = this.store.retrieveSession(id).block(); assertNull(session4); }