|
@@ -25,6 +25,7 @@ import com.gihon.common.properties.GihonCommonProperties;
|
|
|
import com.gihon.common.properties.RedisConstants;
|
|
|
import com.gihon.common.util.JacksonJsonUtils;
|
|
|
import com.gihon.sso.auth.AuthService;
|
|
|
+import com.gihon.sso.entity.vo.MenuVO;
|
|
|
import com.gihon.sso.entity.vo.PermissionVO;
|
|
|
import com.gihon.sso.entity.vo.TokenVal;
|
|
|
import com.gihon.sso.service.GihonButtonService;
|
|
@@ -92,13 +93,13 @@ public class AuthServiceImpl implements AuthService{
|
|
|
// 获取全部的权限列表匹配
|
|
|
// 用权限匹配角色,如果没有角色那么就通过
|
|
|
List<String> needRole = getPermission(uri);
|
|
|
- // Null 是没有配置权限
|
|
|
+ // Null 是没有配置权限只要登录即可
|
|
|
if (needRole == null) {
|
|
|
return true;
|
|
|
- } else if (role == null) {
|
|
|
+ } else if (role == null||role.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
- // Empty是配置权限但是没有角色
|
|
|
+ // Empty是配置权限但是没有角色 只有管理员才行 @See PermissionServiceImpl#cloneCopyMenu
|
|
|
return needRole.stream().anyMatch(r -> role.contains(r));
|
|
|
}
|
|
|
|
|
@@ -155,23 +156,60 @@ public class AuthServiceImpl implements AuthService{
|
|
|
return;
|
|
|
}
|
|
|
List<GihonMenu> menuList = gihonMenuService.getAllMenu(module.getId());
|
|
|
+
|
|
|
+ List<MenuVO> menus = new ArrayList<>();
|
|
|
+
|
|
|
+ MenuVO root = new MenuVO();
|
|
|
+ root.setMenuCode(gihonCommonProperties.getModuleCode());
|
|
|
+ root.setMenuId(-1L);
|
|
|
+
|
|
|
+ menus.add(root);
|
|
|
+
|
|
|
+ MenuVO mp = new MenuVO();
|
|
|
+
|
|
|
+ menuList.forEach(m -> {
|
|
|
+ MenuVO mv = new MenuVO();
|
|
|
+ mv.setMenuCode(m.getMenuCode());
|
|
|
+ mv.setMenuId(m.getId());
|
|
|
+ menus.add(mv);
|
|
|
+// mp.setMenuId(m.getParentId());
|
|
|
+// int index = menus.indexOf(mp);
|
|
|
+// if (index > 0) {
|
|
|
+// menus.get(index).addMenu(mp);
|
|
|
+// }
|
|
|
+ });
|
|
|
+
|
|
|
List<GihonButton> buttonList = gihonButtonService.getMenuButton(menuList.stream().map(m -> m.getId()).collect(Collectors.toList()));
|
|
|
List<PermissionVO> plist = new ArrayList<PermissionVO>();
|
|
|
for (GihonButton btn : buttonList) {
|
|
|
- if (StringUtils.isBlank(btn.getPath())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
List<Long> rbtnList = gihonRoleButtonService.getRoleListByBtn(btn.getId());
|
|
|
PermissionVO pvo = new PermissionVO();
|
|
|
pvo.setUrl(btn.getPath());
|
|
|
pvo.setMethod(btn.getMethod());
|
|
|
- List<GihonRole> rl = gihonRoleService.getRoleListByIds(rbtnList);
|
|
|
- pvo.setRoleList(rl.stream().map(r -> r.getCompanyId()+RedisConstants.SEP+r.getRoleCode()).collect(Collectors.toList()));
|
|
|
+ pvo.setBtnCode(btn.getButtonCode());
|
|
|
+ pvo.setBtnName(btn.getButtonName());
|
|
|
+ if (!rbtnList.isEmpty()) {
|
|
|
+ List<GihonRole> rl = gihonRoleService.getRoleListByIds(rbtnList);
|
|
|
+ pvo.setRoleList(rl.stream().map(r -> r.getCompanyId()+RedisConstants.SEP+r.getRoleCode()).collect(Collectors.toList()));
|
|
|
+ }else {
|
|
|
+ pvo.setRoleList(new ArrayList<>(0));
|
|
|
+ }
|
|
|
+ mp.setMenuId(btn.getMenuId());
|
|
|
+ int index = menus.indexOf(mp);
|
|
|
+ if (index > 0) {
|
|
|
+ menus.get(index).addPermission(pvo);
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(btn.getPath())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
plist.add(pvo);
|
|
|
}
|
|
|
-
|
|
|
+ //用于拦截器的访问权限按钮
|
|
|
stringRedisTemplate.opsForHash().put(RedisConstants.PERMISSN_REDIS,
|
|
|
gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType(), JacksonJsonUtils.writeObject(plist));
|
|
|
+ //用于拦截器的访问权限按钮
|
|
|
+ stringRedisTemplate.opsForHash().put(RedisConstants.MENU_TREE_REDIS,
|
|
|
+ gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType(), JacksonJsonUtils.writeObject(menus));
|
|
|
} catch (Exception e) {
|
|
|
log.error("初始化AuthService失败:", e);
|
|
|
}
|