增加单点登录功能

This commit is contained in:
wanggeng 2022-12-25 16:40:30 +08:00
parent 7012678b46
commit ddad5c96fd
3 changed files with 229 additions and 4 deletions

View File

@ -101,7 +101,6 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ink.wgink</groupId>
<artifactId>service-core</artifactId>
@ -133,15 +132,12 @@
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>ink.wgink</groupId>
<artifactId>module-article</artifactId>

View File

@ -0,0 +1,134 @@
package cn.com.tenlion.xzszwhy.base.controller.route.index;
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.login.base.manager.ConfigManager;
import ink.wgink.login.oauth2.server.pojo.dtos.OAuth2ClientSimpleDTO;
import ink.wgink.login.oauth2.server.service.IOAuth2ClientService;
import ink.wgink.pojo.dtos.menu.MenuDTO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName: CustomIndexPageRouteController
* @Description: 自定义index页面
* @Author: wanggeng
* @Date: 2021/11/15 2:37 下午
* @Version: 1.0
*/
@Api(tags = ISystemConstant.ROUTE_TAGS_PREFIX + "自定义index页面路由")
@RestController
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/custom")
public class CustomIndexPageRouteController {
@Autowired
private SecurityComponent securityComponent;
@Autowired
private IMenuBaseService menuBaseService;
@Autowired
private IRoleMenuBaseService roleMenuBaseService;
@Autowired
private IOAuth2ClientService oauth2ClientService;
@GetMapping("index")
public ModelAndView index() {
ModelAndView mv = new ModelAndView("index/index");
List<OAuth2ClientSimpleDTO> oAuth2ClientSimpleDTOs = listOAuth2ClientOfMine();
mv.addObject("listOAuth2Client", oAuth2ClientSimpleDTOs);
mv.addObject("listOAuth2ClientSize", oAuth2ClientSimpleDTOs.size());
mv.addObject("systemTitle", ConfigManager.getInstance().getConfig().get("systemTitle"));
return mv;
}
/**
* 我的客户端列表
*
* @return
*/
private List<OAuth2ClientSimpleDTO> listOAuth2ClientOfMine() {
List<String> roleIds = securityComponent.listRoleIds();
if (securityComponent.isAdmin(roleIds)) {
List<OAuth2ClientSimpleDTO> oAuth2ClientSimpleDTOs = oauth2ClientService.listSimpleByEnvironment(IOAuth2ClientService.OAUTH_CLIENT_ENVIRONMENT_FORMAL);
oAuth2ClientSimpleDTOs.add(0, getUserCenter());
return oAuth2ClientSimpleDTOs;
}
// 自己角色的菜单
List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
if (menuIds.isEmpty()) {
return new ArrayList<>();
}
// 根节点菜单
List<MenuDTO> rootMenuDTOs = menuBaseService.listByParentId("0");
if (rootMenuDTOs.isEmpty()) {
return new ArrayList<>();
}
List<String> rootMenuIds = listRootMenuIdOfMine(rootMenuDTOs, menuIds);
if (rootMenuIds.isEmpty()) {
return new ArrayList<>();
}
List<OAuth2ClientSimpleDTO> oAuth2ClientSimpleDTOs = oauth2ClientService.listSimpleByMenuIdsAndEnvironment(rootMenuIds, IOAuth2ClientService.OAUTH_CLIENT_ENVIRONMENT_FORMAL);
if (hasUserCenter(rootMenuIds)) {
oAuth2ClientSimpleDTOs.add(0, getUserCenter());
}
return oAuth2ClientSimpleDTOs;
}
/**
* 是否有用户中心
*
* @return
*/
private boolean hasUserCenter(List<String> menuIds) {
for (String menuId : menuIds) {
if (StringUtils.equals("unified-user", menuId)) {
return true;
}
}
return false;
}
/**
* 我的根节点菜单
*
* @param rootMenuDTOs
* @param mineMenuIds
* @return
*/
private List<String> listRootMenuIdOfMine(List<MenuDTO> rootMenuDTOs, List<String> mineMenuIds) {
List<String> rootMenuIds = new ArrayList<>();
for (MenuDTO menuDTO : rootMenuDTOs) {
for (String mineMenuId : mineMenuIds) {
if (StringUtils.equals(menuDTO.getMenuId(), mineMenuId)) {
rootMenuIds.add(menuDTO.getMenuId());
break;
}
}
}
return rootMenuIds;
}
/**
* 统一用户
*
* @return
*/
private OAuth2ClientSimpleDTO getUserCenter() {
OAuth2ClientSimpleDTO oAuth2ClientSimpleDTO = new OAuth2ClientSimpleDTO();
oAuth2ClientSimpleDTO.setSystemIcon("");
oAuth2ClientSimpleDTO.setClientName("统一用户管理系统");
oAuth2ClientSimpleDTO.setEnvironment("oauth2 server");
oAuth2ClientSimpleDTO.setWebServerRedirectUri("default-main");
return oAuth2ClientSimpleDTO;
}
}

View File

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<base th:href="${#request.getContextPath() + '/'}">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title th:text="${systemTitle}"></title>
<link rel="stylesheet" href="assets/custom/index/css/swiper.min.css?t=1">
<link rel="stylesheet" href="assets/custom/index/css/style.css?t=1">
</head>
<body>
<div id="app">
<div class="header">
<em v-cloak>{{date}}</em>
<span th:text="${systemTitle}"></span>
<a href="oauth/logout" class="logout">
退出系统
</a>
</div>
<div class="main">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" th:each="oAuth2Client: ${listOAuth2Client}">
<a th:href="${oAuth2Client.webServerRedirectUri}" class="guide-box">
<div class="slide-box">
<img th:if="${oAuth2Client.systemIcon ne ''}" th:src="'route/file/download/false/'+ ${oAuth2Client.systemIcon}" alt="">
<img th:if="${oAuth2Client.systemIcon eq ''}" src="assets/custom/index/images/system.png"/>
<div class="system-name" th:text="${oAuth2Client.clientName}"></div>
<div class="system-name-small" th:text="${oAuth2Client.environment}"></div>
</div>
</a>
</div>
</div>
<div class="swiper-pagination"></div>
</div>
</div>
</div>
<script src="assets/custom/index/js/swiper.min.js?t=1"></script>
<script src="assets/custom/index/js/vue.js?t=1"></script>
<script>
var vue = new Vue({
el: '#app',
data: {
date: ''
},
methods: {
initSwiper: function () {
var swiper = new Swiper('.swiper-container', {
slidesPerView: 5,
spaceBetween: 0,
centeredSlides: true,
loop: false,
autoplay: {
delay: 3000,
disableOnInteraction : false
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
},
initDate: function () {
var date = new Date()
var hour = date.getHours()
var min = date.getMinutes()
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
if (hour < 10) {
hour = '0' + hour
}
if (min < 10) {
min = '0' + min
}
if (month < 10) {
month = '0' + month
}
if (day < 10) {
day = '0' + day
}
this.date = year + '-' + month + '-' + day + ' ' + hour + ':' + min;
}
},
mounted: function () {
var self = this
this.initSwiper()
setInterval(function () {
self.initDate()
}, 1000)
}
})
</script>
</body>
</html>