feat: 适配spring-boot3

This commit is contained in:
zhouhao
2023-12-25 11:51:41 +08:00
parent 92a0cb5f6e
commit 6a00714151
114 changed files with 519 additions and 2638 deletions

View File

@@ -61,113 +61,4 @@ public class AopAuthorizingControllerTest {
.verifyComplete();
}
@Test
public void testFiledDeny() {
SimpleAuthentication authentication = new SimpleAuthentication();
SimpleFieldFilterDataAccessConfig config = new SimpleFieldFilterDataAccessConfig();
config.setAction("query");
config.setFields(new HashSet<>(Arrays.asList("name")));
authentication.setUser(SimpleUser.builder().id("test").username("test").build());
authentication.setPermissions(Arrays.asList(SimplePermission.builder()
.actions(Collections.singleton("query"))
.dataAccesses(Collections.singleton(config))
.id("test").build()));
ReactiveAuthenticationHolder.setSupplier(new ReactiveAuthenticationSupplier() {
@Override
public Mono<Authentication> get(String userId) {
return Mono.empty();
}
@Override
public Mono<Authentication> get() {
return Mono.just(authentication);
}
});
testController.queryUser(new QueryParam())
.map(Param::getExcludes)
.as(StepVerifier::create)
.expectNextMatches(f -> f.contains("name"))
.verifyComplete();
testController.queryUser(Mono.just(new QueryParam()))
.map(Param::getExcludes)
.as(StepVerifier::create)
.expectNextMatches(f -> f.contains("name"))
.verifyComplete();
}
@Test
public void testDimensionDataAccess() {
SimpleAuthentication authentication = new SimpleAuthentication();
DimensionDataAccessConfig config = new DimensionDataAccessConfig();
config.setAction("query");
config.setScopeType("role");
DimensionDataAccessConfig config2 = new DimensionDataAccessConfig();
config2.setAction("save");
config2.setScopeType("role");
ReactiveAuthenticationHolder.setSupplier(new ReactiveAuthenticationSupplier() {
@Override
public Mono<Authentication> get(String userId) {
return Mono.empty();
}
@Override
public Mono<Authentication> get() {
return Mono.just(authentication);
}
});
authentication.setUser(SimpleUser.builder().id("test").username("test").build());
authentication.setPermissions(Arrays.asList(SimplePermission.builder()
.actions(new HashSet<>(Arrays.asList("query", "save")))
.dataAccesses(new HashSet<>(Arrays.asList(config, config2)))
.id("test").build()));
authentication.setDimensions(Collections.singletonList(Dimension.of("test", "test", DefaultDimensionType.role)));
testController.queryUserByDimension(Mono.just(new QueryParam()))
.map(Param::getTerms)
.flatMapIterable(Function.identity())
.next()
.map(Term::getValue)
.map(CastUtil::<Collection<Object>>cast)
.flatMapIterable(Function.identity())
.next()
.as(StepVerifier::create)
.expectNextMatches("test"::equals)
.verifyComplete();
TestEntity testEntity = new TestEntity();
testEntity.setRoleId("123");
testController.save(Mono.just(testEntity))
.as(StepVerifier::create)
.expectError(AccessDenyException.class)
.verify();
testController.add(Mono.just(testEntity))
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
testController.update(testEntity.getId(),Mono.just(testEntity))
.as(StepVerifier::create)
.expectError(AccessDenyException.class)
.verify();
testEntity = new TestEntity();
testEntity.setRoleId("test");
testController.save(Mono.just(testEntity))
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
}
}