@Test public void testRegetSession() throws Exception { Session session1 = createMock(Session.class); Session session2 = createMock(Session.class); mockSubject.logout(); expect(mockSubject.getSession(true)) .andReturn(session1).times(1) .andReturn(session2).times(1); expect(mockSubject.getSession(false)) .andReturn(session1).times(2) .andReturn(null).times(3); replay(mockSubject); assertNotNull(request.getSession(true)); assertNotNull(request.getSession(false)); mockSubject.logout(); assertNull(request.getSession(false)); assertNotNull(request.getSession(true)); verify(mockSubject); }
public HttpSession getSession(boolean create) { HttpSession httpSession; if (isHttpSessions()) { httpSession = super.getSession(false); if (httpSession == null && create) { if (WebUtils._isSessionCreationEnabled(this)) { httpSession = super.getSession(create); } else { throw newNoSessionCreationException(); } } } else { boolean existing = getSubject().getSession(false) != null; if (this.session == null || !existing) { Session shiroSession = getSubject().getSession(create); if (shiroSession != null) { this.session = new ShiroHttpSession(shiroSession, this, this.servletContext); if (!existing) { setAttribute(REFERENCED_SESSION_IS_NEW, Boolean.TRUE); } } else if (this.session != null) { this.session = null; } } httpSession = this.session; } return httpSession; }
ShiroHttpServletRequest extends HttpServletRequestWrapper { public HttpSession getSession(boolean create) { HttpSession httpSession; if (isHttpSessions()) { httpSession = super.getSession(false); if (httpSession == null && create) { if (WebUtils._isSessionCreationEnabled(this)) { httpSession = super.getSession(create); } else { throw newNoSessionCreationException(); } } } else { boolean existing = getSubject().getSession(false) != null; if (this.session == null || !existing) { Session shiroSession = getSubject().getSession(create); if (shiroSession != null) { this.session = new ShiroHttpSession(shiroSession, this, this.servletContext); if (!existing) { setAttribute(REFERENCED_SESSION_IS_NEW, Boolean.TRUE); } } else if (this.session != null) { this.session = null; } } httpSession = this.session; } return httpSession; } }
ShiroHttpServletRequest extends HttpServletRequestWrapper { public HttpSession getSession(boolean create) { HttpSession httpSession; if (isHttpSessions()) { httpSession = super.getSession(false); if (httpSession == null && create) { if (WebUtils._isSessionCreationEnabled(this)) { httpSession = super.getSession(create); } else { throw newNoSessionCreationException(); } } } else { boolean existing = getSubject().getSession(false) != null; if (this.session == null || !existing) { Session shiroSession = getSubject().getSession(create); if (shiroSession != null) { this.session = new ShiroHttpSession(shiroSession, this, this.servletContext); if (!existing) { setAttribute(REFERENCED_SESSION_IS_NEW, Boolean.TRUE); } } else if (this.session != null) { this.session = null; } } httpSession = this.session; } return httpSession; } ShiroHttpServletRequest(HttpServletRequest wrapped, ServletContext servletContext, boolean httpSessions); }
ShiroHttpServletRequest extends HttpServletRequestWrapper { public HttpSession getSession(boolean create) { HttpSession httpSession; if (isHttpSessions()) { httpSession = super.getSession(false); if (httpSession == null && create) { if (WebUtils._isSessionCreationEnabled(this)) { httpSession = super.getSession(create); } else { throw newNoSessionCreationException(); } } } else { boolean existing = getSubject().getSession(false) != null; if (this.session == null || !existing) { Session shiroSession = getSubject().getSession(create); if (shiroSession != null) { this.session = new ShiroHttpSession(shiroSession, this, this.servletContext); if (!existing) { setAttribute(REFERENCED_SESSION_IS_NEW, Boolean.TRUE); } } else if (this.session != null) { this.session = null; } } httpSession = this.session; } return httpSession; } ShiroHttpServletRequest(HttpServletRequest wrapped, ServletContext servletContext, boolean httpSessions); boolean isHttpSessions(); String getRemoteUser(); boolean isUserInRole(String s); Principal getUserPrincipal(); String getRequestedSessionId(); HttpSession getSession(boolean create); HttpSession getSession(); boolean isRequestedSessionIdValid(); boolean isRequestedSessionIdFromCookie(); boolean isRequestedSessionIdFromURL(); boolean isRequestedSessionIdFromUrl(); }
ShiroHttpServletRequest extends HttpServletRequestWrapper { public HttpSession getSession(boolean create) { HttpSession httpSession; if (isHttpSessions()) { httpSession = super.getSession(false); if (httpSession == null && create) { if (WebUtils._isSessionCreationEnabled(this)) { httpSession = super.getSession(create); } else { throw newNoSessionCreationException(); } } } else { boolean existing = getSubject().getSession(false) != null; if (this.session == null || !existing) { Session shiroSession = getSubject().getSession(create); if (shiroSession != null) { this.session = new ShiroHttpSession(shiroSession, this, this.servletContext); if (!existing) { setAttribute(REFERENCED_SESSION_IS_NEW, Boolean.TRUE); } } else if (this.session != null) { this.session = null; } } httpSession = this.session; } return httpSession; } ShiroHttpServletRequest(HttpServletRequest wrapped, ServletContext servletContext, boolean httpSessions); boolean isHttpSessions(); String getRemoteUser(); boolean isUserInRole(String s); Principal getUserPrincipal(); String getRequestedSessionId(); HttpSession getSession(boolean create); HttpSession getSession(); boolean isRequestedSessionIdValid(); boolean isRequestedSessionIdFromCookie(); boolean isRequestedSessionIdFromURL(); boolean isRequestedSessionIdFromUrl(); static final String COOKIE_SESSION_ID_SOURCE; static final String URL_SESSION_ID_SOURCE; static final String REFERENCED_SESSION_ID; static final String REFERENCED_SESSION_ID_IS_VALID; static final String REFERENCED_SESSION_IS_NEW; static final String REFERENCED_SESSION_ID_SOURCE; static final String IDENTITY_REMOVED_KEY; static final String SESSION_ID_URL_REWRITING_ENABLED; }