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.authorized.AuthorizedDomain;
import com.flyfish.framework.domain.base.IUser; import com.flyfish.framework.domain.base.IUser;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -19,12 +20,15 @@ public class ReactiveAuthorizeAuditor implements ReactiveBeanAuditor<AuthorizedD
*/ */
@Override @Override
public Mono<AuthorizedDomain> audit(AuthorizedDomain data) { public Mono<AuthorizedDomain> audit(AuthorizedDomain data) {
return ReactiveSecurityContextHolder.getContext() if (StringUtils.isBlank(data.getAuthorizeId())) {
.map(ctx -> (IUser) ctx.getAuthentication().getPrincipal()) return ReactiveSecurityContextHolder.getContext()
.map(user -> { .map(ctx -> (IUser) ctx.getAuthentication().getPrincipal())
data.setAuthorizeId(user.getAuthority()); .map(user -> {
return data; data.setAuthorizeId(user.getAuthority());
}) return data;
.defaultIfEmpty(data); })
.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.annotations.Property;
import com.flyfish.framework.domain.base.AuditDomain; import com.flyfish.framework.domain.base.AuditDomain;
import lombok.Getter;
import lombok.Setter; import lombok.Setter;
/** /**
* 带鉴权的实体主要以部门隔绝 * 带鉴权的实体主要以部门隔绝
*/ */
@Setter @Setter
@Getter
public abstract class AuthorizedDomain extends AuditDomain { public abstract class AuthorizedDomain extends AuditDomain {
// 作用域id一般是部门用户存储时插入 // 作用域id一般是部门用户存储时插入