コード例 #1
0
 /**
  * 返回实现IModule接口的列表
  *
  * @param applicationId
  * @return
  */
 @Override
 public List<ModuleBean> getModuleByApplication(String applicationId) {
   Subject subject = shiroService.getSubject();
   List<IModule> moduleList = ModuleManager.getInstall().getModuleList(applicationId);
   List<ModuleBean> moduleBeanList = new ArrayList<ModuleBean>();
   if (moduleList == null) moduleList = new ArrayList<IModule>();
   Mapper mapper = new DozerBeanMapper();
   // 找出所有对应权限的功能模块
   if (moduleList != null && !moduleList.isEmpty()) {
     for (IModule module : moduleList) {
       // 调用isPermitted不能传入空字符,故此默认值为KALIX_NOT_PERMISSION
       String modulePermission =
           StringUtils.isEmpty(module.getPermission())
               ? Const.KALIX_NO_PERMISSION
               : module.getPermission();
       // 具有权限或不进行权限验证,都通过
       if (subject.hasRole(modulePermission)
           || modulePermission.equals(Const.KALIX_NO_PERMISSION)) {
         ModuleBean moduleBean = mapper.map(module, ModuleBean.class);
         moduleBean.setText(module.getText());
         moduleBeanList.add(moduleBean);
       }
     }
   }
   if (moduleBeanList != null && !moduleBeanList.isEmpty()) {
     for (ModuleBean moduleBean : moduleBeanList) {
       moduleBean.setChildren(new ArrayList<MenuBean>());
       List<IMenu> menuList = new ArrayList<IMenu>();
       List<IMenu> allMenu = MenuManager.getInstall().getMenuList(moduleBean.getId());
       // 去掉没有权限的菜单
       if (allMenu != null && !allMenu.isEmpty()) {
         for (IMenu menu : allMenu) {
           // 调用hasRole不能传入空字符,故此默认值为KALIX_NOT_PERMISSION
           String menuPermission =
               StringUtils.isEmpty(menu.getPermission())
                   ? Const.KALIX_NO_PERMISSION
                   : menu.getPermission();
           // 具有权限或不进行权限验证,都通过
           if (subject.hasRole(menuPermission)
               || menuPermission.equals(Const.KALIX_NO_PERMISSION)) {
             menuList.add(menu);
           }
         }
       }
       List<IMenu> rootMenus = getRootMenus(menuList);
       if (rootMenus != null && !rootMenus.isEmpty()) {
         for (IMenu rootMenu : rootMenus) {
           MenuBean menuBean = null;
           if (rootMenu != null) {
             menuBean = mapper.map(rootMenu, MenuBean.class);
             menuBean.setText(rootMenu.getText());
             getMenuChildren(menuBean, menuList, mapper);
           }
           moduleBean.getChildren().add(menuBean);
         }
       }
     }
   }
   return moduleBeanList;
 }
コード例 #2
0
 /**
  * 返回实现IMenu接口的列表
  *
  * @param moduleId
  * @return
  */
 @Override
 public MenuBean getMenuByModule(String moduleId) {
   List<IMenu> menuList = MenuManager.getInstall().getMenuList(moduleId);
   IMenu rootMenu = getRootMenu(menuList);
   /*List<String> mapFile=new ArrayList<>();
   mapFile.add("META-INF/MenuMapper.xml");*/
   Mapper mapper = new DozerBeanMapper();
   MenuBean menuBean = null;
   if (rootMenu != null) {
     menuBean = mapper.map(rootMenu, MenuBean.class);
     menuBean.setText(rootMenu.getText());
     getMenuChildren(menuBean, menuList, mapper);
   }
   return menuBean;
 }