|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -249,29 +249,48 @@ public void testBuilderWithDefaultRolePrefix() {
|
249 | 249 | .implies("B")
|
250 | 250 | .role("B")
|
251 | 251 | .implies("C", "D")
|
| 252 | + .authority("C") |
| 253 | + .implies("E", "F", "B") |
252 | 254 | .build();
|
253 |
| - List<GrantedAuthority> flatAuthorities = AuthorityUtils.createAuthorityList("ROLE_A"); |
254 |
| - List<GrantedAuthority> allAuthorities = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B", "ROLE_C", |
| 255 | + List<GrantedAuthority> flatAuthorities1 = AuthorityUtils.createAuthorityList("ROLE_A"); |
| 256 | + List<GrantedAuthority> allAuthorities1 = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B", "ROLE_C", |
255 | 257 | "ROLE_D");
|
256 | 258 |
|
257 | 259 | assertThat(roleHierarchyImpl).isNotNull();
|
258 |
| - assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)) |
259 |
| - .containsExactlyInAnyOrderElementsOf(allAuthorities); |
| 260 | + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities1)) |
| 261 | + .containsExactlyInAnyOrderElementsOf(allAuthorities1); |
| 262 | + |
| 263 | + List<GrantedAuthority> flatAuthorities2 = AuthorityUtils.createAuthorityList("C"); |
| 264 | + List<GrantedAuthority> allAuthorities2 = AuthorityUtils.createAuthorityList("C", "ROLE_B", "ROLE_C", "ROLE_D", |
| 265 | + "ROLE_E", "ROLE_F"); |
| 266 | + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities2)) |
| 267 | + .containsExactlyInAnyOrderElementsOf(allAuthorities2); |
| 268 | + |
260 | 269 | }
|
261 | 270 |
|
262 | 271 | @Test
|
263 | 272 | public void testBuilderWithRolePrefix() {
|
264 | 273 | RoleHierarchyImpl roleHierarchyImpl = RoleHierarchyImpl.withRolePrefix("CUSTOM_PREFIX_")
|
265 | 274 | .role("A")
|
266 | 275 | .implies("B")
|
| 276 | + .role("B") |
| 277 | + .implies("C", "D") |
| 278 | + .authority("C") |
| 279 | + .implies("E", "F", "B") |
267 | 280 | .build();
|
268 |
| - List<GrantedAuthority> flatAuthorities = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A"); |
269 |
| - List<GrantedAuthority> allAuthorities = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A", |
270 |
| - "CUSTOM_PREFIX_B"); |
| 281 | + List<GrantedAuthority> flatAuthorities1 = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A"); |
| 282 | + List<GrantedAuthority> allAuthorities1 = AuthorityUtils.createAuthorityList("CUSTOM_PREFIX_A", |
| 283 | + "CUSTOM_PREFIX_B", "CUSTOM_PREFIX_C", "CUSTOM_PREFIX_D"); |
271 | 284 |
|
272 | 285 | assertThat(roleHierarchyImpl).isNotNull();
|
273 |
| - assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities)) |
274 |
| - .containsExactlyInAnyOrderElementsOf(allAuthorities); |
| 286 | + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities1)) |
| 287 | + .containsExactlyInAnyOrderElementsOf(allAuthorities1); |
| 288 | + |
| 289 | + List<GrantedAuthority> flatAuthorities2 = AuthorityUtils.createAuthorityList("C"); |
| 290 | + List<GrantedAuthority> allAuthorities2 = AuthorityUtils.createAuthorityList("C", "CUSTOM_PREFIX_B", |
| 291 | + "CUSTOM_PREFIX_C", "CUSTOM_PREFIX_D", "CUSTOM_PREFIX_E", "CUSTOM_PREFIX_F"); |
| 292 | + assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities2)) |
| 293 | + .containsExactlyInAnyOrderElementsOf(allAuthorities2); |
275 | 294 | }
|
276 | 295 |
|
277 | 296 | @Test
|
|
0 commit comments