use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class OAuth2AuthorizedClientArgumentResolver method resolveArgument.
@NonNull
@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) {
String clientRegistrationId = this.resolveClientRegistrationId(parameter);
if (StringUtils.isEmpty(clientRegistrationId)) {
throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or " + "@RegisteredOAuth2AuthorizedClient(registrationId = \"client1\").");
}
Authentication principal = SecurityContextHolder.getContext().getAuthentication();
if (principal == null) {
principal = ANONYMOUS_AUTHENTICATION;
}
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
// @formatter:off
OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest.withClientRegistrationId(clientRegistrationId).principal(principal).attribute(HttpServletRequest.class.getName(), servletRequest).attribute(HttpServletResponse.class.getName(), servletResponse).build();
// @formatter:on
return this.authorizedClientManager.authorize(authorizeRequest);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class ServletOAuth2AuthorizedClientExchangeFilterFunction method authorizeClient.
private Mono<OAuth2AuthorizedClient> authorizeClient(String clientRegistrationId, ClientRequest request) {
if (this.authorizedClientManager == null) {
return Mono.empty();
}
Map<String, Object> attrs = request.attributes();
Authentication authentication = getAuthentication(attrs);
if (authentication == null) {
authentication = ANONYMOUS_AUTHENTICATION;
}
HttpServletRequest servletRequest = getRequest(attrs);
HttpServletResponse servletResponse = getResponse(attrs);
OAuth2AuthorizeRequest.Builder builder = OAuth2AuthorizeRequest.withClientRegistrationId(clientRegistrationId).principal(authentication);
builder.attributes((attributes) -> addToAttributes(attributes, servletRequest, servletResponse));
OAuth2AuthorizeRequest authorizeRequest = builder.build();
// blocking I/O operation using RestTemplate internally
return Mono.fromSupplier(() -> this.authorizedClientManager.authorize(authorizeRequest)).subscribeOn(Schedulers.boundedElastic());
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class ServletOAuth2AuthorizedClientExchangeFilterFunction method removeAuthorizedClient.
private void removeAuthorizedClient(OAuth2AuthorizedClientRepository authorizedClientRepository, String clientRegistrationId, Authentication principal, Map<String, Object> attributes) {
HttpServletRequest request = getRequest(attributes);
HttpServletResponse response = getResponse(attributes);
authorizedClientRepository.removeAuthorizedClient(clientRegistrationId, principal, request, response);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class DebugFilterTests method doFilterProcessesForwardedRequests.
// SEC-1901
@Test
public void doFilterProcessesForwardedRequests() throws Exception {
setupMocks();
given(this.request.getAttribute(this.requestAttr)).willReturn(Boolean.TRUE);
HttpServletRequest request = new DebugRequestWrapper(this.request);
this.filter.doFilter(request, this.response, this.filterChain);
verify(this.logger).info(anyString());
verify(this.fcp).doFilter(request, this.response, this.filterChain);
verify(this.request, never()).removeAttribute(this.requestAttr);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class StrictHttpFirewallTests method getFirewalledRequestGetHeadersWhenControlCharacterInHeaderValueThenException.
@Test
public void getFirewalledRequestGetHeadersWhenControlCharacterInHeaderValueThenException() {
this.request.addHeader("Something", "bad\0value");
HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getHeaders("Something").nextElement());
}
Aggregations