use of jakarta.servlet.http.HttpSession in project spring-security by spring-projects.
the class RememberMeConfigurerTests method logoutWhenRememberMeCookieThenAuthenticationIsRememberMeCookieExpired.
@Test
public void logoutWhenRememberMeCookieThenAuthenticationIsRememberMeCookieExpired() throws Exception {
this.spring.register(RememberMeConfig.class).autowire();
// @formatter:off
MockHttpServletRequestBuilder loginRequest = post("/login").with(csrf()).param("username", "user").param("password", "password").param("remember-me", "true");
// @formatter:on
MvcResult mvcResult = this.mvc.perform(loginRequest).andReturn();
Cookie rememberMeCookie = mvcResult.getResponse().getCookie("remember-me");
HttpSession session = mvcResult.getRequest().getSession();
// @formatter:off
MockHttpServletRequestBuilder logoutRequest = post("/logout").with(csrf()).cookie(rememberMeCookie).session((MockHttpSession) session);
this.mvc.perform(logoutRequest).andExpect(redirectedUrl("/login?logout")).andExpect(cookie().maxAge("remember-me", 0));
// @formatter:on
}
use of jakarta.servlet.http.HttpSession in project spring-security by spring-projects.
the class SessionManagementConfigurerTests method loginWhenUserSessionExpiredAndMaxSessionsIsOneThenLoggedIn.
@Test
public void loginWhenUserSessionExpiredAndMaxSessionsIsOneThenLoggedIn() throws Exception {
this.spring.register(ConcurrencyControlConfig.class).autowire();
// @formatter:off
MockHttpServletRequestBuilder firstRequest = post("/login").with(csrf()).param("username", "user").param("password", "password");
MvcResult mvcResult = this.mvc.perform(firstRequest).andReturn();
// @formatter:on
HttpSession authenticatedSession = mvcResult.getRequest().getSession();
this.spring.getContext().publishEvent(new HttpSessionDestroyedEvent(authenticatedSession));
// @formatter:off
MockHttpServletRequestBuilder secondRequest = post("/login").with(csrf()).param("username", "user").param("password", "password");
this.mvc.perform(secondRequest).andExpect(status().isFound()).andExpect(redirectedUrl("/"));
// @formatter:on
}
use of jakarta.servlet.http.HttpSession in project spring-security by spring-projects.
the class SessionManagementConfigurerTests method requestWhenSessionCreationPolicyStateLessInLambdaThenNoSessionCreated.
@Test
public void requestWhenSessionCreationPolicyStateLessInLambdaThenNoSessionCreated() throws Exception {
this.spring.register(SessionCreationPolicyStateLessInLambdaConfig.class).autowire();
MvcResult mvcResult = this.mvc.perform(get("/")).andReturn();
HttpSession session = mvcResult.getRequest().getSession(false);
assertThat(session).isNull();
}
use of jakarta.servlet.http.HttpSession in project spring-security by spring-projects.
the class SecurityContextConfigurerTests method requestWhenSecurityContextWithDefaultsInLambdaThenSessionIsCreated.
@Test
public void requestWhenSecurityContextWithDefaultsInLambdaThenSessionIsCreated() throws Exception {
this.spring.register(SecurityContextWithDefaultsInLambdaConfig.class).autowire();
MvcResult mvcResult = this.mvc.perform(formLogin()).andReturn();
HttpSession session = mvcResult.getRequest().getSession(false);
assertThat(session).isNotNull();
}
use of jakarta.servlet.http.HttpSession in project spring-security by spring-projects.
the class SecurityContextConfigurerTests method requestWhenNullSecurityContextRepositoryInLambdaThenContextNotSavedInSession.
@Test
public void requestWhenNullSecurityContextRepositoryInLambdaThenContextNotSavedInSession() throws Exception {
this.spring.register(NullSecurityContextRepositoryInLambdaConfig.class).autowire();
MvcResult mvcResult = this.mvc.perform(formLogin()).andReturn();
HttpSession session = mvcResult.getRequest().getSession(false);
assertThat(session).isNull();
}
Aggregations