congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
MockHttpServletRequestBuilder.session
Code IndexAdd Tabnine to your IDE (free)

How to use
session
method
in
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

Best Java code snippets using org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.session (Showing top 20 results out of 315)

origin: hs-web/hsweb-framework

protected MockHttpServletRequestBuilder initDefaultSetting(MockHttpServletRequestBuilder builder) {
  return builder.session(session).characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON);
}
origin: spring-projects/spring-framework

@Test
public void session() {
  MockHttpSession session = new MockHttpSession(this.servletContext);
  session.setAttribute("foo", "bar");
  this.builder.session(session);
  this.builder.sessionAttr("baz", "qux");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals(session, request.getSession());
  assertEquals("bar", request.getSession().getAttribute("foo"));
  assertEquals("qux", request.getSession().getAttribute("baz"));
}
origin: cloudfoundry/uaa

private ResultActions performGetMfaManualRegister() throws Exception {
  return getMockMvc().perform(get("/login/mfa/manual")
   .session(session)
  );
}
origin: spring-projects/spring-security

  private static RequestBuilder formLogin(MockHttpSession session) {
    return post("/login")
        .param("username", "user")
        .param("password", "password")
        .session(session)
        .with(csrf());
  }
}
origin: cloudfoundry/uaa

@Test
public void testRedirectToMfaAfterLogin() throws Exception {
  redirectToMFARegistration();
  MockHttpServletResponse response = getMockMvc().perform(get("/profile")
   .session(session)).andReturn().getResponse();
  assertTrue(response.getRedirectedUrl().contains("/login"));
}
origin: cloudfoundry/uaa

@Test
public void testRedirectToLoginPageAfterClickingBackFromMfaRegistrationPage() throws Exception {
  redirectToMFARegistration();
  MockHttpServletResponse response = getMockMvc().perform(get("/logout.do")
   .session(session)).andReturn().getResponse();
  assertTrue(response.getRedirectedUrl().endsWith("/login"));
}
origin: spring-projects/spring-security

@Test
public void requestWhenSessionFixationProtectionIsMigrateSessionThenSessionIsReplaced()
    throws Exception {
  this.spring.configLocations(this.xml("SessionFixationProtectionMigrateSession")).autowire();
  MockHttpSession session = new MockHttpSession();
  String sessionId = session.getId();
  MvcResult result =
    this.mvc.perform(get("/auth")
        .session(session)
        .with(httpBasic("user", "password")))
        .andExpect(session())
        .andReturn();
  assertThat(result.getRequest().getSession(false).getId()).isNotEqualTo(sessionId);
}
origin: cloudfoundry/uaa

  private void login(MockHttpSession session) throws Exception {
    mockMvc.perform(
        post("/login.do")
            .with(cookieCsrf())
            .param("username", "marissa")
            .param("password", "koala")
            .session(session)
    ).andExpect(redirectedUrl("/"));
  }
}
origin: cloudfoundry/uaa

@Test
void testSilentAuthentication_Returns400_whenInvalidRedirectUrlIsProvided() throws Exception {
  MockHttpSession session = new MockHttpSession();
  login(session);
  mockMvc.perform(
      get("/oauth/authorize?response_type=token&scope=openid&client_id=ant&prompt=none&redirect_uri=no good uri")
          .session(session)
  )
      .andExpect(status().is4xxClientError());
}
origin: spring-projects/spring-security

@Test
public void servletLogoutWhenUsingDefaultConfigurationThenUsesSpringSecurity()
    throws Exception {
  this.spring.configLocations(this.xml("Simple")).autowire();
  MvcResult result = this.mvc.perform(get("/good-login")).andReturn();
  MockHttpSession session = (MockHttpSession) result.getRequest().getSession(false);
  assertThat(session).isNotNull();
  result = this.mvc.perform(get("/do-logout").session(session))
      .andExpect(status().isOk())
      .andExpect(content().string(""))
      .andReturn();
  session = (MockHttpSession) result.getRequest().getSession(false);
  assertThat(session).isNull();
}
origin: cloudfoundry/uaa

public static String performMfaPostVerifyWithCode(int code, MockMvc mvc, MockHttpSession session, String host) throws Exception {
  return mvc.perform(post("/login/mfa/verify.do")
   .param("code", Integer.toString(code))
   .header("Host", host)
   .session(session)
   .with(cookieCsrf()))
   .andExpect(status().is3xxRedirection())
   .andExpect(redirectedUrl("/login/mfa/completed"))
   .andReturn().getResponse().getRedirectedUrl();
}
origin: spring-projects/spring-security

@Test
public void logoutWhenDefaultConfigurationThenCsrfCleared()
  throws Exception {
  this.spring.configLocations(
      this.xml("shared-controllers"),
      this.xml("AutoConfig")
    ).autowire();
  MvcResult result = this.mvc.perform(get("/csrf")).andReturn();
  MockHttpSession session = (MockHttpSession) result.getRequest().getSession();
  this.mvc.perform(post("/logout").session(session)
            .with(csrf()))
      .andExpect(status().isFound());
  this.mvc.perform(get("/csrf").session(session))
      .andExpect(csrfChanged(result));
}
origin: spring-projects/spring-security

