| | |
| | | package com.iailab.module.system.controller.admin.auth; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.LocalDateTimeUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.iailab.framework.common.enums.CommonStatusEnum; |
| | | import com.iailab.framework.common.enums.UserTypeEnum; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.security.config.SecurityProperties; |
| | | import com.iailab.framework.security.core.LoginUser; |
| | | import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
| | | import com.iailab.module.system.controller.admin.app.vo.AppMenuRespVO; |
| | | import com.iailab.module.system.controller.admin.app.vo.AppRespVO; |
| | |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.*; |
| | | import static com.iailab.framework.tenant.core.context.TenantContextHolder.getTenantId; |
| | | |
| | | |
| | |
| | | return success(authService.refreshToken(refreshToken)); |
| | | } |
| | | |
| | | @PostMapping("/client-refresh-token") |
| | | @PermitAll |
| | | @Operation(summary = "刷新令牌") |
| | | @Parameter(name = "refreshToken", description = "刷新令牌", required = true) |
| | | public Map<String, Object> refreshToken(@RequestParam("refreshToken") String refreshToken, @RequestParam("clientId") String clientId) { |
| | | AuthLoginRespVO authLoginRespVO = authService.refreshToken(refreshToken, clientId); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("access_token", authLoginRespVO.getAccessToken()); |
| | | map.put("refresh_token", authLoginRespVO.getRefreshToken()); |
| | | map.put("expires_time", LocalDateTimeUtil.toEpochMilli(authLoginRespVO.getExpiresTime()) / 1000L); |
| | | return map; |
| | | } |
| | | |
| | | @GetMapping("/get-permission-info") |
| | | @Operation(summary = "获取登录用户的权限信息") |
| | | public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() { |
| | |
| | | Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); |
| | | List<MenuDO> menuList = menuService.getMenuList(menuIds); |
| | | menuList = menuService.filterDisableMenus(menuList); |
| | | menuList = menuService.filterMenus(menuList, "system"); |
| | | |
| | | // 2. 拼接结果返回 |
| | | return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); |
| | | } |
| | | |
| | | @GetMapping("/get-app-permission-info") |
| | | @Operation(summary = "脚手架获取登录用户的权限信息") |
| | | public CommonResult<AuthPermissionInfoRespVO> getAppPermissionInfo() { |
| | | // 1.1 获得用户信息 |
| | | AdminUserDO user = userService.getUser(getLoginUserId()); |
| | | if (user == null) { |
| | | return success(null); |
| | | } |
| | | |
| | | // 1.2 获得角色列表 |
| | | Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(getLoginUserId()); |
| | | if (CollUtil.isEmpty(roleIds)) { |
| | | return success(AuthConvert.INSTANCE.convert(user, Collections.emptyList(), Collections.emptyList())); |
| | | } |
| | | List<RoleDO> roles = roleService.getRoleList(roleIds); |
| | | roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色 |
| | | |
| | | // 1.3 获得菜单列表 |
| | | Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); |
| | | List<MenuDO> menuList = menuService.getMenuList(menuIds); |
| | | menuList = menuService.filterDisableMenus(menuList); |
| | | menuList = menuService.filterMenus(menuList, "app"); |
| | | |
| | | // 2. 拼接结果返回 |
| | | return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); |
| | |
| | | List<MenuDO> menuList = menuService.getMenuList(menuIds); |
| | | menuList = menuService.filterDisableMenus(menuList); |
| | | MenuDO menuDO = menuService.getMenuByAppId(id); |
| | | AppDO info = appService.getInfo(id); |
| | | List<MenuDO> children = new LinkedList<>(); |
| | | // 遍历每一层 |
| | | Collection<Long> parentIds = Collections.singleton(menuDO.getId()); |
| | |
| | | } |
| | | children.retainAll(menuList); |
| | | List<MenuDO> tempChildren = new LinkedList<>(); |
| | | //为每一个二级菜单增加一个隐藏父级目录 |
| | | //为每一个二级菜单(非外链菜单)增加一个隐藏父级目录 |
| | | children.stream().forEach(menu -> { |
| | | if (menu.getType().equals(MenuTypeEnum.MENU.getType()) && menu.getParentId().equals(menuDO.getId())) { |
| | | MenuDO parentMenu = BeanUtils.toBean(menu, MenuDO.class); |
| | | parentMenu.setId(System.currentTimeMillis() + (int) (Math.random() * (99999 - 10000 + 1)) + 10000); |
| | | parentMenu.setType(MenuTypeEnum.DIR.getType()); |
| | | parentMenu.setVisible(true); |
| | | parentMenu.setAlwaysShow(false); |
| | | parentMenu.setParentId(menuDO.getId()); |
| | | menu.setParentId(parentMenu.getId()); |
| | | tempChildren.add(parentMenu); |
| | | tempChildren.add(menu); |
| | | } else { |
| | | tempChildren.add(menu); |
| | | if (menu.getParentId().equals(menuDO.getId())) { |
| | | if(menu.getType().equals(MenuTypeEnum.MENU.getType())) { |
| | | MenuDO parentMenu = BeanUtils.toBean(menu, MenuDO.class); |
| | | parentMenu.setId(System.currentTimeMillis() + (int) (Math.random() * (99999 - 10000 + 1)) + 10000); |
| | | parentMenu.setType(MenuTypeEnum.DIR.getType()); |
| | | parentMenu.setVisible(true); |
| | | parentMenu.setAlwaysShow(false); |
| | | parentMenu.setParentId(menuDO.getId()); |
| | | parentMenu.setPath("/"); |
| | | menu.setParentId(parentMenu.getId()); |
| | | tempChildren.add(parentMenu); |
| | | } else if(menu.getType().equals(MenuTypeEnum.DIR.getType())) { |
| | | // 为应用菜单二级目录前增加“/” |
| | | if(!menu.getPath().contains("http:") && !menu.getPath().contains("https:")) { |
| | | menu.setPath("/" + menu.getPath()); |
| | | } |
| | | } |
| | | } |
| | | tempChildren.add(menu); |
| | | }); |
| | | menuVOS = AuthConvert.INSTANCE.buildMenuTree(tempChildren, menuDO.getId(), menuDO.getPath()); |
| | | menuVOS = AuthConvert.INSTANCE.buildMenuTree(tempChildren, menuDO.getId(), menuDO.getPath(), info.getType()); |
| | | // 2. 拼接结果返回 |
| | | return success(menuVOS); |
| | | } |