Search in sources :

Example 1 with PortResolverImpl

use of org.springframework.security.web.PortResolverImpl 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 PortResolverImpl

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

the class HttpSessionRequestCacheTests method getRequestCustomNoClassCastException.

// SEC-2246
@Test
public void getRequestCustomNoClassCastException() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("POST", "/destination");
    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpSessionRequestCache cache = new HttpSessionRequestCache() {

        @Override
        public void saveRequest(HttpServletRequest request, HttpServletResponse response) {
            request.getSession().setAttribute(SAVED_REQUEST, new CustomSavedRequest(new DefaultSavedRequest(request, new PortResolverImpl())));
        }
    };
    cache.saveRequest(request, response);
    cache.saveRequest(request, response);
    assertThat(cache.getRequest(request, response)).isInstanceOf(CustomSavedRequest.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) PortResolverImpl(org.springframework.security.web.PortResolverImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with PortResolverImpl

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

the class DefaultSavedRequestMixinTests method serializeDefaultRequestBuildWithConstructorTest.

@Test
public void serializeDefaultRequestBuildWithConstructorTest() throws IOException, JSONException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setCookies(new Cookie("SESSION", "123456789"));
    request.addHeader("x-auth-token", "12");
    String actualString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new DefaultSavedRequest(request, new PortResolverImpl()));
    JSONAssert.assertEquals(REQUEST_JSON, actualString, true);
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) PortResolverImpl(org.springframework.security.web.PortResolverImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 PortResolverImpl (org.springframework.security.web.PortResolverImpl)3 Cookie (javax.servlet.http.Cookie)2 DefaultSavedRequest (org.springframework.security.web.savedrequest.DefaultSavedRequest)2 SavedCookie (org.springframework.security.web.savedrequest.SavedCookie)2 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1