fix(多租户管理):clientId和clientSecret配置原理梳理,租户数据隔离和数据权限隔离等
This commit is contained in:
-50
@@ -1,50 +0,0 @@
|
|||||||
package com.central.user.config;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
|
||||||
import com.central.common.context.TenantContextHolder;
|
|
||||||
import com.central.common.filter.TenantFilter;
|
|
||||||
import com.central.common.properties.TenantProperties;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
|
||||||
import net.sf.jsqlparser.expression.StringValue;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableConfigurationProperties(TenantProperties.class)
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class TenantConfiguration {
|
|
||||||
private final TenantProperties tenantProperties;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public TenantLineHandler tenantLineHandler() {
|
|
||||||
return new TenantLineHandler() {
|
|
||||||
@Override
|
|
||||||
public String getTenantIdColumn() {
|
|
||||||
return "tenant_id";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ignoreTable(String tableName) {
|
|
||||||
return tenantProperties.getIgnoreTables().stream().anyMatch(
|
|
||||||
(t) -> t.equalsIgnoreCase(tableName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Expression getTenantId() {
|
|
||||||
String tenant = TenantContextHolder.getTenant();
|
|
||||||
if (tenant != null) {
|
|
||||||
return new StringValue(tenant);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public TenantFilter tenantFilter() {
|
|
||||||
return new TenantFilter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
package com.central.user.controller;
|
|
||||||
|
|
||||||
import com.central.common.context.TenantContextHolder;
|
|
||||||
import com.central.common.model.PageResult;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.user.model.SysTenant;
|
|
||||||
import com.central.user.service.ISysTenantService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/tenant")
|
|
||||||
@Tag(name = "租户管理")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class SysTenantController {
|
|
||||||
private final ISysTenantService sysTenantService;
|
|
||||||
|
|
||||||
@Operation(summary = "查询租户列表")
|
|
||||||
@GetMapping("/list")
|
|
||||||
public PageResult<SysTenant> list(@RequestParam Map<String, Object> params) {
|
|
||||||
return sysTenantService.findList(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "查询租户详情")
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public Result<SysTenant> get(@PathVariable String id) {
|
|
||||||
return Result.succeed(sysTenantService.getById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "新增/更新租户")
|
|
||||||
@PostMapping("/save")
|
|
||||||
public Result save(@RequestBody SysTenant tenant) {
|
|
||||||
return sysTenantService.saveOrUpdateTenant(tenant);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "删除租户")
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public Result delete(@PathVariable String id) {
|
|
||||||
return sysTenantService.deleteTenant(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "更新租户状态")
|
|
||||||
@PutMapping("/status/{id}/{status}")
|
|
||||||
public Result updateStatus(@PathVariable String id, @PathVariable Integer status) {
|
|
||||||
return sysTenantService.updateStatus(id, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "查询当前租户")
|
|
||||||
@GetMapping("/current")
|
|
||||||
public Result<String> getCurrentTenant() {
|
|
||||||
return Result.succeed(TenantContextHolder.getTenant());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.central.user.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.central.db.mapper.SuperMapper;
|
|
||||||
import com.central.user.model.SysTenant;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface SysTenantMapper extends SuperMapper<SysTenant> {
|
|
||||||
List<SysTenant> findList(Page<SysTenant> page, @Param("t") Map<String, Object> params);
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package com.central.user.model;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
|
||||||
import com.central.common.model.SuperEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("sys_tenant")
|
|
||||||
public class SysTenant extends SuperEntity {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户编码
|
|
||||||
*/
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户状态:0-禁用,1-正常
|
|
||||||
*/
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户类型
|
|
||||||
*/
|
|
||||||
private Integer type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户域名
|
|
||||||
*/
|
|
||||||
private String domain;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户数据源名称
|
|
||||||
*/
|
|
||||||
private String datasourceConfigId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除
|
|
||||||
*/
|
|
||||||
@TableLogic
|
|
||||||
private Boolean isDeleted;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remarks;
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package com.central.user.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.central.common.model.PageResult;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.user.model.SysTenant;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface ISysTenantService extends IService<SysTenant> {
|
|
||||||
PageResult<SysTenant> findList(Map<String, Object> params);
|
|
||||||
Result saveOrUpdateTenant(SysTenant tenant);
|
|
||||||
Result deleteTenant(String id);
|
|
||||||
Result updateStatus(String id, Integer status);
|
|
||||||
}
|
|
||||||
@@ -45,8 +45,6 @@ zlt:
|
|||||||
- com.central.user.mapper.SysRoleMapper.findAll
|
- com.central.user.mapper.SysRoleMapper.findAll
|
||||||
# 用户列表显示用户所关联的所有角色
|
# 用户列表显示用户所关联的所有角色
|
||||||
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
|
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
|
||||||
# 租户列表
|
|
||||||
- com.central.user.mapper.SysTenantMapper.findList
|
|
||||||
# 数据权限
|
# 数据权限
|
||||||
datascope:
|
datascope:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: user-center
|
name: user-center
|
||||||
cloud:
|
# cloud:
|
||||||
nacos:
|
# nacos:
|
||||||
discovery:
|
# discovery:
|
||||||
ip: 124.222.128.40
|
# ip: 124.222.128.40
|
||||||
# cloud:
|
# cloud:
|
||||||
# nacos:
|
# nacos:
|
||||||
# discovery:
|
# discovery:
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.central.user.mapper.SysTenantMapper">
|
|
||||||
<select id="findList" resultType="com.central.user.model.SysTenant">
|
|
||||||
select * from sys_tenant t
|
|
||||||
<where>
|
|
||||||
<if test="p.name != null and p.name != ''">
|
|
||||||
and t.name like concat('%', #{p.name}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="p.code != null and p.code != ''">
|
|
||||||
and t.code = #{p.code}
|
|
||||||
</if>
|
|
||||||
<if test="p.status != null">
|
|
||||||
and t.status = #{p.status}
|
|
||||||
</if>
|
|
||||||
and t.is_deleted = 0
|
|
||||||
</where>
|
|
||||||
order by t.create_time desc
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
########################## bootstrap级别通用配置 ##########################
|
########################## bootstrap级别通用配置 ##########################
|
||||||
# 默认开发环境
|
# 默认开发环境
|
||||||
spring.profiles.active=prod
|
spring.profiles.active=dev
|
||||||
|
|
||||||
##### nacos(注册中心和配置中心)地址
|
##### nacos(注册中心和配置中心)地址
|
||||||
spring.cloud.nacos.server-addr=81.70.164.178:8848
|
#spring.cloud.nacos.server-addr=81.70.164.178:8848
|
||||||
#spring.cloud.nacos.server-addr=127.0.0.1:8848
|
spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||||
spring.cloud.nacos.username=nacos
|
spring.cloud.nacos.username=nacos
|
||||||
spring.cloud.nacos.password=nacosGFLY
|
spring.cloud.nacos.password=nacos
|
||||||
|
#spring.cloud.nacos.password=nacosGFLY
|
||||||
spring.cloud.nacos.config.file-extension=yml
|
spring.cloud.nacos.config.file-extension=yml
|
||||||
spring.cloud.nacos.config.shared-configs[0].data-id=common.yml
|
spring.cloud.nacos.config.shared-configs[0].data-id=common.yml
|
||||||
spring.cloud.nacos.config.shared-configs[0].refresh=true
|
spring.cloud.nacos.config.shared-configs[0].refresh=true
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: uaa-server
|
name: uaa-server
|
||||||
cloud:
|
# cloud:
|
||||||
nacos:
|
# nacos:
|
||||||
discovery:
|
# discovery:
|
||||||
ip: 124.222.128.40
|
# ip: 124.222.128.40
|
||||||
|
|
||||||
encrypt:
|
encrypt:
|
||||||
key-store:
|
key-store:
|
||||||
|
|||||||
@@ -9,43 +9,43 @@
|
|||||||
export default {
|
export default {
|
||||||
dev: {
|
dev: {
|
||||||
'/api-uaa/': {
|
'/api-uaa/': {
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-user/': {
|
'/api-user/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-log/': {
|
'/api-log/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-search/': {
|
'/api-search/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-generator/': {
|
'/api-generator/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-file/': {
|
'/api-file/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-order/': {
|
'/api-order/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-device/': {
|
'/api-device/': {
|
||||||
// target: 'http://127.0.0.1:9900',
|
target: 'http://127.0.0.1:9900',
|
||||||
target: 'http://119.45.169.13:9900',
|
// target: 'http://119.45.169.13:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export const AUTH_CONFIG = {
|
||||||
|
// basicToken: 'Basic d2ViQXBwOndlYkFwcA==',
|
||||||
|
basicToken: 'Basic Z2ZhcHA6SWtpbmd0ZWNAMjAyMA==', // 备用token
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { request } from 'umi';
|
import { request } from 'umi';
|
||||||
|
import { AUTH_CONFIG } from '@/config/auth';
|
||||||
|
|
||||||
export async function currentUser(options?: { [key: string]: any }) {
|
export async function currentUser(options?: { [key: string]: any }) {
|
||||||
return request<API.OptionalResult<API.CurrentUser>>('/api-user/users/current', {
|
return request<API.OptionalResult<API.CurrentUser>>('/api-user/users/current', {
|
||||||
@@ -38,7 +39,7 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an
|
|||||||
requestType: 'form',
|
requestType: 'form',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
Authorization: 'Basic d2ViQXBwOndlYkFwcA==',
|
Authorization: AUTH_CONFIG.basicToken,
|
||||||
},
|
},
|
||||||
data: { ...body, grant_type: 'password_code' },
|
data: { ...body, grant_type: 'password_code' },
|
||||||
...(options || {}),
|
...(options || {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user