feat:租户隔离策略

This commit is contained in:
wangyu 2021-12-08 23:57:16 +08:00
parent a88776119c
commit 042eeae7ea
2 changed files with 13 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package com.flyfish.framework.auditor;
import com.flyfish.framework.domain.authorized.AuthorizedDomain;
import com.flyfish.framework.domain.base.IUser;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
@ -19,6 +20,7 @@ public class ReactiveAuthorizeAuditor implements ReactiveBeanAuditor<AuthorizedD
*/
@Override
public Mono<AuthorizedDomain> audit(AuthorizedDomain data) {
if (StringUtils.isBlank(data.getAuthorizeId())) {
return ReactiveSecurityContextHolder.getContext()
.map(ctx -> (IUser) ctx.getAuthentication().getPrincipal())
.map(user -> {
@ -27,4 +29,6 @@ public class ReactiveAuthorizeAuditor implements ReactiveBeanAuditor<AuthorizedD
})
.defaultIfEmpty(data);
}
return Mono.just(data);
}
}

View File

@ -2,12 +2,14 @@ package com.flyfish.framework.domain.authorized;
import com.flyfish.framework.annotations.Property;
import com.flyfish.framework.domain.base.AuditDomain;
import lombok.Getter;
import lombok.Setter;
/**
* 带鉴权的实体主要以部门隔绝
*/
@Setter
@Getter
public abstract class AuthorizedDomain extends AuditDomain {
// 作用域id一般是部门用户存储时插入