use of jakarta.servlet.http.HttpServletRequestWrapper in project tomcat by apache.
the class Request method setRequest.
/**
* Set a wrapped HttpServletRequest to pass to the application. Components
* wishing to wrap the request should obtain the request via
* {@link #getRequest()}, wrap it and then call this method with the
* wrapped request.
*
* @param applicationRequest The wrapped request to pass to the application
*/
public void setRequest(HttpServletRequest applicationRequest) {
// Check the wrapper wraps this request
ServletRequest r = applicationRequest;
while (r instanceof HttpServletRequestWrapper) {
r = ((HttpServletRequestWrapper) r).getRequest();
}
if (r != facade) {
throw new IllegalArgumentException(sm.getString("request.illegalWrap"));
}
this.applicationRequest = applicationRequest;
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class HttpSessionSecurityContextRepositoryTests method traverseWrappedRequests.
// SEC-2578
@Test
public void traverseWrappedRequests() {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
SecurityContext context = repo.loadContext(holder);
assertThat(request.getSession(false)).isNull();
// Simulate authentication during the request
context.setAuthentication(this.testToken);
repo.saveContext(context, new HttpServletRequestWrapper(holder.getRequest()), new HttpServletResponseWrapper(holder.getResponse()));
assertThat(request.getSession(false)).isNotNull();
assertThat(request.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)).isEqualTo(context);
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class DebugFilterTests method doFilterDoesNotWrapWithDebugRequestWrapperAgain.
@Test
public void doFilterDoesNotWrapWithDebugRequestWrapperAgain() throws Exception {
setupMocks();
given(this.request.getAttribute(this.requestAttr)).willReturn(Boolean.TRUE);
HttpServletRequest fireWalledRequest = new HttpServletRequestWrapper(new DebugRequestWrapper(this.request));
this.filter.doFilter(fireWalledRequest, this.response, this.filterChain);
verify(this.fcp).doFilter(fireWalledRequest, this.response, this.filterChain);
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class DefaultSavedRequestMixinTests method serializeDefaultRequestBuildWithConstructorTest.
@Test
public void serializeDefaultRequestBuildWithConstructorTest() throws IOException, JSONException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("x-auth-token", "12");
// Spring 5 MockHttpServletRequest automatically adds a header when the cookies
// are set. To get consistency we override the request.
HttpServletRequest requestToWrite = new HttpServletRequestWrapper(request) {
@Override
public Cookie[] getCookies() {
return new Cookie[] { new Cookie("SESSION", "123456789") };
}
};
String actualString = this.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new DefaultSavedRequest(requestToWrite, new PortResolverImpl()));
JSONAssert.assertEquals(REQUEST_JSON, actualString, true);
}
Aggregations