diff --git a/boot/platform/src/main/java/com/platform/boot/relational/LoggerFilter.java b/boot/platform/src/main/java/com/platform/boot/relational/LoggerFilter.java index 5d01f1d8..07f08c9a 100644 --- a/boot/platform/src/main/java/com/platform/boot/relational/LoggerFilter.java +++ b/boot/platform/src/main/java/com/platform/boot/relational/LoggerFilter.java @@ -160,7 +160,8 @@ private Mono processRequestBody(ServerWebExchange exchange, ServerHttpRe HandlerStrategies.withDefaults().messageReaders()); return serverRequest.bodyToMono(String.class).doOnNext((objectValue) -> { Object previousCachedBody = exchange.getAttributes().put(CACHED_REQUEST_BODY_ATTR, objectValue); - log.debug("{}Logger filter [processRequestBody] body: {}", exchange.getLogPrefix(), previousCachedBody); + log.debug("{}Logger filter chain [processRequestBody] body: {}", + exchange.getLogPrefix(), previousCachedBody); }); } diff --git a/boot/platform/src/main/java/com/platform/boot/security/SecurityManager.java b/boot/platform/src/main/java/com/platform/boot/security/SecurityManager.java index 76275035..56971b1d 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/SecurityManager.java +++ b/boot/platform/src/main/java/com/platform/boot/security/SecurityManager.java @@ -88,24 +88,21 @@ public Mono loadByOauth2(String bindType, String openid) { .bind("bindType", bindType).bind("openid", openid) .map((row, metadata) -> this.r2dbcConverter.read(User.class, row, metadata)) .all(); - return queryWithCache(bindType + openid, userMono).singleOrEmpty(); + return this.queryWithCache(bindType + openid, userMono).singleOrEmpty(); } public Mono loadByUsername(String username) { Query query = Query.query(Criteria.where("username").is(username).ignoreCase(true)); var userMono = this.entityTemplate.select(query, User.class); - return queryWithCache(username, userMono).singleOrEmpty(); + return this.queryWithCache(username, userMono).singleOrEmpty(); } @Override public Mono findByUsername(String username) { - var userMono = this.loadByUsername(username) - .zipWhen(user -> this.authorities(user.getCode())); - + var userMono = this.loadByUsername(username).zipWhen(user -> this.authorities(user.getCode())); var userDetailsMono = userMono .flatMap(tuple2 -> buildUserDetails(tuple2.getT1(), new HashSet<>(tuple2.getT2()))); - return userDetailsMono.cast(UserDetails.class) .onErrorResume(throwable -> Mono.error(new AuthenticationServiceException( throwable.getLocalizedMessage(), throwable))) @@ -117,14 +114,14 @@ public Mono findByUsername(String username) { private Mono buildUserDetails(User user, Set authorities) { SecurityDetails userDetails = SecurityDetails.of(user.getCode(), user.getUsername(), user.getName(), user.getPassword(), user.getDisabled(), user.getAccountExpired(), - user.getAccountLocked(), user.getCredentialsExpired(), authorities, Map.of("username", user.getUsername()), - "username"); - var tuple2Mono = Mono.zip(this.loadGroups(user.getCode()), this.loadTenants(user.getCode())); - return tuple2Mono.flatMap(tuple2 -> { + user.getAccountLocked(), user.getCredentialsExpired(), authorities, + Map.of("username", user.getUsername()), "username"); + var tuple2Mono = Mono.zipDelayError(this.loadGroups(user.getCode()), this.loadTenants(user.getCode())); + return tuple2Mono.mapNotNull(tuple2 -> { userDetails.setGroups(new HashSet<>(tuple2.getT1())); userDetails.setTenants(new HashSet<>(tuple2.getT2())); - return Mono.defer(() -> Mono.just(userDetails)); - }).switchIfEmpty(Mono.defer(() -> Mono.just(userDetails))); + return userDetails; + }).then(Mono.defer(() -> Mono.just(userDetails))); } private Mono> loadGroups(String userCode) { diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/group/GroupsController.java b/boot/platform/src/main/java/com/platform/boot/security/core/group/GroupsController.java index 365be3cf..76c0c927 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/group/GroupsController.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/group/GroupsController.java @@ -33,17 +33,9 @@ public Mono> page(GroupRequest request, Pageable pageable) { this.groupsService.page(request.securityCode(securityDetails.getTenantCode()), pageable)); } - @PostMapping("add") + @PostMapping("save") @PreAuthorize("hasRole(@contextUtils.RULE_ADMINISTRATORS)") public Mono add(@Valid @RequestBody GroupRequest request) { - Assert.isNull(request.getId(), "When adding a new Group, the ID must be null"); - return this.groupsService.operate(request); - } - - @PutMapping("modify") - @PreAuthorize("hasRole(@contextUtils.RULE_ADMINISTRATORS)") - public Mono modify(@Valid @RequestBody GroupRequest request) { - Assert.notNull(request.getId(), "When modifying an existing Group, the ID must not be null"); return this.groupsService.operate(request); } diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/group/authority/GroupAuthorityRequest.java b/boot/platform/src/main/java/com/platform/boot/security/core/group/authority/GroupAuthorityRequest.java index 08960edf..f9fd28ba 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/group/authority/GroupAuthorityRequest.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/group/authority/GroupAuthorityRequest.java @@ -1,7 +1,6 @@ package com.platform.boot.security.core.group.authority; import com.platform.boot.commons.utils.BeanUtils; -import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -18,7 +17,6 @@ @ToString(callSuper = true) public class GroupAuthorityRequest extends GroupAuthority implements Serializable { - @NotNull(message = "权限[authorities]不能为空!") private Set authorities; public GroupAuthority toGroupAuthority() { diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMemberRequest.java b/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMemberRequest.java index c39e17a6..662e6115 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMemberRequest.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMemberRequest.java @@ -10,7 +10,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import java.io.Serializable; import java.util.List; import java.util.Map; import java.util.Set; @@ -22,9 +21,10 @@ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class GroupMemberRequest extends GroupMember implements Serializable { +public class GroupMemberRequest extends GroupMember { private Set users; + private String username; public GroupMember toGroupMember() { diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMembersService.java b/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMembersService.java index 63ecf36c..2a7aa2c5 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMembersService.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/group/member/GroupMembersService.java @@ -70,12 +70,6 @@ public Mono save(GroupMember groupMember) { } } - /** - * Deletes a tenant. - * - * @param request the tenant request - * @return a Mono of void - */ public Mono delete(GroupMemberRequest request) { return this.memberRepository.delete(request.toGroupMember()).doAfterTerminate(() -> this.cache.clear()); } diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantRequest.java b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantRequest.java index ff8807dc..358194a2 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantRequest.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantRequest.java @@ -7,7 +7,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; -import java.io.Serializable; import java.util.List; import java.util.Map; @@ -17,7 +16,7 @@ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TenantRequest extends Tenant implements Serializable { +public class TenantRequest extends Tenant { private Map query; diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsController.java b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsController.java index 35bf95f3..d21bd00b 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsController.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsController.java @@ -33,17 +33,9 @@ public Mono> page(TenantRequest request, Pageable pageable) { return this.tenantsService.page(request, pageable); } - @PostMapping("add") + @PostMapping("save") @PreAuthorize("hasRole(@contextUtils.RULE_ADMINISTRATORS)") - public Mono add(@Valid @RequestBody TenantRequest request) { - Assert.isNull(request.getId(), "When adding a new Tenant, the ID must be null"); - return this.tenantsService.operate(request); - } - - @PutMapping("modify") - @PreAuthorize("hasRole(@contextUtils.RULE_ADMINISTRATORS)") - public Mono modify(@Valid @RequestBody TenantRequest request) { - Assert.notNull(request.getId(), "When modifying an existing Tenant, the ID must not be null"); + public Mono operate(@Valid @RequestBody TenantRequest request) { return this.tenantsService.operate(request); } diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsService.java b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsService.java index b680c642..3e36f0b6 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsService.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/TenantsService.java @@ -22,6 +22,7 @@ public class TenantsService extends AbstractDatabase { private final TenantsRepository tenantsRepository; + private final TenantMembersRepository membersRepository; public Flux search(TenantRequest request, Pageable pageable) { diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMemberRequest.java b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMemberRequest.java index f4447a4f..5a7e1d21 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMemberRequest.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMemberRequest.java @@ -24,7 +24,9 @@ public class TenantMemberRequest extends TenantMember { private Set users; + private String username; + private String securityCode; public TenantMemberRequest securityCode(String securityCode) { diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMembersService.java b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMembersService.java index 3ed4e5b9..0e15d609 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMembersService.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/tenant/member/TenantMembersService.java @@ -57,7 +57,6 @@ public Mono> page(TenantMemberRequest request, Pageab .map(tuple2 -> new PageImpl<>(tuple2.getT1(), pageable, tuple2.getT2())); } - @Transactional(rollbackFor = Exception.class) public Mono operate(TenantMemberRequest request) { var tenantMemberMono = this.entityTemplate.selectOne(Query.query(request.toCriteria()), TenantMember.class) diff --git a/boot/platform/src/main/java/com/platform/boot/security/core/user/authority/UserAuthoritiesService.java b/boot/platform/src/main/java/com/platform/boot/security/core/user/authority/UserAuthoritiesService.java index bbfa72e6..ce1a57b7 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/core/user/authority/UserAuthoritiesService.java +++ b/boot/platform/src/main/java/com/platform/boot/security/core/user/authority/UserAuthoritiesService.java @@ -28,12 +28,13 @@ public Flux search(UserAuthorityRequest request) { public Mono operate(UserAuthorityRequest request) { var dataMono = this.entityTemplate.selectOne(Query.query(request.toCriteria()), UserAuthority.class); - return dataMono.switchIfEmpty(Mono.defer(() -> this.save(request.toAuthority()))) - .doAfterTerminate(() -> this.cache.clear()); + dataMono = dataMono.switchIfEmpty(Mono.defer(() -> this.save(request.toAuthority()))); + return dataMono.doAfterTerminate(() -> this.cache.clear()); } public Mono delete(UserAuthorityRequest request) { - return this.userAuthoritiesRepository.delete(request.toAuthority()).doAfterTerminate(() -> this.cache.clear()); + return this.userAuthoritiesRepository.delete(request.toAuthority()) + .doAfterTerminate(() -> this.cache.clear()); } public Mono save(UserAuthority userAuthority) { diff --git a/boot/platform/src/main/java/com/platform/boot/security/filter/CsrfWebFilter.java b/boot/platform/src/main/java/com/platform/boot/security/filter/CsrfWebFilter.java index 60a7456a..8890bbc0 100644 --- a/boot/platform/src/main/java/com/platform/boot/security/filter/CsrfWebFilter.java +++ b/boot/platform/src/main/java/com/platform/boot/security/filter/CsrfWebFilter.java @@ -20,7 +20,7 @@ public class CsrfWebFilter implements WebFilter, Ordered { @Override public @NonNull Mono filter(ServerWebExchange exchange, @NonNull WebFilterChain chain) { - log.debug("{}Csrf filter chain continue next.", exchange.getLogPrefix()); + log.debug("{}Csrf filter chain [CsrfWebFilter] next.", exchange.getLogPrefix()); Mono csrfTokenMono = exchange.getAttribute(CsrfToken.class.getName()); if (csrfTokenMono != null) { return csrfTokenMono.flatMap(csrfToken -> Mono.defer(() -> chain.filter(exchange))