HttpSessionStorage implements SAMLMessageStorage { public XMLObject retrieveMessage(String messageID) { Hashtable<String, SAMLObject<XMLObject>> messages = getMessages(); SAMLObject o = messages.get(messageID); if (o == null) { log.debug("Message {} not found in session {}", messageID, session.getId()); return null; } else { log.debug("Message {} found in session {}, clearing", messageID, session.getId()); messages.clear(); updateSession(messages); return o.getObject(); } } HttpSessionStorage(HttpServletRequest request);  HttpSessionStorage(HttpSession session); void storeMessage(String messageID, XMLObject message); XMLObject retrieveMessage(String messageID); Set<String> getAllMessages();  }
@Test public void testRaceInitialization() throws Exception { session = createMock(HttpSession.class); expect(session.getId()).andReturn("session123").anyTimes(); expect(session.getAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE)).andReturn(session).anyTimes(); expect(session.getAttribute(SPRING_SAML_STORAGE_KEY)).andReturn(null).times(3); session.setAttribute(eq(SPRING_SAML_STORAGE_KEY), notNull()); expect(session.getAttribute(SPRING_SAML_STORAGE_KEY)).andReturn(new Hashtable()); replay(session); class TestRunner extends Thread { public SAMLMessageStorage storage; public void start() { storage = new HttpSessionStorage(session); storage.retrieveMessage("abc123"); } } TestRunner a = new TestRunner(); TestRunner b = new TestRunner(); synchronized (session) { a.start(); b.start(); synchronized (this) { wait(50); } } verify(session); assertNotNull(a.storage); assertNotNull(b.storage); }