|
25 | 25 | import reactor.core.publisher.Mono; |
26 | 26 |
|
27 | 27 | import org.springframework.security.authentication.BadCredentialsException; |
28 | | -import org.springframework.security.authentication.NonBuildableAuthenticationToken; |
29 | 28 | import org.springframework.security.authentication.ReactiveAuthenticationManager; |
30 | 29 | import org.springframework.security.authentication.ReactiveAuthenticationManagerResolver; |
31 | | -import org.springframework.security.authentication.SecurityAssertions; |
32 | 30 | import org.springframework.security.authentication.TestingAuthenticationToken; |
33 | 31 | import org.springframework.security.core.Authentication; |
34 | 32 | import org.springframework.security.core.GrantedAuthority; |
@@ -178,31 +176,6 @@ public void filterWhenDefaultsAndAuthenticationFailThenUnauthorized() { |
178 | 176 | assertThat(result.getResponseCookies()).isEmpty(); |
179 | 177 | } |
180 | 178 |
|
181 | | - @Test |
182 | | - public void filterWhenAuthenticatedThenCombinesAuthorities() { |
183 | | - String ROLE_EXISTING = "ROLE_EXISTING"; |
184 | | - TestingAuthenticationToken existingAuthn = new TestingAuthenticationToken("username", "password", |
185 | | - ROLE_EXISTING); |
186 | | - given(this.authenticationManager.authenticate(any())) |
187 | | - .willReturn(Mono.just(new TestingAuthenticationToken("user", "password", "TEST"))); |
188 | | - given(this.securityContextRepository.save(any(), any())).willReturn(Mono.empty()); |
189 | | - this.filter = new AuthenticationWebFilter(this.authenticationManager); |
190 | | - this.filter.setSecurityContextRepository(this.securityContextRepository); |
191 | | - WebTestClient client = WebTestClientBuilder.bindToWebFilters(new RunAsWebFilter(existingAuthn), this.filter) |
192 | | - .build(); |
193 | | - client.get() |
194 | | - .uri("/") |
195 | | - .headers((headers) -> headers.setBasicAuth("test", "this")) |
196 | | - .exchange() |
197 | | - .expectStatus() |
198 | | - .isOk(); |
199 | | - ArgumentCaptor<SecurityContext> context = ArgumentCaptor.forClass(SecurityContext.class); |
200 | | - verify(this.securityContextRepository).save(any(), context.capture()); |
201 | | - Authentication authentication = context.getValue().getAuthentication(); |
202 | | - assertThat(authentication.getAuthorities()).extracting(GrantedAuthority::getAuthority) |
203 | | - .containsExactlyInAnyOrder(ROLE_EXISTING, "TEST"); |
204 | | - } |
205 | | - |
206 | 179 | /** |
207 | 180 | * This is critical to avoid adding duplicate GrantedAuthority instances with the |
208 | 181 | * same' authority when the issuedAt is too old and a new instance is requested. |
@@ -232,31 +205,6 @@ public void filterWhenDefaultEqualsAuthorityThenNoDuplicates() { |
232 | 205 | .containsExactly(DefaultEqualsGrantedAuthority.AUTHORITY); |
233 | 206 | } |
234 | 207 |
|
235 | | - @Test |
236 | | - void doFilterWhenNotOverridingToBuilderThenDoesNotMergeAuthorities() throws Exception { |
237 | | - TestingAuthenticationToken existingAuthn = new TestingAuthenticationToken("username", "password", "FACTORONE"); |
238 | | - given(this.authenticationManager.authenticate(any())) |
239 | | - .willReturn(Mono.just(new NonBuildableAuthenticationToken("user", "password", "FACTORTWO"))); |
240 | | - given(this.securityContextRepository.save(any(), any())).willReturn(Mono.empty()); |
241 | | - this.filter = new AuthenticationWebFilter(this.authenticationManager); |
242 | | - this.filter.setSecurityContextRepository(this.securityContextRepository); |
243 | | - WebTestClient client = WebTestClientBuilder.bindToWebFilters(new RunAsWebFilter(existingAuthn), this.filter) |
244 | | - .build(); |
245 | | - client.get() |
246 | | - .uri("/") |
247 | | - .headers((headers) -> headers.setBasicAuth("test", "this")) |
248 | | - .exchange() |
249 | | - .expectStatus() |
250 | | - .isOk(); |
251 | | - ArgumentCaptor<SecurityContext> context = ArgumentCaptor.forClass(SecurityContext.class); |
252 | | - verify(this.securityContextRepository).save(any(), context.capture()); |
253 | | - Authentication authentication = context.getValue().getAuthentication(); |
254 | | - SecurityAssertions.assertThat(authentication) |
255 | | - .authorities() |
256 | | - .extracting(GrantedAuthority::getAuthority) |
257 | | - .containsExactly("FACTORTWO"); |
258 | | - } |
259 | | - |
260 | 208 | @Test |
261 | 209 | public void filterWhenAuthenticationManagerResolverDefaultsAndAuthenticationFailThenUnauthorized() { |
262 | 210 | given(this.authenticationManager.authenticate(any())) |
|
0 commit comments