Merge branch '7.0.x'

This commit is contained in:
Joe Grandja 2026-01-23 06:43:14 -05:00
commit fc5194d78b
2 changed files with 15 additions and 1 deletions

View File

@ -98,9 +98,11 @@ public final class BearerTokenAuthenticationEntryPoint implements Authentication
}
private static String getResourceMetadataParameter(HttpServletRequest request) {
String path = request.getContextPath()
+ OAuth2ProtectedResourceMetadataFilter.DEFAULT_OAUTH2_PROTECTED_RESOURCE_METADATA_ENDPOINT_URI;
// @formatter:off
return UriComponentsBuilder.fromUriString(UrlUtils.buildFullRequestUrl(request))
.replacePath(OAuth2ProtectedResourceMetadataFilter.DEFAULT_OAUTH2_PROTECTED_RESOURCE_METADATA_ENDPOINT_URI)
.replacePath(path)
.replaceQuery(null)
.fragment(null)
.build()

View File

@ -65,6 +65,18 @@ public class BearerTokenAuthenticationEntryPointTests {
"Bearer realm=\"test\", resource_metadata=\"http://localhost/.well-known/oauth-protected-resource\"");
}
@Test
public void commenceWhenNoBearerTokenErrorAndContextPathSetThenStatus401AndAuthHeaderWithContextPath() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/ctx");
MockHttpServletResponse response = new MockHttpServletResponse();
this.authenticationEntryPoint.commence(request, response, new BadCredentialsException("test"));
assertThat(response.getStatus()).isEqualTo(401);
assertThat(response.getHeader("WWW-Authenticate"))
.isEqualTo("Bearer resource_metadata=\"http://localhost/ctx/.well-known/oauth-protected-resource\"");
}
@Test
public void commenceWhenInvalidRequestErrorThenStatus400AndHeaderWithError() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();