新增OAuth2认证端与客户端菜单接口
This commit is contained in:
parent
60b0923f1d
commit
e085001fd6
@ -1,10 +1,14 @@
|
||||
package ink.wgink.login.oauth2.client.controller.route;
|
||||
|
||||
import ink.wgink.common.component.SecurityComponent;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.menu.IMenuBaseService;
|
||||
import ink.wgink.interfaces.role.IRoleMenuBaseService;
|
||||
import ink.wgink.pojo.bos.UserInfoBO;
|
||||
import ink.wgink.properties.ServerProperties;
|
||||
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||
import ink.wgink.pojo.dtos.role.RoleSimpleDTO;
|
||||
import ink.wgink.properties.oauth2.client.OAuth2ClientProperties;
|
||||
import ink.wgink.properties.oauth2.client.OAuth2ClientServerProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -12,6 +16,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
@ -28,7 +34,9 @@ public class IndexRouteController {
|
||||
@Autowired
|
||||
private SecurityComponent securityComponent;
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
private OAuth2ClientServerProperties oAuth2ClientServerProperties;
|
||||
@Autowired
|
||||
private OAuth2ClientProperties oAuth2ClientProperties;
|
||||
@Autowired(required = false)
|
||||
private IMenuBaseService menuBaseService;
|
||||
@Autowired(required = false)
|
||||
@ -36,8 +44,8 @@ public class IndexRouteController {
|
||||
|
||||
@GetMapping("index")
|
||||
public ModelAndView goIndex() {
|
||||
if (!StringUtils.isBlank(serverProperties.getDefaultIndexPage())) {
|
||||
return new ModelAndView(new RedirectView(serverProperties.getDefaultIndexPage()));
|
||||
if (!StringUtils.isBlank(oAuth2ClientServerProperties.getDefaultIndexPage())) {
|
||||
return new ModelAndView(new RedirectView(oAuth2ClientServerProperties.getDefaultIndexPage()));
|
||||
}
|
||||
return new ModelAndView("forward:/default-main");
|
||||
}
|
||||
@ -52,52 +60,36 @@ public class IndexRouteController {
|
||||
ModelAndView mv = new ModelAndView("default-main");
|
||||
UserInfoBO userInfoBO = securityComponent.getCurrentUser();
|
||||
mv.addObject("userUsername", userInfoBO.getUserUsername());
|
||||
// Map<String, Object> config = ConfigManager.getInstance().getConfig();
|
||||
// // 先加载系统短标题,没有加载主标题,没有加载配置文件系统标题
|
||||
// if (!Objects.isNull(config.get(IUserCenterConst.SYSTEM_SHORT_TITLE)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_SHORT_TITLE).toString())) {
|
||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, config.get(IUserCenterConst.SYSTEM_SHORT_TITLE).toString());
|
||||
// } else if(!Objects.isNull(config.get(IUserCenterConst.SYSTEM_TITLE)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_TITLE).toString())) {
|
||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, config.get(IUserCenterConst.SYSTEM_TITLE).toString());
|
||||
// } else {
|
||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, serverProperties.getSystemTitle());
|
||||
// }
|
||||
// // 系统短LOGO
|
||||
// if (!Objects.isNull(config.get(IUserCenterConst.SYSTEM_SHORT_LOGO)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_SHORT_LOGO).toString())) {
|
||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_LOGO, config.get(IUserCenterConst.SYSTEM_SHORT_LOGO).toString());
|
||||
// } else {
|
||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_LOGO, "");
|
||||
// }
|
||||
// mv.addObject("ws", serverProperties.getWs());
|
||||
// // 菜单模式
|
||||
// if (!Objects.isNull(config.get(IUserCenterConst.MENU_MODE)) && !StringUtils.isBlank(config.get(IUserCenterConst.MENU_MODE).toString())) {
|
||||
// mv.addObject(IUserCenterConst.MENU_MODE, config.get(IUserCenterConst.MENU_MODE).toString());
|
||||
// }
|
||||
// if (menuBaseService != null) {
|
||||
// List<MenuDTO> menus;
|
||||
// if (StringUtils.equalsIgnoreCase(ISystemConstant.ADMIN, userInfoBO.getUserUsername())) {
|
||||
// // 管理员
|
||||
// List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||
// if (menuIds.isEmpty()) {
|
||||
// menus = menuBaseService.listAllByParentId(IMenuBaseService.MENU_UNIFIED_USER);
|
||||
// } else {
|
||||
// menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||
// }
|
||||
// } else {
|
||||
// // 普通用户
|
||||
// List<RoleSimpleDTO> roleSimpleDTOs = securityComponent.getCurrentUser().getRoles();
|
||||
// if (roleSimpleDTOs.isEmpty()) {
|
||||
// menus = new ArrayList<>();
|
||||
// } else {
|
||||
// List<String> roleIds = new ArrayList<>();
|
||||
// for (RoleSimpleDTO roleSimpleDTO : roleSimpleDTOs) {
|
||||
// roleIds.add(roleSimpleDTO.getRoleId());
|
||||
// }
|
||||
// List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||
// menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||
// }
|
||||
// }
|
||||
// mv.addObject("menus", menus);
|
||||
// }
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
// 先加载系统短标题,没有加载主标题,没有加载配置文件系统标题
|
||||
mv.addObject("systemTitle", oAuth2ClientServerProperties.getSystemTitle());
|
||||
mv.addObject("ws", oAuth2ClientServerProperties.getWs());
|
||||
if (menuBaseService != null) {
|
||||
List<MenuDTO> menus;
|
||||
if (StringUtils.equalsIgnoreCase(ISystemConstant.ADMIN, userInfoBO.getUserUsername())) {
|
||||
// 管理员
|
||||
List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||
if (menuIds.isEmpty()) {
|
||||
menus = menuBaseService.listAllByParentId(IMenuBaseService.MENU_UNIFIED_USER);
|
||||
} else {
|
||||
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||
}
|
||||
} else {
|
||||
// 普通用户
|
||||
List<RoleSimpleDTO> roleSimpleDTOs = securityComponent.getCurrentUser().getRoles();
|
||||
if (roleSimpleDTOs.isEmpty()) {
|
||||
menus = new ArrayList<>();
|
||||
} else {
|
||||
List<String> roleIds = new ArrayList<>();
|
||||
for (RoleSimpleDTO roleSimpleDTO : roleSimpleDTOs) {
|
||||
roleIds.add(roleSimpleDTO.getRoleId());
|
||||
}
|
||||
List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||
}
|
||||
}
|
||||
mv.addObject("menus", menus);
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
@ -109,8 +101,8 @@ public class IndexRouteController {
|
||||
@GetMapping("default-home")
|
||||
public ModelAndView defaultHome() {
|
||||
ModelAndView mv;
|
||||
if (!StringUtils.isBlank(serverProperties.getDefaultHomePage())) {
|
||||
mv = new ModelAndView(new RedirectView(serverProperties.getDefaultHomePage()));
|
||||
if (!StringUtils.isBlank(oAuth2ClientServerProperties.getDefaultHomePage())) {
|
||||
mv = new ModelAndView(new RedirectView(oAuth2ClientServerProperties.getDefaultHomePage()));
|
||||
} else {
|
||||
mv = new ModelAndView("default-home");
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package ink.wgink.login.oauth2.client.remote.menu;
|
||||
|
||||
import ink.wgink.annotation.rpc.rest.RemoteService;
|
||||
import ink.wgink.annotation.rpc.rest.method.RemoteGetMethod;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemotePathParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteQueryParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteServerParams;
|
||||
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: IMenuRemoteService
|
||||
* @Description: 菜单调用
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 11:18 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RemoteService
|
||||
public interface IMenuRemoteService {
|
||||
|
||||
/**
|
||||
* 客户端菜单列表
|
||||
*
|
||||
* @param server 服务地址
|
||||
* @param clientId 客户端ID
|
||||
* @param userId 用户ID
|
||||
* @param accessToken token
|
||||
* @return
|
||||
*/
|
||||
@RemoteGetMethod("/resource/oauth2client/list/{clientId}/{userId}")
|
||||
List<MenuDTO> list(@RemoteServerParams String server,
|
||||
@RemotePathParams("clientId") String clientId,
|
||||
@RemotePathParams("userId") String userId,
|
||||
@RemoteQueryParams("access_token") String accessToken);
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package ink.wgink.login.oauth2.client.service.menu;
|
||||
|
||||
/**
|
||||
* @ClassName: IMenuService
|
||||
* @Description: 菜单业务
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 11:16 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IMenuService {
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ink.wgink.login.oauth2.client.service.menu.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.login.oauth2.client.service.menu.IMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ClassName: MenuServiceImpl
|
||||
* @Description: 菜单业务
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 11:16 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class MenuServiceImpl extends DefaultBaseService implements IMenuService {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package ink.wgink.login.oauth2.server.controller.resources;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService;
|
||||
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: OauthClientController
|
||||
* @Description: Oauth客户端
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/12 11:15 AM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "Oauth客户端")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/oauth2client")
|
||||
public class OAuth2ClientResourceController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IOAuth2ClientMenuService oAuth2ClientMenuService;
|
||||
|
||||
|
||||
@ApiOperation(value = "Oauth2客户端菜单列表", notes = "Oauth2客户端菜单列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "clientId", value = "客户端ID", paramType = "path"),
|
||||
@ApiImplicitParam(name = "roleIds", value = "角色ID列表,逗号分割", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("list/{clientId}/{roleIds}")
|
||||
public List<MenuDTO> list(@PathVariable("clientId") String clientId, @PathVariable("roleIds") List<String> roleIds) throws SearchException {
|
||||
return oAuth2ClientMenuService.list(clientId, roleIds);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package ink.wgink.login.oauth2.server.service;
|
||||
|
||||
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: IOAuth2ClientMenuService
|
||||
* @Description: 客户端菜单业务
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 11:33 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IOAuth2ClientMenuService {
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @param clientId 客户端ID
|
||||
* @param roleIds 角色ID列表
|
||||
* @return
|
||||
*/
|
||||
List<MenuDTO> list(String clientId, List<String> roleIds);
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package ink.wgink.login.oauth2.server.service.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.DependencyException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.menu.IMenuBaseService;
|
||||
import ink.wgink.interfaces.role.IRoleMenuBaseService;
|
||||
import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService;
|
||||
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: OAuth2ClientMenuServiceImpl
|
||||
* @Description: OAauth2客户端菜单业务
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 11:33 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements IOAuth2ClientMenuService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private IRoleMenuBaseService roleMenuBaseService;
|
||||
@Autowired(required = false)
|
||||
private IMenuBaseService menuBaseService;
|
||||
|
||||
@Override
|
||||
public List<MenuDTO> list(String clientId, List<String> roleIds) {
|
||||
if (roleMenuBaseService == null) {
|
||||
throw new DependencyException("角色依赖未引入");
|
||||
}
|
||||
if (menuBaseService == null) {
|
||||
throw new DependencyException("菜单依赖为引入");
|
||||
}
|
||||
List<String> menuIds;
|
||||
if (StringUtils.equals(roleIds.get(0), ISystemConstant.ADMIN)) {
|
||||
// 管理员菜单
|
||||
menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||
} else {
|
||||
// 其他角色菜单
|
||||
menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||
}
|
||||
return menuBaseService.listByIds(menuIds);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user