Search in sources :

Example 1 with SavedCookie

use of org.springframework.security.web.savedrequest.SavedCookie in project spring-security by spring-projects.

the class DefaultSavedRequestMixinTests method matchRequestBuildWithConstructorAndBuilder.

// @formatter:on
@Test
public void matchRequestBuildWithConstructorAndBuilder() {
    DefaultSavedRequest request = new DefaultSavedRequest.Builder().setCookies(Collections.singletonList(new SavedCookie(new Cookie("SESSION", "123456789")))).setHeaders(Collections.singletonMap("x-auth-token", Collections.singletonList("12"))).setScheme("http").setRequestURL("http://localhost").setServerName("localhost").setRequestURI("").setLocales(Collections.singletonList(new Locale("en"))).setContextPath("").setMethod("").setServletPath("").build();
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setCookies(new Cookie("SESSION", "123456789"));
    mockRequest.addHeader("x-auth-token", "12");
    assert request.doesRequestMatch(mockRequest, new PortResolverImpl());
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) Locale(java.util.Locale) PortResolverImpl(org.springframework.security.web.PortResolverImpl) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Example 2 with SavedCookie

use of org.springframework.security.web.savedrequest.SavedCookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method deserializeSavedCookieJsonTest.

@Test
public void deserializeSavedCookieJsonTest() throws IOException {
    SavedCookie savedCookie = (SavedCookie) mapper.readValue(COOKIE_JSON, Object.class);
    assertThat(savedCookie).isNotNull();
    assertThat(savedCookie.getName()).isEqualTo("SESSION");
    assertThat(savedCookie.getValue()).isEqualTo("123456789");
    assertThat(savedCookie.isSecure()).isEqualTo(false);
    assertThat(savedCookie.getVersion()).isEqualTo(0);
    assertThat(savedCookie.getComment()).isNull();
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Test(org.junit.Test)

Example 3 with SavedCookie

use of org.springframework.security.web.savedrequest.SavedCookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeSavedCookieWithList.

@Test
public void serializeSavedCookieWithList() throws JsonProcessingException, JSONException {
    List<SavedCookie> savedCookies = new ArrayList<SavedCookie>();
    savedCookies.add(new SavedCookie(new Cookie("SESSION", "123456789")));
    String actualJson = mapper.writeValueAsString(savedCookies);
    JSONAssert.assertEquals(COOKIES_JSON, actualJson, true);
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with SavedCookie

use of org.springframework.security.web.savedrequest.SavedCookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeWithOverrideConfigurationTest.

@Test
public void serializeWithOverrideConfigurationTest() throws JsonProcessingException, JSONException {
    SavedCookie savedCookie = new SavedCookie(new Cookie("SESSION", "123456789"));
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PUBLIC_ONLY).setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.ANY);
    String actualJson = mapper.writeValueAsString(savedCookie);
    JSONAssert.assertEquals(COOKIE_JSON, actualJson, true);
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Test(org.junit.Test)

Example 5 with SavedCookie

use of org.springframework.security.web.savedrequest.SavedCookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeWithDefaultConfigurationTest.

// @formatter:on
@Test
public void serializeWithDefaultConfigurationTest() throws JsonProcessingException, JSONException {
    SavedCookie savedCookie = new SavedCookie(new Cookie("SESSION", "123456789"));
    String actualJson = mapper.writeValueAsString(savedCookie);
    JSONAssert.assertEquals(COOKIE_JSON, actualJson, true);
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Test(org.junit.Test)

Aggregations

SavedCookie (org.springframework.security.web.savedrequest.SavedCookie)7 Cookie (javax.servlet.http.Cookie)6 Test (org.junit.Test)6 Locale (java.util.Locale)2 DefaultSavedRequest (org.springframework.security.web.savedrequest.DefaultSavedRequest)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 PortResolverImpl (org.springframework.security.web.PortResolverImpl)1