|
64 | 64 | import org.springframework.security.web.server.context.SecurityContextServerWebExchangeWebFilter;
|
65 | 65 | import org.springframework.web.server.WebFilterChain;
|
66 | 66 | import org.springframework.security.web.server.authentication.AnonymousAuthenticationWebFilterTests;
|
| 67 | +import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint; |
67 | 68 |
|
68 | 69 | /**
|
69 | 70 | * @author Rob Winch
|
@@ -255,6 +256,29 @@ public void basicWithAnonymous() {
|
255 | 256 | assertThat(result.getResponseCookies().getFirst("SESSION")).isNull();
|
256 | 257 | }
|
257 | 258 |
|
| 259 | + @Test |
| 260 | + public void basicWithCustomRealmName() { |
| 261 | + this.http.securityContextRepository(new WebSessionServerSecurityContextRepository()); |
| 262 | + HttpBasicServerAuthenticationEntryPoint authenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint(); |
| 263 | + authenticationEntryPoint.setRealm("myrealm"); |
| 264 | + this.http.httpBasic().authenticationEntryPoint(authenticationEntryPoint); |
| 265 | + this.http.authenticationManager(this.authenticationManager); |
| 266 | + ServerHttpSecurity.AuthorizeExchangeSpec authorize = this.http.authorizeExchange(); |
| 267 | + authorize.anyExchange().authenticated(); |
| 268 | + |
| 269 | + WebTestClient client = buildClient(); |
| 270 | + |
| 271 | + EntityExchangeResult<String> result = client.get() |
| 272 | + .uri("/") |
| 273 | + .exchange() |
| 274 | + .expectStatus().isUnauthorized() |
| 275 | + .expectHeader().value(HttpHeaders.WWW_AUTHENTICATE, value -> assertThat(value).contains("myrealm")) |
| 276 | + .expectBody(String.class) |
| 277 | + .returnResult(); |
| 278 | + |
| 279 | + assertThat(result.getResponseCookies().getFirst("SESSION")).isNull(); |
| 280 | + } |
| 281 | + |
258 | 282 | private <T extends WebFilter> Optional<T> getWebFilter(SecurityWebFilterChain filterChain, Class<T> filterClass) {
|
259 | 283 | return (Optional<T>) filterChain.getWebFilters()
|
260 | 284 | .filter(Objects::nonNull)
|
|
0 commit comments