|
@@ -16,7 +16,6 @@ import com.boman.system.api.domain.SysRole;
|
|
import com.boman.system.api.domain.SysUser;
|
|
import com.boman.system.api.domain.SysUser;
|
|
import com.boman.system.api.model.LoginUser;
|
|
import com.boman.system.api.model.LoginUser;
|
|
import com.boman.web.core.domain.FormDataDto;
|
|
import com.boman.web.core.domain.FormDataDto;
|
|
-import com.boman.web.core.service.TableServiceCmdService;
|
|
|
|
import com.boman.web.core.service.common.ICommonService;
|
|
import com.boman.web.core.service.common.ICommonService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -34,19 +33,70 @@ public class AuthUtils {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(AuthUtils.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(AuthUtils.class);
|
|
|
|
|
|
|
|
+ public static boolean checkAuthObjectDelete(GenTable genTable, Long id, String pkName) {
|
|
|
|
+ String tableName = genTable.getTableName();
|
|
|
|
+ String functionName = genTable.getFunctionName();
|
|
|
|
+ LoginUser loginUser = getLoginUser();
|
|
|
|
+ if (SysUser.isAdmin(loginUser.getUserid())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!containsFunctionBool(genTable.getMenuRole(), GenTable.D, functionName)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!checkPermsAuthBool(tableName, GenTable.D)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return checkRoleDataAuthBool(tableName, pkName, id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkQueryListAuth(GenTable genTable, JSONObject condition) {
|
|
|
|
+ containsFunction(genTable.getMenuRole(), GenTable.Q, "此模块:[" + genTable.getTableName() + "], 没有查询功能");
|
|
|
|
+
|
|
|
|
+ LoginUser loginUser = getLoginUser();
|
|
|
|
+ if (SysUser.isAdmin(loginUser.getUserid())) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Long> roleIdList = map(loginUser.getSysUser().getRoles(), SysRole::getId);
|
|
|
|
+ RemoteRoleDataService remoteRoleDataService = SpringUtils.getBean(RemoteRoleDataService.class);
|
|
|
|
+ List<SysRoleData> roleDataList = remoteRoleDataService.listByRoleIdList(roleIdList);
|
|
|
|
+ if (isEmpty(roleDataList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 此张表所对应的roleData
|
|
|
|
+ SysRoleData roleData = filterOne(roleDataList, sysRoleData -> genTable.getTableName().equals(sysRoleData.getTableName()));
|
|
|
|
+ packAuthCondition(roleData.getDataScope(), condition, loginUser);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 功能描述: 某一张表是否有AMD....功能
|
|
* 功能描述: 某一张表是否有AMD....功能
|
|
*
|
|
*
|
|
* @param menuRole AMDQSUE
|
|
* @param menuRole AMDQSUE
|
|
- * @param function AMDQSUE中的其中一个
|
|
|
|
|
|
+ * @param funcType AMDQSUE中的其中一个
|
|
* @param errMsg 错误提示语
|
|
* @param errMsg 错误提示语
|
|
*/
|
|
*/
|
|
- public static void containsFunction(String menuRole, String function, String errMsg) {
|
|
|
|
- if (!menuRole.contains(function)) {
|
|
|
|
|
|
+ public static void containsFunction(String menuRole, String funcType, String errMsg) {
|
|
|
|
+ if (!menuRole.contains(funcType)) {
|
|
throw new UnSuchFunctionException(errMsg);
|
|
throw new UnSuchFunctionException(errMsg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 某一张表是否有AMD....功能
|
|
|
|
+ *
|
|
|
|
+ * @param menuRole AMDQSUE
|
|
|
|
+ * @param funcType AMDQSUE中的其中一个
|
|
|
|
+ */
|
|
|
|
+ public static boolean containsFunctionBool(String menuRole, String funcType, String functionName) {
|
|
|
|
+ if (!menuRole.contains(funcType)) {
|
|
|
|
+ LOGGER.error("非法操作,操作人: {},模块: {}, 此模块无 {} 功能", getLoginUser().getUsername(), functionName, funcType(funcType));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 功能描述: 拿到当前登陆人
|
|
* 功能描述: 拿到当前登陆人
|
|
@@ -99,11 +149,28 @@ public class AuthUtils {
|
|
List<String> permsList = getLoginUserPermsList();
|
|
List<String> permsList = getLoginUserPermsList();
|
|
String perms = packPermsKey(tableName, funcType);
|
|
String perms = packPermsKey(tableName, funcType);
|
|
if (!permsList.contains(perms)) {
|
|
if (!permsList.contains(perms)) {
|
|
- LOGGER.error("姓名: {},非法操作,tableName:{}, 操作类型:{}", getLoginUser().getUsername(), tableName, funcType);
|
|
|
|
|
|
+ LOGGER.error("非法操作,操作人: {},tableName: {}, 操作类型: {}", getLoginUser().getUsername(), tableName, funcType);
|
|
throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: loginUser对应的Perms,权限认定
|
|
|
|
+ *
|
|
|
|
+ * @param tableName tableName
|
|
|
|
+ * @param funcType AMDQSUEI {@link GenTable}
|
|
|
|
+ */
|
|
|
|
+ public static boolean checkPermsAuthBool(String tableName, String funcType) {
|
|
|
|
+ List<String> permsList = getLoginUserPermsList();
|
|
|
|
+ String perms = packPermsKey(tableName, funcType);
|
|
|
|
+ if (!permsList.contains(perms)) {
|
|
|
|
+ LOGGER.error("非法操作,操作人: {},tableName: {}, 操作类型: 此人未配置 {} 权限", getLoginUser().getUsername(), tableName, funcType(GenTable.D));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 功能描述: loginUser对应的roleData,权限认定
|
|
* 功能描述: loginUser对应的roleData,权限认定
|
|
*
|
|
*
|
|
@@ -122,11 +189,37 @@ public class AuthUtils {
|
|
String dataScope = roleDataList.get(0).getDataScope();
|
|
String dataScope = roleDataList.get(0).getDataScope();
|
|
// 不可以修改
|
|
// 不可以修改
|
|
if (!countByCreteBy(dataScope, pkName, id, tableName)) {
|
|
if (!countByCreteBy(dataScope, pkName, id, tableName)) {
|
|
- LOGGER.error("姓名: {},非法操作,tableName:{}", getLoginUser().getUsername(), tableName);
|
|
|
|
|
|
+ LOGGER.error("非法操作,操作人: {},tableName: {}, id: {}", getLoginUser().getUsername(), tableName, id);
|
|
throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: loginUser对应的roleData,权限认定
|
|
|
|
+ *
|
|
|
|
+ * @param tableName tableName
|
|
|
|
+ * @param pkName pkName
|
|
|
|
+ * @param id id
|
|
|
|
+ */
|
|
|
|
+ public static boolean checkRoleDataAuthBool(String tableName, String pkName, Long id) {
|
|
|
|
+ List<Long> roleIdList = getLoginUserRoleIdList();
|
|
|
|
+ RemoteRoleDataService remoteRoleDataService = SpringUtils.getBean(RemoteRoleDataService.class);
|
|
|
|
+ List<SysRoleData> roleDataList = remoteRoleDataService.listByRoleIdListTableName(joinList(roleIdList), tableName);
|
|
|
|
+ if (isEmpty(roleDataList)) {
|
|
|
|
+ //没有配,证明有此表的全部权限
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String dataScope = roleDataList.get(0).getDataScope();
|
|
|
|
+ // 可以修改
|
|
|
|
+ if (countByCreteBy(dataScope, pkName, id, tableName)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LOGGER.error("非法操作,操作人: {},tableName: {}, id: {}", getLoginUser().getUsername(), tableName, id);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 功能描述: 根据crete_by到数据库 count, 如果 >0 可以修改
|
|
* 功能描述: 根据crete_by到数据库 count, 如果 >0 可以修改
|
|
*
|
|
*
|