use of org.springframework.web.context.request.ServletRequestAttributes in project skeleton-commons by skeleton-software-community.
the class TokenFromCookieExtractor method extractToken.
@Override
public String extractToken(String key) {
String result = tokenFromHeaderExtractor.extractToken(key);
if (result != null) {
return result;
}
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Cookie[] cookies = servletRequestAttributes.getRequest().getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals(key)) {
result = cookie.getValue();
break;
}
}
return result;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-security by spring-projects.
the class ServletOAuth2AuthorizedClientExchangeFilterFunction method populateDefaultRequestResponse.
private void populateDefaultRequestResponse(Map<String, Object> attrs) {
if (attrs.containsKey(HTTP_SERVLET_REQUEST_ATTR_NAME) && attrs.containsKey(HTTP_SERVLET_RESPONSE_ATTR_NAME)) {
return;
}
RequestAttributes context = RequestContextHolder.getRequestAttributes();
if (context instanceof ServletRequestAttributes) {
attrs.putIfAbsent(HTTP_SERVLET_REQUEST_ATTR_NAME, ((ServletRequestAttributes) context).getRequest());
attrs.putIfAbsent(HTTP_SERVLET_RESPONSE_ATTR_NAME, ((ServletRequestAttributes) context).getResponse());
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-security by spring-projects.
the class SecurityReactorContextConfigurationTests method createSubscriberIfNecessaryWhenWebSecurityContextAvailableThenCreateWithParentContext.
@Test
public void createSubscriberIfNecessaryWhenWebSecurityContextAvailableThenCreateWithParentContext() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.servletRequest, this.servletResponse));
SecurityContextHolder.getContext().setAuthentication(this.authentication);
String testKey = "test_key";
String testValue = "test_value";
BaseSubscriber<Object> parent = new BaseSubscriber<Object>() {
@Override
public Context currentContext() {
return Context.of(testKey, testValue);
}
};
CoreSubscriber<Object> subscriber = this.subscriberRegistrar.createSubscriberIfNecessary(parent);
Context resultContext = subscriber.currentContext();
assertThat(resultContext.getOrEmpty(testKey)).hasValue(testValue);
Map<Object, Object> securityContextAttributes = resultContext.getOrDefault(SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES, null);
assertThat(securityContextAttributes).hasSize(3);
assertThat(securityContextAttributes).contains(entry(HttpServletRequest.class, this.servletRequest), entry(HttpServletResponse.class, this.servletResponse), entry(Authentication.class, this.authentication));
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-framework by spring-projects.
the class MvcUriComponentsBuilderTests method adaptRequestFromForwardedHeaders.
// SPR-16668
private void adaptRequestFromForwardedHeaders() throws Exception {
MockFilterChain chain = new MockFilterChain();
new ForwardedHeaderFilter().doFilter(this.request, new MockHttpServletResponse(), chain);
HttpServletRequest adaptedRequest = (HttpServletRequest) chain.getRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(adaptedRequest));
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-framework by spring-projects.
the class RequestContextFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
ServletRequestAttributes attributes = new ServletRequestAttributes(request, response);
initContextHolders(request, attributes);
try {
filterChain.doFilter(request, response);
} finally {
resetContextHolders();
if (logger.isTraceEnabled()) {
logger.trace("Cleared thread-bound request context: " + request);
}
attributes.requestCompleted();
}
}
Aggregations