forked from github/dataease
Merge branch 'main' of github.com:dataease/dataease into main
This commit is contained in:
commit
7eb0c473bf
@ -6,7 +6,6 @@ import io.dataease.auth.entity.TokenInfo;
|
||||
import io.dataease.auth.service.AuthUserService;
|
||||
import io.dataease.auth.util.JWTUtils;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.ServletUtils;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
@ -112,7 +111,7 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
|
||||
// JWTUtils.removeTokenExpire(token);
|
||||
String newToken = JWTUtils.sign(tokenInfo, password);
|
||||
// 记录新token操作时间
|
||||
// JWTUtils.addTokenExpire(newToken);
|
||||
JWTUtils.addTokenExpire(newToken);
|
||||
|
||||
JWTToken jwtToken = new JWTToken(newToken);
|
||||
this.getSubject(request, response).login(jwtToken);
|
||||
|
@ -2,8 +2,11 @@ package io.dataease.auth.service.impl;
|
||||
|
||||
import io.dataease.auth.api.dto.CurrentRoleDto;
|
||||
import io.dataease.auth.entity.SysUserEntity;
|
||||
import io.dataease.base.domain.SysUser;
|
||||
import io.dataease.base.mapper.SysUserMapper;
|
||||
import io.dataease.base.mapper.ext.AuthMapper;
|
||||
import io.dataease.auth.service.AuthUserService;
|
||||
import io.dataease.base.mapper.ext.ExtPluginSysMenuMapper;
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.plugins.common.dto.PluginSysMenu;
|
||||
import io.dataease.plugins.util.PluginUtils;
|
||||
@ -13,8 +16,12 @@ import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -23,6 +30,10 @@ public class AuthUserServiceImpl implements AuthUserService {
|
||||
|
||||
@Resource
|
||||
private AuthMapper authMapper;
|
||||
@Resource
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Resource
|
||||
private ExtPluginSysMenuMapper extPluginSysMenuMapper;
|
||||
|
||||
/**
|
||||
* 此处需被F2CRealm登录认证调用 也就是说每次请求都会被调用 所以最好加上缓存
|
||||
@ -53,16 +64,16 @@ public class AuthUserServiceImpl implements AuthUserService {
|
||||
@Cacheable(value = AuthConstants.USER_PERMISSION_CACHE_NAME, key = "'user' + #userId" )
|
||||
@Override
|
||||
public List<String> permissions(Long userId){
|
||||
List<String> permissions = authMapper.permissions(userId);
|
||||
List<PluginSysMenu> pluginSysMenus = PluginUtils.pluginMenus();
|
||||
if (CollectionUtils.isNotEmpty(pluginSysMenus)) {
|
||||
List<Long> menuIds = authMapper.userMenuIds(userId);
|
||||
List<String> pluginPermissions = pluginSysMenus.stream().
|
||||
filter(sysMenu -> menuIds.contains(sysMenu.getMenuId()))
|
||||
.map(menu -> menu.getPermission()).collect(Collectors.toList());
|
||||
permissions.addAll(pluginPermissions);
|
||||
// 用户登录获取菜单权限时同时更新插件菜单表
|
||||
this.syncPluginMenu();
|
||||
List<String> permissions;
|
||||
SysUser sysUser = sysUserMapper.selectByPrimaryKey(userId);
|
||||
if(sysUser.getIsAdmin()!=null&&sysUser.getIsAdmin()){
|
||||
permissions = authMapper.permissionsAll();
|
||||
}else{
|
||||
permissions = authMapper.permissions(userId);
|
||||
}
|
||||
return permissions.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
||||
return Optional.ofNullable(permissions).orElse(new ArrayList<>()).stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,4 +101,13 @@ public class AuthUserServiceImpl implements AuthUserService {
|
||||
public void clearCache(Long userId) {
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void syncPluginMenu() {
|
||||
List<PluginSysMenu> pluginSysMenuList = PluginUtils.pluginMenus();
|
||||
extPluginSysMenuMapper.deletePluginMenu();
|
||||
if(CollectionUtils.isNotEmpty(pluginSysMenuList)){
|
||||
extPluginSysMenuMapper.savePluginMenu(pluginSysMenuList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,24 +84,17 @@ public class JWTUtils {
|
||||
*/
|
||||
public static boolean loginExpire(String token){
|
||||
if (Login_Interval==0) {
|
||||
String property = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout");
|
||||
// 默认超时时间是8h
|
||||
int minute = StringUtils.isNotEmpty(property) ? Integer.parseInt(property): (8*60);
|
||||
int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 8*60);
|
||||
// 分钟换算成毫秒
|
||||
Login_Interval = minute * 1000 * 60;
|
||||
}
|
||||
Long now = System.currentTimeMillis();
|
||||
Long lastOperateTime = tokenLastOperateTime(token);
|
||||
if (ObjectUtils.isEmpty(lastOperateTime)) return true;
|
||||
boolean isExpire = false;
|
||||
if (lastOperateTime != null) {
|
||||
isExpire = now - lastOperateTime > Login_Interval;
|
||||
}
|
||||
if (isExpire) {
|
||||
// System.out.println("-----------------------");
|
||||
// System.out.println("-----上次操作时间是["+lastOperateTime+"]-----");
|
||||
// System.out.println("-----当前操作时间是["+now+"]-----");
|
||||
// System.out.println("-----------------------");
|
||||
}
|
||||
return isExpire;
|
||||
}
|
||||
|
||||
@ -116,7 +109,7 @@ public class JWTUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名,5min后过期
|
||||
* 生成签名,1min后过期
|
||||
* @param tokenInfo 用户信息
|
||||
* @param secret 用户的密码
|
||||
* @return 加密的token
|
||||
@ -165,10 +158,12 @@ public class JWTUtils {
|
||||
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
|
||||
Cache tokens_expire = cacheManager.getCache("tokens_expire");
|
||||
Long expTime = tokens_expire.get(token, Long.class);
|
||||
// System.out.println("get-------"+token+" :"+expTime);
|
||||
return expTime;
|
||||
}
|
||||
|
||||
public static void removeTokenExpire(String token){
|
||||
// System.out.println("remove----"+token);
|
||||
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
|
||||
Cache tokens_expire = cacheManager.getCache("tokens_expire");
|
||||
tokens_expire.evict(token);
|
||||
@ -178,6 +173,7 @@ public class JWTUtils {
|
||||
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
|
||||
Cache tokens_expire = cacheManager.getCache("tokens_expire");
|
||||
long now = System.currentTimeMillis();
|
||||
// System.out.println("add-------"+token+" :"+now);
|
||||
tokens_expire.put(token, now);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ public interface AuthMapper {
|
||||
|
||||
List<String> permissions(@Param("userId") Long userId);
|
||||
|
||||
List<String> permissionsAll();
|
||||
|
||||
List<Long> userMenuIds(@Param("userId") Long userId);
|
||||
|
||||
|
||||
@ -25,4 +27,5 @@ public interface AuthMapper {
|
||||
|
||||
|
||||
List<CurrentRoleDto> roles(@Param("userId") Long userId);
|
||||
|
||||
}
|
||||
|
@ -4,19 +4,19 @@
|
||||
|
||||
<resultMap id="baseMap" type="io.dataease.auth.entity.SysUserEntity">
|
||||
<id column="user_id" property="userId"/>
|
||||
<result column="username" jdbcType="VARCHAR" property="username" />
|
||||
<result column="nick_name" jdbcType="VARCHAR" property="nickName" />
|
||||
<result column="dept_id" property="deptId" />
|
||||
<result column="password" jdbcType="VARCHAR" property="password" />
|
||||
<result column="email" jdbcType="VARCHAR" property="email" />
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
||||
<result column="enabled" property="enabled" />
|
||||
<result column="is_admin" jdbcType="BIT" property="isAdmin" />
|
||||
<result column="username" jdbcType="VARCHAR" property="username"/>
|
||||
<result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
|
||||
<result column="dept_id" property="deptId"/>
|
||||
<result column="password" jdbcType="VARCHAR" property="password"/>
|
||||
<result column="email" jdbcType="VARCHAR" property="email"/>
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone"/>
|
||||
<result column="enabled" property="enabled"/>
|
||||
<result column="is_admin" jdbcType="BIT" property="isAdmin"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="roleMap" type="io.dataease.auth.api.dto.CurrentRoleDto" >
|
||||
<resultMap id="roleMap" type="io.dataease.auth.api.dto.CurrentRoleDto">
|
||||
<id column="role_id" property="id"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
@ -34,12 +34,21 @@
|
||||
where sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="permissions" resultType="String">
|
||||
select sm.permission
|
||||
from sys_menu sm
|
||||
left join sys_roles_menus srm on srm.menu_id = sm.menu_id
|
||||
left join sys_users_roles sur on sur.role_id = srm.role_id
|
||||
where sur.user_id = #{userId}
|
||||
<select id="permissions" resultType="String">
|
||||
SELECT
|
||||
sys_menu.permission
|
||||
FROM
|
||||
( SELECT GET_V_AUTH_MODEL_ID_P_USE ( #{userId}, 'menu' ) cids ) t,
|
||||
sys_menu
|
||||
WHERE
|
||||
FIND_IN_SET( sys_menu.menu_id, cids ) UNION ALL
|
||||
SELECT
|
||||
plugin_sys_menu.permission
|
||||
FROM
|
||||
( SELECT GET_V_AUTH_MODEL_ID_P_USE ( #{userId}, 'menu' ) cids ) t,
|
||||
plugin_sys_menu
|
||||
WHERE
|
||||
FIND_IN_SET( plugin_sys_menu.menu_id, cids )
|
||||
</select>
|
||||
|
||||
<select id="userMenuIds" resultType="Long">
|
||||
@ -57,6 +66,16 @@
|
||||
</select>
|
||||
|
||||
|
||||
<select id="permissionsAll" resultType="String">
|
||||
SELECT
|
||||
sys_menu.permission
|
||||
FROM
|
||||
sys_menu UNION ALL
|
||||
SELECT
|
||||
plugin_sys_menu.permission
|
||||
FROM
|
||||
plugin_sys_menu
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -0,0 +1,15 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.controller.sys.request.SimpleTreeNode;
|
||||
import io.dataease.plugins.common.dto.PluginSysMenu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtPluginSysMenuMapper {
|
||||
|
||||
void savePluginMenu(@Param("menuList") List<PluginSysMenu> menuList);
|
||||
|
||||
void deletePluginMenu();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?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="io.dataease.base.mapper.ext.ExtPluginSysMenuMapper">
|
||||
|
||||
<delete id="deletePluginMenu">
|
||||
delete from plugin_sys_menu
|
||||
</delete>
|
||||
|
||||
<insert id="savePluginMenu">
|
||||
INSERT INTO `plugin_sys_menu` ( menu_id, title, pid, sub_count, permission, hidden ) VALUES
|
||||
<foreach collection="menuList" item="menu" index="index" separator=",">
|
||||
(#{menu.menuId},#{menu.title},#{menu.pid},#{menu.subCount},#{menu.permission},#{menu.hidden})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
||||
</mapper>
|
@ -1,13 +1,13 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.SysAuthDTO;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtSysAuthMapper {
|
||||
List<SysAuthDTO> searchAuth(SysAuthRequest request);
|
||||
List<SysAuthDetailDTO> searchAuth(SysAuthRequest request);
|
||||
|
||||
Boolean authExist(@Param("authSource") String authSource, @Param("authTarget") String authTarget);
|
||||
|
||||
|
@ -2,17 +2,15 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.dataease.base.mapper.ext.ExtSysAuthMapper">
|
||||
|
||||
<resultMap id="BaseResultMapDTO" type="io.dataease.dto.SysAuthDTO"
|
||||
extends="io.dataease.base.mapper.SysAuthMapper.BaseResultMap">
|
||||
<collection property="sysAuthDetails" ofType="io.dataease.base.domain.SysAuthDetail" javaType="list">
|
||||
<result column="auth_id" property="authId"/>
|
||||
<result column="privilege_name" property="privilegeName"/>
|
||||
<result column="privilege_type" property="privilegeType"/>
|
||||
<result column="privilege_value" property="privilegeValue"/>
|
||||
<result column="privilege_extend" property="privilegeExtend"/>
|
||||
</collection>
|
||||
<resultMap id="BaseResultMapAuthDetailDTO" type="io.dataease.dto.SysAuthDetailDTO"
|
||||
extends="io.dataease.base.mapper.SysAuthDetailMapper.BaseResultMap">
|
||||
<result column="auth_source" jdbcType="VARCHAR" property="authSource" />
|
||||
<result column="auth_source_type" jdbcType="VARCHAR" property="authSourceType" />
|
||||
<result column="auth_target" jdbcType="VARCHAR" property="authTarget" />
|
||||
<result column="auth_target_type" jdbcType="VARCHAR" property="authTargetType" />
|
||||
</resultMap>
|
||||
<select id="searchAuth" resultMap="BaseResultMapDTO">
|
||||
|
||||
<select id="searchAuth" resultMap="BaseResultMapAuthDetailDTO">
|
||||
select
|
||||
sys_auth.id,
|
||||
sys_auth.auth_source,
|
||||
|
@ -21,18 +21,21 @@
|
||||
<result column="dept_name" property="deptName" />
|
||||
</association>
|
||||
<association property="dept" column="dept_id" javaType="io.dataease.controller.sys.response.SysUserDept" resultMap="sysUserDept"/>
|
||||
<collection property="roles" ofType="io.dataease.controller.sys.response.SysUserRole" >
|
||||
<id column="role_id" property="roleId" />
|
||||
<result column="role_name" property="roleName"/>
|
||||
|
||||
<collection property="roles"
|
||||
javaType="java.util.ArrayList"
|
||||
ofType="io.dataease.controller.sys.response.SysUserRole"
|
||||
column="user_id"
|
||||
select="queryRole">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
|
||||
|
||||
|
||||
<select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="BaseResultMap">
|
||||
select u.*,u.user_id as id, r.role_id,r.name as role_name , d.pid, d.name as dept_name
|
||||
from sys_user u left join sys_users_roles ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
select u.*,u.user_id as id, d.pid, d.name as dept_name
|
||||
from sys_user u
|
||||
left join sys_dept d on d.dept_id = u.dept_id
|
||||
|
||||
<if test="_parameter != null">
|
||||
@ -45,4 +48,11 @@
|
||||
order by u.update_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="queryRole" resultMap="sysUserRole">
|
||||
select r.role_id, r.name as role_name
|
||||
from sys_users_roles sur
|
||||
left join sys_role r on r.role_id = sur.role_id
|
||||
where sur.user_id = #{user_id}
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -7,4 +7,5 @@ import java.util.List;
|
||||
|
||||
public interface ExtVAuthModelMapper {
|
||||
List<VAuthModelDTO> searchTree(BaseTreeRequest request);
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
<where>
|
||||
model_type = #{modelType}
|
||||
<if test="1== withAuth">
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( cids2 ,#{modelType}))
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( cids2 ,#{modelType}))
|
||||
</if>
|
||||
<if test="pid !=null">
|
||||
and v_auth_model.pid = #{pid}
|
||||
@ -36,7 +36,8 @@
|
||||
</if>
|
||||
|
||||
<if test="name != null and name !='' and withExtend == 'parent'">
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( (select GROUP_CONCAT(id) from v_auth_model where model_type = #{modelType} and `name` like CONCAT('%', #{name},'%')) ,#{modelType}))
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( (select GROUP_CONCAT(id) from
|
||||
v_auth_model where model_type = #{modelType} and `name` like CONCAT('%', #{name},'%')) ,#{modelType}))
|
||||
</if>
|
||||
|
||||
<if test="name != null and name =='' and withExtend == 'parent'">
|
||||
@ -54,7 +55,7 @@
|
||||
<where>
|
||||
model_type = #{modelType}
|
||||
<if test="1== withAuth">
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( cids3 ,#{modelType}))
|
||||
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( cids3 ,#{modelType}))
|
||||
</if>
|
||||
</where>
|
||||
) authTemp
|
||||
@ -69,4 +70,5 @@
|
||||
</where>
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -19,5 +19,10 @@ public class SystemConstants {
|
||||
public final static Integer OFF = 0;
|
||||
}
|
||||
|
||||
public static final class AUTH_SOURCE{
|
||||
public final static String MENU = "menu";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import io.dataease.controller.request.BaseTreeRequest;
|
||||
import io.dataease.controller.request.SysAuthDetailRequest;
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.BaseAuthDetail;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import io.dataease.dto.VAuthModelDTO;
|
||||
import io.dataease.service.sys.SysAuthService;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -44,7 +45,7 @@ public class SysAuthController {
|
||||
|
||||
@ApiOperation("查询授权")
|
||||
@PostMapping("/authDetails")
|
||||
public Map<String,List<SysAuthDetail>> authDetails(@RequestBody SysAuthRequest request){
|
||||
public Map<String,List<SysAuthDetailDTO>> authDetails(@RequestBody SysAuthRequest request){
|
||||
return sysAuthService.searchAuthDetails(request);
|
||||
}
|
||||
|
||||
|
20
backend/src/main/java/io/dataease/dto/SysAuthDetailDTO.java
Normal file
20
backend/src/main/java/io/dataease/dto/SysAuthDetailDTO.java
Normal file
@ -0,0 +1,20 @@
|
||||
package io.dataease.dto;
|
||||
|
||||
import io.dataease.base.domain.SysAuthDetail;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Author: wangjiahao
|
||||
* Date: 2021-06-03
|
||||
* Description:
|
||||
*/
|
||||
@Data
|
||||
public class SysAuthDetailDTO extends SysAuthDetail {
|
||||
private String authSource;
|
||||
|
||||
private String authSourceType;
|
||||
|
||||
private String authTarget;
|
||||
|
||||
private String authTargetType;
|
||||
}
|
@ -132,6 +132,8 @@ public class DataSetTableService {
|
||||
dataSetTableFieldsService.deleteByTableId(id);
|
||||
// 删除同步任务
|
||||
dataSetTableTaskService.deleteByTableId(id);
|
||||
// 删除关联关系
|
||||
dataSetTableUnionService.deleteUnionByTableId(id);
|
||||
try {
|
||||
deleteDorisTable(id, table);
|
||||
} catch (Exception e) {
|
||||
@ -359,7 +361,7 @@ public class DataSetTableService {
|
||||
datasourceRequest.setDatasource(ds);
|
||||
String sql = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getSql();
|
||||
// 使用输入的sql先预执行一次,并拿到所有字段
|
||||
if(StringUtils.isEmpty(sql)){
|
||||
if (StringUtils.isEmpty(sql)) {
|
||||
throw new Exception(Translator.get("i18n_sql_not_empty"));
|
||||
}
|
||||
datasourceRequest.setQuery(sql);
|
||||
|
@ -76,6 +76,14 @@ public class DataSetTableUnionService {
|
||||
return sourceList;
|
||||
}
|
||||
|
||||
public void deleteUnionByTableId(String tableId) {
|
||||
DatasetTableUnionExample datasetTableUnionExample = new DatasetTableUnionExample();
|
||||
DatasetTableUnionExample.Criteria criteriaSource = datasetTableUnionExample.createCriteria().andSourceTableIdEqualTo(tableId);
|
||||
DatasetTableUnionExample.Criteria criteriaTarget = datasetTableUnionExample.createCriteria().andTargetTableIdEqualTo(tableId);
|
||||
datasetTableUnionExample.or(criteriaTarget);
|
||||
datasetTableUnionMapper.deleteByExample(datasetTableUnionExample);
|
||||
}
|
||||
|
||||
private void checkUnion(DatasetTableUnion datasetTableUnion) {
|
||||
// check 关联关系是否存在
|
||||
DatasetTableUnionExample datasetTableUnionExample = new DatasetTableUnionExample();
|
||||
|
@ -12,12 +12,10 @@ import io.dataease.commons.constants.SystemConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.controller.request.BaseTreeRequest;
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.SysAuthDTO;
|
||||
import io.dataease.dto.SysDeptDTO;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import io.dataease.dto.VAuthModelDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -25,6 +23,8 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
@Service
|
||||
public class SysAuthService {
|
||||
|
||||
@ -41,7 +41,7 @@ public class SysAuthService {
|
||||
@Resource
|
||||
private ExtVAuthModelMapper extVAuthModelMapper;
|
||||
|
||||
private static List<String> PRI_MODEL_TYPE = Arrays.asList("link","dataset","chart","panel","menu");
|
||||
private static List<String> PRI_MODEL_TYPE = Arrays.asList("link", "dataset", "chart", "panel", "menu");
|
||||
|
||||
|
||||
/**
|
||||
@ -51,23 +51,22 @@ public class SysAuthService {
|
||||
public List<VAuthModelDTO> searchAuthModelTree(BaseTreeRequest request) {
|
||||
CurrentUserDto currentUserDto = AuthUtils.getUser();
|
||||
request.setCreateBy(String.valueOf(currentUserDto.getUserId()));
|
||||
if(PRI_MODEL_TYPE.contains(request.getModelType())&&(currentUserDto.getIsAdmin() == null || !currentUserDto.getIsAdmin())){
|
||||
if (PRI_MODEL_TYPE.contains(request.getModelType()) && (currentUserDto.getIsAdmin() == null || !currentUserDto.getIsAdmin())) {
|
||||
request.setWithAuth("1");
|
||||
}else{
|
||||
} else {
|
||||
request.setWithAuth("0");
|
||||
}
|
||||
return extVAuthModelMapper.searchTree(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 查询授权明细map
|
||||
**/
|
||||
public Map<String, List<SysAuthDetail>> searchAuthDetails(SysAuthRequest request) {
|
||||
List<SysAuthDTO> authDTOList = extSysAuthMapper.searchAuth(request);
|
||||
return Optional.ofNullable(authDTOList).orElse(new ArrayList<>()).stream()
|
||||
.collect(Collectors.toMap(SysAuthDTO::getAuthSource, SysAuthDTO::getSysAuthDetails));
|
||||
public Map<String, List<SysAuthDetailDTO>> searchAuthDetails(SysAuthRequest request) {
|
||||
List<SysAuthDetailDTO> authDetailDTOList = extSysAuthMapper.searchAuth(request);
|
||||
return Optional.ofNullable(authDetailDTOList).orElse(new ArrayList<>()).stream()
|
||||
.collect(groupingBy(SysAuthDetailDTO::getAuthSource));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,33 +80,33 @@ public class SysAuthService {
|
||||
SysAuthDetail sysAuthDetail = request.getAuthDetail();
|
||||
//TODO 获取需要授权的资源id(当前节点和所有权限的下级节点)
|
||||
List<String> authSources = getAuthModels(request.getAuthSource(), request.getAuthSourceType());
|
||||
if(CollectionUtils.isEmpty(authSources)){
|
||||
if (CollectionUtils.isEmpty(authSources)) {
|
||||
throw new RuntimeException(Translator.get("i18n_auth_source_be_canceled"));
|
||||
}
|
||||
//TODO 获取需要被授权的目标id(部门当前节点和所有权限的下级节点)
|
||||
List<String> authTargets =getAuthModels(request.getAuthTarget(), request.getAuthTargetType());
|
||||
List<String> authTargets = getAuthModels(request.getAuthTarget(), request.getAuthTargetType());
|
||||
|
||||
if(CollectionUtils.isNotEmpty(authSources)&& CollectionUtils.isNotEmpty(authTargets)){
|
||||
if (CollectionUtils.isNotEmpty(authSources) && CollectionUtils.isNotEmpty(authTargets)) {
|
||||
List<String> authIdChange = new ArrayList<>();
|
||||
authTargets.stream().forEach(authTarget -> {
|
||||
authSources.forEach(authSource ->{
|
||||
String authId = checkAuth(authSource, request.getAuthSourceType(),authTarget,request.getAuthTargetType());
|
||||
authSources.forEach(authSource -> {
|
||||
String authId = checkAuth(authSource, request.getAuthSourceType(), authTarget, request.getAuthTargetType());
|
||||
authIdChange.add(authId);
|
||||
});
|
||||
});
|
||||
// 授权修改
|
||||
if(sysAuthDetail.getPrivilegeValue()==SystemConstants.PRIVILEGE_VALUE.ON){
|
||||
if (sysAuthDetail.getPrivilegeValue() == SystemConstants.PRIVILEGE_VALUE.ON) {
|
||||
//当前为开启1 >>> 关闭0 需要将权限级别(PrivilegeType)大于当前级别的全新都修改为关闭 0
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.OFF,sysAuthDetail.getPrivilegeType(),authIdChange);
|
||||
}else{
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.OFF, sysAuthDetail.getPrivilegeType(), authIdChange);
|
||||
} else {
|
||||
//当前为关闭0 >>> 开启1 需要将权限级别(PrivilegeType)小于当前级别的全新都修改为开启 1
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.ON,sysAuthDetail.getPrivilegeType(),authIdChange);
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.ON, sysAuthDetail.getPrivilegeType(), authIdChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getAuthModels(String id, String type) {
|
||||
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id,type, SystemConstants.WITH_EXTEND.CHILDREN));
|
||||
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id, type, SystemConstants.WITH_EXTEND.CHILDREN));
|
||||
List<String> authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream().map(VAuthModelDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
return authSources;
|
||||
@ -116,9 +115,9 @@ public class SysAuthService {
|
||||
/**
|
||||
* @Description: 查询当前target 是否有存在授权 不存在 增加权限 并复制权限模板
|
||||
**/
|
||||
private String checkAuth(String authSource,String authSourceType,String authTarget,String authTargetType){
|
||||
String authId = extSysAuthMapper.findAuthId(authSource,authSourceType,authTarget,authTargetType);
|
||||
if(StringUtils.isEmpty(authId)){
|
||||
private String checkAuth(String authSource, String authSourceType, String authTarget, String authTargetType) {
|
||||
String authId = extSysAuthMapper.findAuthId(authSource, authSourceType, authTarget, authTargetType);
|
||||
if (StringUtils.isEmpty(authId)) {
|
||||
authId = UUID.randomUUID().toString();
|
||||
//TODO 插入权限
|
||||
SysAuth sysAuthRecord = new SysAuth();
|
||||
@ -132,10 +131,11 @@ public class SysAuthService {
|
||||
sysAuthMapper.insertSelective(sysAuthRecord);
|
||||
|
||||
//TODO 复制权限模板
|
||||
extSysAuthDetailMapper.copyAuthModel(authSourceType,authId,AuthUtils.getUser().getUsername());
|
||||
extSysAuthDetailMapper.copyAuthModel(authSourceType, authId, AuthUtils.getUser().getUsername());
|
||||
}
|
||||
|
||||
return authId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -458,3 +458,28 @@ CREATE TABLE `license` (
|
||||
`f2c_license` longtext COMMENT 'F2C License',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `plugin_sys_menu`;
|
||||
CREATE TABLE `plugin_sys_menu` (
|
||||
`menu_id` bigint(8) NOT NULL,
|
||||
`pid` bigint(8) DEFAULT NULL,
|
||||
`sub_count` int(8) DEFAULT NULL,
|
||||
`type` varchar(255) DEFAULT NULL,
|
||||
`title` varchar(255) DEFAULT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`component` varchar(255) DEFAULT NULL,
|
||||
`menu_sort` varchar(255) DEFAULT NULL,
|
||||
`icon` varchar(255) DEFAULT NULL,
|
||||
`path` varchar(255) DEFAULT NULL,
|
||||
`i_frame` tinyint(1) DEFAULT NULL,
|
||||
`cache` tinyint(1) DEFAULT NULL,
|
||||
`hidden` tinyint(1) DEFAULT NULL,
|
||||
`permission` varchar(255) DEFAULT NULL,
|
||||
`create_by` varchar(255) DEFAULT NULL,
|
||||
`update_by` varchar(255) DEFAULT NULL,
|
||||
`create_time` bigint(13) DEFAULT NULL,
|
||||
`update_time` bigint(13) DEFAULT NULL,
|
||||
`no_layout` tinyint(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`menu_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
@ -29,7 +29,7 @@
|
||||
<defaultCache
|
||||
eternal="false"
|
||||
maxElementsInMemory="1000"
|
||||
overflowToDisk="false"
|
||||
overflowToDisk="true"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="600"
|
||||
@ -38,46 +38,46 @@
|
||||
<cache
|
||||
name="users_info"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
maxElementsOnDisk="1000"
|
||||
maxElementsInMemory="1000"
|
||||
maxElementsOnDisk="0"
|
||||
overflowToDisk="true"
|
||||
diskPersistent="true"
|
||||
timeToIdleSeconds="1800"
|
||||
timeToLiveSeconds="3600"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="28800"
|
||||
timeToLiveSeconds="36000"
|
||||
memoryStoreEvictionPolicy="LRU"
|
||||
/>
|
||||
<cache
|
||||
name="users_roles_info"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
maxElementsOnDisk="1000"
|
||||
maxElementsInMemory="1000"
|
||||
maxElementsOnDisk="0"
|
||||
overflowToDisk="true"
|
||||
diskPersistent="true"
|
||||
timeToIdleSeconds="1800"
|
||||
timeToLiveSeconds="3600"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="28800"
|
||||
timeToLiveSeconds="36000"
|
||||
memoryStoreEvictionPolicy="LRU"
|
||||
/>
|
||||
<cache
|
||||
name="users_permissions_info"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
maxElementsOnDisk="1000"
|
||||
maxElementsInMemory="1000"
|
||||
maxElementsOnDisk="0"
|
||||
overflowToDisk="true"
|
||||
diskPersistent="true"
|
||||
timeToIdleSeconds="1800"
|
||||
timeToLiveSeconds="3600"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="28800"
|
||||
timeToLiveSeconds="36000"
|
||||
memoryStoreEvictionPolicy="LRU"
|
||||
/>
|
||||
|
||||
<cache
|
||||
name="tokens_expire"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
maxElementsOnDisk="1000"
|
||||
maxElementsInMemory="1000"
|
||||
maxElementsOnDisk="0"
|
||||
overflowToDisk="true"
|
||||
diskPersistent="true"
|
||||
timeToIdleSeconds="1800"
|
||||
timeToLiveSeconds="3600"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="28800"
|
||||
timeToLiveSeconds="36000"
|
||||
memoryStoreEvictionPolicy="LRU"
|
||||
/>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user