|
@@ -5,7 +5,6 @@ import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
import com.xy.consts.CommConsts;
|
|
|
import com.xy.entity.SysMenuJoinSysRoleMenu;
|
|
|
-import com.xy.error.CommRuntimeException;
|
|
|
import lombok.Data;
|
|
|
import lombok.experimental.Accessors;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -148,6 +147,7 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 获取所有系统ID
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @return
|
|
|
*/
|
|
|
public static List<Long> getSystemIds(String token) {
|
|
@@ -169,6 +169,7 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 检验系统ID是否属于当前登录人
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
@@ -177,71 +178,72 @@ public class AuthorizeUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检验系统ID是否属于当前登录人并抛出异常
|
|
|
+ * 获取所有角色ID
|
|
|
*
|
|
|
* @param loginId 登录id
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
- public static void checkSystemIdByException(Long loginId, Long systemId) {
|
|
|
- Boolean aBoolean = checkSystemId(loginId, systemId);
|
|
|
- if (!aBoolean) {
|
|
|
- throw new CommRuntimeException("系统不存在");
|
|
|
+ public static List<Long> getRoleIds(Long loginId, Long systemId) {
|
|
|
+ List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
|
|
|
+ if (!Emptys.check(cacheEntities)) {
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
+ List<Long> list = new ArrayList<>(cacheEntities.size());
|
|
|
+ cacheEntities.forEach(cacheEntity -> list.add(cacheEntity.getRoleId()));
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检验系统ID是否属于当前登录人并抛出异常
|
|
|
+ * 获取所有角色ID
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
- public static void checkSystemIdByException(String token, Long systemId) {
|
|
|
- checkSystemIdByException(getLoginId(token, Long.class), systemId);
|
|
|
+ public static List<Long> getRoleIds(String token, Long systemId) {
|
|
|
+ return getRoleIds(getLoginId(token, Long.class), systemId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取所有角色ID
|
|
|
+ * 获取所有角色code
|
|
|
*
|
|
|
* @param loginId 登录id
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<Long> getRoleIds(Long loginId, Long systemId) {
|
|
|
+ public static List<String> getRoleCodes(Long loginId, Long systemId) {
|
|
|
List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
|
|
|
if (!Emptys.check(cacheEntities)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- List<Long> list = new ArrayList<>(cacheEntities.size());
|
|
|
- cacheEntities.forEach(cacheEntity -> list.add(Long.parseLong(cacheEntity.getRoleId().toString())));
|
|
|
+ List<String> list = new ArrayList<>(cacheEntities.size());
|
|
|
+ cacheEntities.forEach(cacheEntity -> list.add(cacheEntity.getRoleCode()));
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取所有角色ID
|
|
|
+ * 获取所有角色code
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<Long> getRoleIds(String token, Long systemId) {
|
|
|
- return getRoleIds(getLoginId(token, Long.class), systemId);
|
|
|
+ public static List<String> getRoleCodes(String token, Long systemId) {
|
|
|
+ return getRoleCodes(getLoginId(token, Long.class), systemId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是管理员
|
|
|
*
|
|
|
- * @param loginId 登录id
|
|
|
+ * @param loginId 登录id
|
|
|
+ * @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
public static Boolean isAdmin(Long loginId, Long systemId) {
|
|
|
- List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
|
|
|
- if (!Emptys.check(cacheEntities)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- for (AuthorizeUtils.CacheEntity cacheEntity : cacheEntities) {
|
|
|
- if (CommConsts.ADMIN_ROLE_CODE.equals(cacheEntity.getRoleCode())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ List<String> roleCodes = getRoleCodes(loginId, systemId);
|
|
|
+ if (roleCodes.contains(CommConsts.ADMIN_ROLE_CODE)) {
|
|
|
+ return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -249,6 +251,8 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 是否是管理员
|
|
|
*
|
|
|
+ * @param token token
|
|
|
+ * @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
|
public static Boolean isAdmin(String token, Long systemId) {
|
|
@@ -283,6 +287,7 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 获取所有菜单接口uri
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
* @return
|
|
|
*/
|
|
@@ -293,6 +298,7 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 登录鉴权
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @return
|
|
|
*/
|
|
|
public static boolean authByLogin(String token) {
|
|
@@ -309,7 +315,9 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 接口鉴权
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
+ * @param uri 接口uri
|
|
|
* @return
|
|
|
*/
|
|
|
public static boolean authByInterface(String token, Long systemId, String uri) {
|
|
@@ -329,7 +337,9 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 数据鉴权
|
|
|
*
|
|
|
+ * @param token token
|
|
|
* @param systemId 系统id
|
|
|
+ * @param uri 接口uri
|
|
|
* @return
|
|
|
*/
|
|
|
public static boolean authByData(String token, Long systemId, String uri) {
|
|
@@ -346,8 +356,8 @@ public class AuthorizeUtils {
|
|
|
/**
|
|
|
* 获取登录id
|
|
|
*
|
|
|
- * @param token
|
|
|
- * @param tClass
|
|
|
+ * @param token token
|
|
|
+ * @param tClass id泛型
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|