新增OAuth2认证端与客户端菜单接口
This commit is contained in:
parent
60b0923f1d
commit
e085001fd6
@ -1,10 +1,14 @@
|
|||||||
package ink.wgink.login.oauth2.client.controller.route;
|
package ink.wgink.login.oauth2.client.controller.route;
|
||||||
|
|
||||||
import ink.wgink.common.component.SecurityComponent;
|
import ink.wgink.common.component.SecurityComponent;
|
||||||
|
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||||
import ink.wgink.interfaces.menu.IMenuBaseService;
|
import ink.wgink.interfaces.menu.IMenuBaseService;
|
||||||
import ink.wgink.interfaces.role.IRoleMenuBaseService;
|
import ink.wgink.interfaces.role.IRoleMenuBaseService;
|
||||||
import ink.wgink.pojo.bos.UserInfoBO;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
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.ModelAndView;
|
||||||
import org.springframework.web.servlet.view.RedirectView;
|
import org.springframework.web.servlet.view.RedirectView;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
* 当你想要放弃的时候,想想当初你为何开始
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
@ -28,7 +34,9 @@ public class IndexRouteController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SecurityComponent securityComponent;
|
private SecurityComponent securityComponent;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerProperties serverProperties;
|
private OAuth2ClientServerProperties oAuth2ClientServerProperties;
|
||||||
|
@Autowired
|
||||||
|
private OAuth2ClientProperties oAuth2ClientProperties;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private IMenuBaseService menuBaseService;
|
private IMenuBaseService menuBaseService;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
@ -36,8 +44,8 @@ public class IndexRouteController {
|
|||||||
|
|
||||||
@GetMapping("index")
|
@GetMapping("index")
|
||||||
public ModelAndView goIndex() {
|
public ModelAndView goIndex() {
|
||||||
if (!StringUtils.isBlank(serverProperties.getDefaultIndexPage())) {
|
if (!StringUtils.isBlank(oAuth2ClientServerProperties.getDefaultIndexPage())) {
|
||||||
return new ModelAndView(new RedirectView(serverProperties.getDefaultIndexPage()));
|
return new ModelAndView(new RedirectView(oAuth2ClientServerProperties.getDefaultIndexPage()));
|
||||||
}
|
}
|
||||||
return new ModelAndView("forward:/default-main");
|
return new ModelAndView("forward:/default-main");
|
||||||
}
|
}
|
||||||
@ -52,52 +60,36 @@ public class IndexRouteController {
|
|||||||
ModelAndView mv = new ModelAndView("default-main");
|
ModelAndView mv = new ModelAndView("default-main");
|
||||||
UserInfoBO userInfoBO = securityComponent.getCurrentUser();
|
UserInfoBO userInfoBO = securityComponent.getCurrentUser();
|
||||||
mv.addObject("userUsername", userInfoBO.getUserUsername());
|
mv.addObject("userUsername", userInfoBO.getUserUsername());
|
||||||
// Map<String, Object> config = ConfigManager.getInstance().getConfig();
|
Map<String, Object> config = new HashMap<>();
|
||||||
// // 先加载系统短标题,没有加载主标题,没有加载配置文件系统标题
|
// 先加载系统短标题,没有加载主标题,没有加载配置文件系统标题
|
||||||
// if (!Objects.isNull(config.get(IUserCenterConst.SYSTEM_SHORT_TITLE)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_SHORT_TITLE).toString())) {
|
mv.addObject("systemTitle", oAuth2ClientServerProperties.getSystemTitle());
|
||||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, config.get(IUserCenterConst.SYSTEM_SHORT_TITLE).toString());
|
mv.addObject("ws", oAuth2ClientServerProperties.getWs());
|
||||||
// } else if(!Objects.isNull(config.get(IUserCenterConst.SYSTEM_TITLE)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_TITLE).toString())) {
|
if (menuBaseService != null) {
|
||||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, config.get(IUserCenterConst.SYSTEM_TITLE).toString());
|
List<MenuDTO> menus;
|
||||||
// } else {
|
if (StringUtils.equalsIgnoreCase(ISystemConstant.ADMIN, userInfoBO.getUserUsername())) {
|
||||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_TITLE, serverProperties.getSystemTitle());
|
// 管理员
|
||||||
// }
|
List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||||
// // 系统短LOGO
|
if (menuIds.isEmpty()) {
|
||||||
// if (!Objects.isNull(config.get(IUserCenterConst.SYSTEM_SHORT_LOGO)) && !StringUtils.isBlank(config.get(IUserCenterConst.SYSTEM_SHORT_LOGO).toString())) {
|
menus = menuBaseService.listAllByParentId(IMenuBaseService.MENU_UNIFIED_USER);
|
||||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_LOGO, config.get(IUserCenterConst.SYSTEM_SHORT_LOGO).toString());
|
} else {
|
||||||
// } else {
|
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||||
// mv.addObject(IUserCenterConst.SYSTEM_SHORT_LOGO, "");
|
}
|
||||||
// }
|
} else {
|
||||||
// mv.addObject("ws", serverProperties.getWs());
|
// 普通用户
|
||||||
// // 菜单模式
|
List<RoleSimpleDTO> roleSimpleDTOs = securityComponent.getCurrentUser().getRoles();
|
||||||
// if (!Objects.isNull(config.get(IUserCenterConst.MENU_MODE)) && !StringUtils.isBlank(config.get(IUserCenterConst.MENU_MODE).toString())) {
|
if (roleSimpleDTOs.isEmpty()) {
|
||||||
// mv.addObject(IUserCenterConst.MENU_MODE, config.get(IUserCenterConst.MENU_MODE).toString());
|
menus = new ArrayList<>();
|
||||||
// }
|
} else {
|
||||||
// if (menuBaseService != null) {
|
List<String> roleIds = new ArrayList<>();
|
||||||
// List<MenuDTO> menus;
|
for (RoleSimpleDTO roleSimpleDTO : roleSimpleDTOs) {
|
||||||
// if (StringUtils.equalsIgnoreCase(ISystemConstant.ADMIN, userInfoBO.getUserUsername())) {
|
roleIds.add(roleSimpleDTO.getRoleId());
|
||||||
// // 管理员
|
}
|
||||||
// List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||||
// if (menuIds.isEmpty()) {
|
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||||
// menus = menuBaseService.listAllByParentId(IMenuBaseService.MENU_UNIFIED_USER);
|
}
|
||||||
// } else {
|
}
|
||||||
// menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
mv.addObject("menus", menus);
|
||||||
// }
|
}
|
||||||
// } 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;
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +101,8 @@ public class IndexRouteController {
|
|||||||
@GetMapping("default-home")
|
@GetMapping("default-home")
|
||||||
public ModelAndView defaultHome() {
|
public ModelAndView defaultHome() {
|
||||||
ModelAndView mv;
|
ModelAndView mv;
|
||||||
if (!StringUtils.isBlank(serverProperties.getDefaultHomePage())) {
|
if (!StringUtils.isBlank(oAuth2ClientServerProperties.getDefaultHomePage())) {
|
||||||
mv = new ModelAndView(new RedirectView(serverProperties.getDefaultHomePage()));
|
mv = new ModelAndView(new RedirectView(oAuth2ClientServerProperties.getDefaultHomePage()));
|
||||||
} else {
|
} else {
|
||||||
mv = new ModelAndView("default-home");
|
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