@Test
public void requestWhenConcurrencyControlIsSetThenDefaultsToResponseBodyExpirationResponse()
    throws Exception {
  this.spring.configLocations(this.xml("ConcurrencyControlSessionRegistryAlias")).autowire();
  this.mvc.perform(get("/auth")
      .session(this.expiredSession())
      .with(httpBasic("user", "password")))
      .andExpect(content().string("This session has been expired (possibly due to multiple concurrent "
          + "logins being attempted as the same user)."));
}
origin: spring-projects/spring-security

@Test
public void requestWhenCreateSessionIsSetToStatelessThenIgnoresExistingSession()
    throws Exception {
  this.spring.configLocations(this.xml("CreateSessionStateless")).autowire();
  MvcResult result =
      this.mvc.perform(post("/login")
          .param("username", "user")
          .param("password", "password")
          .session(new MockHttpSession())
          .with(csrf()))
          .andExpect(status().isFound())
          .andExpect(session())
          .andReturn();
  assertThat(result.getRequest().getSession(false).getAttribute(SPRING_SECURITY_CONTEXT_KEY))
      .isNull();
}
origin: spring-projects/spring-security

@Test
public void requestWhenSessionFixationProtectionIsNoneThenSessionNotInvalidated()
    throws Exception {
  this.spring.configLocations(this.xml("SessionFixationProtectionNone")).autowire();
  MockHttpSession session = new MockHttpSession();
  String sessionId = session.getId();
  this.mvc.perform(get("/auth")
      .session(session)
      .with(httpBasic("user", "password")))
      .andExpect(session().id(sessionId));
}
origin: spring-projects/spring-security

@Test
public void requestWhenExpiredUrlIsSetThenInvalidatesSessionAndRedirects()
    throws Exception {
  this.spring.configLocations(this.xml("ConcurrencyControlExpiredUrl")).autowire();
  this.mvc.perform(get("/auth")
      .session(this.expiredSession())
      .with(httpBasic("user", "password")))
      .andExpect(redirectedUrl("/expired"))
      .andExpect(session().exists(false));
}
origin: spring-projects/spring-security

/**
 * SEC-2137
 */
@Test
public void requestWhenSessionFixationProtectionDisabledAndConcurrencyControlEnabledThenSessionNotInvalidated()
    throws Exception {
  this.spring.configLocations(this.xml("Sec2137")).autowire();
  MockHttpSession session = new MockHttpSession();
  this.mvc.perform(get("/auth")
      .session(session)
      .with(httpBasic("user", "password")))
      .andExpect(status().isOk())
      .andExpect(session().id(session.getId()));
}
origin: spring-projects/spring-security

@Test
public void requestWhenConcurrencyControlAndRememberMeAreSetThenInvokedWhenSessionExpires()
    throws Exception {
  this.spring.configLocations(this.xml("ConcurrencyControlRememberMeHandler")).autowire();
  this.mvc.perform(get("/auth")
      .session(this.expiredSession())
      .with(httpBasic("user", "password")))
      .andExpect(status().isOk())
      .andExpect(cookie().exists("rememberMeCookie"))
      .andExpect(session().exists(false));
}
origin: spring-projects/spring-security

@Test
public void requestWhenConcurrencyControlAndCustomLogoutHandlersAreSetThenAllAreInvokedWhenSessionExpires()
    throws Exception {
  this.spring.configLocations(this.xml("ConcurrencyControlLogoutAndRememberMeHandlers")).autowire();
  this.mvc.perform(get("/auth")
      .session(this.expiredSession())
      .with(httpBasic("user", "password")))
      .andExpect(status().isOk())
      .andExpect(cookie().maxAge("testCookie", 0))
      .andExpect(cookie().exists("rememberMeCookie"))
      .andExpect(session().valid(true));
}
origin: spring-projects/spring-security

@Test
@WithMockUser
public void postWhenCsrfMismatchesThenForbidden()
  throws Exception {
  this.spring.configLocations(
      this.xml("shared-controllers"),
      this.xml("AutoConfig")
    ).autowire();
  MvcResult result = this.mvc.perform(get("/ok")).andReturn();
  MockHttpSession session = (MockHttpSession) result.getRequest().getSession();
  this.mvc.perform(post("/ok")
            .session(session)
            .with(csrf().useInvalidToken()))
      .andExpect(status().isForbidden());
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuildersession

Javadoc

Set the HTTP session to use, possibly re-used across requests.

Individual attributes provided via #sessionAttr(String,Object)override the content of the session provided here.

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • content
    Set the request body.
  • param
    Add a request parameter to the MockHttpServletRequest.If called more than once, new values get added
  • accept
    Set the 'Accept' header to the given media type(s).
  • header
    Add a header to the request. Values are always added.
  • with
    An extension point for further initialization of MockHttpServletRequestin ways not built directly in
  • requestAttr
    Set a request attribute.
  • buildRequest
    Build a MockHttpServletRequest.
  • contextPath
    Specify the portion of the requestURI that represents the context path. The context path, if specifi
  • principal
    Set the principal of the request.
  • flashAttr
    Set an "input" flash attribute.
  • headers
    Add all headers to the request. Values are always added.
  • flashAttr,
  • headers,
  • sessionAttr,
  • cookie,
  • params,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Updating database using SQL prepared statement
  • setScale (BigDecimal)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JComboBox (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now