MenuController.java:authRoutes 中返回的路由需要检查用户的租户身份
作者: old6ma创建于 2025年5月27日更新于 2025年5月27日
Problem description: The function should return the routes with the permissions owned by the input user, and the way to obtain resources is through the role ID of the input user. However, it should further check whether the user is an admin tenant or an ordinary tenant, and distinguish the tenant identity to return the resources accessible to different tenants. Therefore, it is necessary to check the tenant identity and then return the routes. The function and its calling functions are as follows: MenuController.java:authRoutes: `/**
- Get the role permissions configured
*/
@GetMapping("auth-routes")
@ApiOperationSupport(order = 12)
@Operation(summary = "Role permissions for menus")
public R<List> authRoutes(BladeUser user) {
if (Func.isEmpty(user) || user.getUserId() == 0L) {
return null;
}
return R.data(menuService.authRoutes(user));
}
**MenuServiceImpl.java:authRotes:**@Override public List authRoutes(BladeUser user) { if (Func.isEmpty(user)) { return null; } List routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId())); List list = new ArrayList<>(); routes.forEach(route -> list.add(Kv.init().set(route.getPath(), Kv.init().set("authority", Func.toStrArray(route.getAlias()))))); return list; }The following are the code of two functions in the same file of MenuServiceImpl.java:authRotes:@Override public List grantTree(BladeUser user) { return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId()))); } @Override public List grantDataScopeTree(BladeUser user) { return ForestNodeMerger.merge(user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId()))); }` From these two functions, it can be further determined that the allocation of routes is related to the tenant identity, such as the routes owned by the admin tenant and the ordinary tenant under the unified service should be different.
内容来源: chillzhuang/SpringBlade