From e62bc23b371252eefe5a64d0e5459679ec0f194c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Thu, 1 Nov 2018 21:12:30 +0800 Subject: [PATCH] =?UTF-8?q?:bookmark:=20=E5=8F=91=E5=B8=83=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=89=88=E6=9C=AC=E3=80=82=E4=BB=A3=E7=A0=81=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20v1.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthenticationController.java | 2 - .../auth/service/UserDetailServiceImpl.java | 3 + .../bean/resolver/TokenArgumentResolver.java | 2 +- .../pig/common/bean/xss/HtmlFilter.java | 4 +- .../pig/common/entity/SysZuulRoute.java | 8 +- .../java/com/github/pig/common/vo/UserVO.java | 1 - .../pig/config/PigConfigApplication.java | 1 - .../component/filter/PreviewFilter.java | 14 --- .../component/filter/XssSecurityFilter.java | 2 - .../fallback/MenuServiceFallbackImpl.java | 2 - .../service/impl/PermissionServiceImpl.java | 36 +++--- .../pig/gateway/util/UserDetailsImpl.java | 115 ------------------ .../DingTalkServiceChangeReceiveListener.java | 1 - .../common/listener/LogReceiveListener.java | 1 - .../pig/admin/controller/DictController.java | 1 - .../pig/admin/controller/MenuController.java | 23 ++-- .../OauthClientDetailsController.java | 14 +-- .../model/entity/SysOauthClientDetails.java | 4 +- .../pig/admin/service/SysMenuService.java | 1 - .../service/impl/SysMenuServiceImpl.java | 6 +- .../SysOauthClientDetailsServiceImpl.java | 2 +- .../service/impl/SysRoleMenuServiceImpl.java | 1 - .../service/impl/SysUserServiceImpl.java | 60 ++++----- .../service/impl/SysZuulRouteServiceImpl.java | 4 +- .../MonitorDingTalkPropertiesConfig.java | 3 - .../config/MonitorPropertiesConfig.java | 4 - .../monitor/filter/StatusChangeNotifier.java | 1 - .../pig/zipkin/PigZipkinElkApplication.java | 1 - pom.xml | 2 +- 29 files changed, 74 insertions(+), 245 deletions(-) delete mode 100644 pig-gateway/src/main/java/com/github/pig/gateway/util/UserDetailsImpl.java diff --git a/pig-auth/src/main/java/com/github/pig/auth/controller/AuthenticationController.java b/pig-auth/src/main/java/com/github/pig/auth/controller/AuthenticationController.java index 5e2aa8d9..940b7f43 100644 --- a/pig-auth/src/main/java/com/github/pig/auth/controller/AuthenticationController.java +++ b/pig-auth/src/main/java/com/github/pig/auth/controller/AuthenticationController.java @@ -22,10 +22,8 @@ import com.github.pig.common.util.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.annotation.CacheEvict; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.provider.token.ConsumerTokenServices; -import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/pig-auth/src/main/java/com/github/pig/auth/service/UserDetailServiceImpl.java b/pig-auth/src/main/java/com/github/pig/auth/service/UserDetailServiceImpl.java index 3472c336..c5737978 100644 --- a/pig-auth/src/main/java/com/github/pig/auth/service/UserDetailServiceImpl.java +++ b/pig-auth/src/main/java/com/github/pig/auth/service/UserDetailServiceImpl.java @@ -38,6 +38,9 @@ public class UserDetailServiceImpl implements UserDetailsService { @Override public UserDetailsImpl loadUserByUsername(String username) throws UsernameNotFoundException { UserVO userVo = userService.findUserByUsername(username); + if (userVo == null) { + throw new UsernameNotFoundException("用户名不存在或者密码错误"); + } return new UserDetailsImpl(userVo); } } diff --git a/pig-common/src/main/java/com/github/pig/common/bean/resolver/TokenArgumentResolver.java b/pig-common/src/main/java/com/github/pig/common/bean/resolver/TokenArgumentResolver.java index 37b7d637..ada8a4c8 100644 --- a/pig-common/src/main/java/com/github/pig/common/bean/resolver/TokenArgumentResolver.java +++ b/pig-common/src/main/java/com/github/pig/common/bean/resolver/TokenArgumentResolver.java @@ -81,7 +81,7 @@ public class TokenArgumentResolver implements HandlerMethodArgumentResolver { List sysRoleList = new ArrayList<>(); Arrays.stream(roles.split(",")).forEach(role -> { SysRole sysRole = new SysRole(); - sysRole.setRoleName(role); + sysRole.setRoleCode(role); sysRoleList.add(sysRole); }); userVO.setRoleList(sysRoleList); diff --git a/pig-common/src/main/java/com/github/pig/common/bean/xss/HtmlFilter.java b/pig-common/src/main/java/com/github/pig/common/bean/xss/HtmlFilter.java index 5b37b90b..e2a1f851 100644 --- a/pig-common/src/main/java/com/github/pig/common/bean/xss/HtmlFilter.java +++ b/pig-common/src/main/java/com/github/pig/common/bean/xss/HtmlFilter.java @@ -17,14 +17,14 @@ package com.github.pig.common.bean.xss; +import java.text.Normalizer; +import java.text.Normalizer.Form; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.text.Normalizer; -import java.text.Normalizer.Form; /** * HTML filtering utility for protecting against XSS (Cross Site Scripting). diff --git a/pig-common/src/main/java/com/github/pig/common/entity/SysZuulRoute.java b/pig-common/src/main/java/com/github/pig/common/entity/SysZuulRoute.java index 85816ff0..21bc991f 100644 --- a/pig-common/src/main/java/com/github/pig/common/entity/SysZuulRoute.java +++ b/pig-common/src/main/java/com/github/pig/common/entity/SysZuulRoute.java @@ -17,15 +17,15 @@ package com.github.pig.common.entity; -import com.baomidou.mybatisplus.enums.IdType; -import java.util.Date; -import com.baomidou.mybatisplus.annotations.TableId; -import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; import java.io.Serializable; +import java.util.Date; /** *

diff --git a/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java b/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java index 924f3d34..c90b9aa6 100644 --- a/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java +++ b/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java @@ -20,7 +20,6 @@ package com.github.pig.common.vo; import lombok.Data; import java.io.Serializable; -import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/pig-config/src/main/java/com/github/pig/config/PigConfigApplication.java b/pig-config/src/main/java/com/github/pig/config/PigConfigApplication.java index b1ef2aba..7640676c 100644 --- a/pig-config/src/main/java/com/github/pig/config/PigConfigApplication.java +++ b/pig-config/src/main/java/com/github/pig/config/PigConfigApplication.java @@ -19,7 +19,6 @@ package com.github.pig.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.config.server.EnableConfigServer; diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java index 284a8fe7..f9b085cf 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java @@ -18,33 +18,19 @@ package com.github.pig.gateway.component.filter; import com.alibaba.fastjson.JSONObject; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.pig.common.constant.CommonConstant; -import com.github.pig.common.constant.SecurityConstants; import com.github.pig.common.util.R; -import com.github.pig.common.util.exception.CheckedException; import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.context.RequestContext; -import com.xiaoleilu.hutool.collection.CollectionUtil; -import com.xiaoleilu.hutool.io.IoUtil; import com.xiaoleilu.hutool.util.StrUtil; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; -import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER; - /** * @author lengleng * @date 2018年05月10日 diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/XssSecurityFilter.java b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/XssSecurityFilter.java index cedfcecf..ca63a8b0 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/XssSecurityFilter.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/XssSecurityFilter.java @@ -18,9 +18,7 @@ package com.github.pig.gateway.component.filter; import com.github.pig.common.bean.xss.XssHttpServletRequestWrapper; -import com.netflix.zuul.ZuulFilter; import lombok.extern.slf4j.Slf4j; -import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/feign/fallback/MenuServiceFallbackImpl.java b/pig-gateway/src/main/java/com/github/pig/gateway/feign/fallback/MenuServiceFallbackImpl.java index fd5bea84..12d9f6bb 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/feign/fallback/MenuServiceFallbackImpl.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/feign/fallback/MenuServiceFallbackImpl.java @@ -21,8 +21,6 @@ import com.github.pig.common.vo.MenuVO; import com.github.pig.gateway.feign.MenuService; import com.xiaoleilu.hutool.collection.CollUtil; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.Set; diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java index 4f77e043..1da77290 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java @@ -17,12 +17,10 @@ package com.github.pig.gateway.service.impl; -import com.baomidou.mybatisplus.toolkit.StringUtils; import com.github.pig.common.vo.MenuVO; import com.github.pig.gateway.feign.MenuService; import com.github.pig.gateway.service.PermissionService; import com.xiaoleilu.hutool.collection.CollUtil; -import com.xiaoleilu.hutool.collection.CollectionUtil; import com.xiaoleilu.hutool.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +33,7 @@ import javax.servlet.http.HttpServletRequest; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; /** * @author lengleng @@ -55,33 +54,28 @@ public class PermissionServiceImpl implements PermissionService { // return true; // } Object principal = authentication.getPrincipal(); - List grantedAuthorityList = (List) authentication.getAuthorities(); - boolean hasPermission = false; + List authorityList = (List) authentication.getAuthorities(); + AtomicBoolean hasPermission = new AtomicBoolean(false); if (principal != null) { - if (CollectionUtil.isEmpty(grantedAuthorityList)) { + if (CollUtil.isEmpty(authorityList)) { log.warn("角色列表为空:{}", authentication.getPrincipal()); - return hasPermission; + return false; } Set urls = new HashSet<>(); - for (SimpleGrantedAuthority authority : grantedAuthorityList) { - if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) { - Set menuVOSet = menuService.findMenuByRole(authority.getAuthority()); - if (CollUtil.isNotEmpty(menuVOSet)) { + authorityList.stream().filter(authority -> + !StrUtil.equals(authority.getAuthority(), "ROLE_USER")) + .forEach(authority -> { + Set menuVOSet = menuService.findMenuByRole(authority.getAuthority()); CollUtil.addAll(urls, menuVOSet); - } - } - } + }); - for (MenuVO menu : urls) { - if (StringUtils.isNotEmpty(menu.getUrl()) && antPathMatcher.match(menu.getUrl(), request.getRequestURI()) - && request.getMethod().equalsIgnoreCase(menu.getMethod())) { - hasPermission = true; - break; - } - } + urls.stream().filter(menu -> StrUtil.isNotEmpty(menu.getUrl()) + && antPathMatcher.match(menu.getUrl(), request.getRequestURI()) + && request.getMethod().equalsIgnoreCase(menu.getMethod())) + .findFirst().ifPresent(menuVO -> hasPermission.set(true)); } - return hasPermission; + return hasPermission.get(); } } diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/util/UserDetailsImpl.java b/pig-gateway/src/main/java/com/github/pig/gateway/util/UserDetailsImpl.java deleted file mode 100644 index 9147aa9e..00000000 --- a/pig-gateway/src/main/java/com/github/pig/gateway/util/UserDetailsImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - -package com.github.pig.gateway.util; - -import com.github.pig.common.constant.CommonConstant; -import com.github.pig.common.constant.SecurityConstants; -import com.github.pig.common.vo.SysRole; -import com.github.pig.common.vo.UserVO; -import org.apache.commons.lang.StringUtils; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author lengleng - * @date 2017/10/29 - */ -public class UserDetailsImpl implements UserDetails { - private static final long serialVersionUID = 1L; - - private String username; - private String password; - private String status; - private List roleList = new ArrayList<>(); - - public UserDetailsImpl(UserVO userVo) { - this.username = userVo.getUsername(); - this.password = userVo.getPassword(); - this.status = userVo.getDelFlag(); - roleList = userVo.getRoleList(); - } - - @Override - public Collection getAuthorities() { - List authorityList = new ArrayList<>(); - for (SysRole role : roleList) { - authorityList.add(new SimpleGrantedAuthority(role.getRoleCode())); - } - authorityList.add(new SimpleGrantedAuthority(SecurityConstants.BASE_ROLE)); - return authorityList; - } - - @Override - public String getPassword() { - return this.password; - } - - @Override - public String getUsername() { - return this.username; - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return StringUtils.equals(CommonConstant.STATUS_LOCK, status) ? false : true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return StringUtils.equals(CommonConstant.STATUS_NORMAL, status) ? true : false; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setPassword(String password) { - this.password = password; - } - - public List getRoleList() { - return roleList; - } - - public void setRoleList(List roleList) { - this.roleList = roleList; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } -} diff --git a/pig-modules/pig-mc-service/src/main/java/com/github/pig/mc/listener/DingTalkServiceChangeReceiveListener.java b/pig-modules/pig-mc-service/src/main/java/com/github/pig/mc/listener/DingTalkServiceChangeReceiveListener.java index fcb04f29..da57891e 100644 --- a/pig-modules/pig-mc-service/src/main/java/com/github/pig/mc/listener/DingTalkServiceChangeReceiveListener.java +++ b/pig-modules/pig-mc-service/src/main/java/com/github/pig/mc/listener/DingTalkServiceChangeReceiveListener.java @@ -18,7 +18,6 @@ package com.github.pig.mc.listener; import com.github.pig.common.constant.MqQueueConstant; -import com.github.pig.common.util.template.DingTalkMsgTemplate; import com.github.pig.mc.handler.DingTalkMessageHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitHandler; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/common/listener/LogReceiveListener.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/common/listener/LogReceiveListener.java index 33c39888..4e0a3d53 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/common/listener/LogReceiveListener.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/common/listener/LogReceiveListener.java @@ -20,7 +20,6 @@ package com.github.pig.admin.common.listener; import com.github.pig.admin.service.SysLogService; import com.github.pig.common.constant.MqQueueConstant; import com.github.pig.common.entity.SysLog; -import com.github.pig.common.util.UserUtils; import com.github.pig.common.vo.LogVO; import org.slf4j.MDC; import org.springframework.amqp.rabbit.annotation.RabbitHandler; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java index 41d247ab..64bdda61 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java @@ -20,7 +20,6 @@ package com.github.pig.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.github.pig.admin.model.dto.RoleDTO; import com.github.pig.admin.model.entity.SysDict; import com.github.pig.admin.service.SysDictService; import com.github.pig.common.constant.CommonConstant; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java index aa2d7e93..3c515638 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java @@ -25,12 +25,13 @@ import com.github.pig.admin.service.SysMenuService; import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.util.R; import com.github.pig.common.vo.MenuVO; +import com.github.pig.common.vo.UserVO; import com.github.pig.common.web.BaseController; -import com.xiaoleilu.hutool.collection.CollUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; +import java.util.stream.Collectors; /** * @author lengleng @@ -56,20 +57,20 @@ public class MenuController extends BaseController { /** * 返回当前用户的树形菜单集合 * + * @param userVO * @return 当前用户的树形菜单 */ @GetMapping(value = "/userMenu") - public List userMenu() { + public List userMenu(UserVO userVO) { // 获取符合条件得菜单 Set all = new HashSet<>(); - getRole().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleName(roleName))); - List menuTreeList = new ArrayList<>(); - all.forEach(menuVo -> { - if (CommonConstant.MENU.equals(menuVo.getType())) { - menuTreeList.add(new MenuTree(menuVo)); - } - }); - CollUtil.sort(menuTreeList, Comparator.comparingInt(MenuTree::getSort)); + userVO.getRoleList().forEach(role -> all.addAll(sysMenuService.findMenuByRoleName(role.getRoleCode()))); + + List menuTreeList = all.stream().filter(vo -> CommonConstant.MENU + .equals(vo.getType())) + .map(MenuTree::new) + .sorted(Comparator.comparingInt(MenuTree::getSort)) + .collect(Collectors.toList()); return TreeUtil.bulid(menuTreeList, -1); } @@ -84,7 +85,7 @@ public class MenuController extends BaseController { condition.setDelFlag(CommonConstant.STATUS_NORMAL); return TreeUtil.bulidTree(sysMenuService.selectList(new EntityWrapper<>(condition)), -1); } - + /** * 返回角色的菜单集合 * diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/OauthClientDetailsController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/OauthClientDetailsController.java index e254b28a..d0696349 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/OauthClientDetailsController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/OauthClientDetailsController.java @@ -17,17 +17,17 @@ package com.github.pig.admin.controller; -import java.util.Map; - -import com.github.pig.admin.model.entity.SysOauthClientDetails; -import com.github.pig.common.util.R; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.github.pig.common.util.Query; +import com.github.pig.admin.model.entity.SysOauthClientDetails; import com.github.pig.admin.service.SysOauthClientDetailsService; +import com.github.pig.common.util.Query; +import com.github.pig.common.util.R; import com.github.pig.common.web.BaseController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; /** *

diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysOauthClientDetails.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysOauthClientDetails.java index f1923cbe..0722a043 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysOauthClientDetails.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysOauthClientDetails.java @@ -17,9 +17,9 @@ package com.github.pig.admin.model.entity; -import com.baomidou.mybatisplus.annotations.TableId; -import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java index b26e647b..2fd16d64 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java @@ -19,7 +19,6 @@ package com.github.pig.admin.service; import com.baomidou.mybatisplus.service.IService; -import com.github.pig.admin.model.dto.MenuTree; import com.github.pig.admin.model.entity.SysMenu; import com.github.pig.common.vo.MenuVO; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java index 0e583251..03e6ec7f 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java @@ -19,22 +19,18 @@ package com.github.pig.admin.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.github.pig.admin.common.util.TreeUtil; import com.github.pig.admin.mapper.SysMenuMapper; -import com.github.pig.admin.model.dto.MenuTree; import com.github.pig.admin.model.entity.SysMenu; import com.github.pig.admin.service.SysMenuService; import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.util.Assert; import com.github.pig.common.vo.MenuVO; -import com.xiaoleilu.hutool.collection.CollUtil; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.List; /** *

diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysOauthClientDetailsServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysOauthClientDetailsServiceImpl.java index 1679c8ff..3b2aa7ab 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysOauthClientDetailsServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysOauthClientDetailsServiceImpl.java @@ -17,8 +17,8 @@ package com.github.pig.admin.service.impl; -import com.github.pig.admin.mapper.SysOauthClientDetailsMapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.github.pig.admin.mapper.SysOauthClientDetailsMapper; import com.github.pig.admin.model.entity.SysOauthClientDetails; import com.github.pig.admin.service.SysOauthClientDetailsService; import org.springframework.stereotype.Service; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java index 739797fa..cc17786d 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysRoleMenuServiceImpl.java @@ -22,7 +22,6 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.github.pig.admin.mapper.SysRoleMenuMapper; import com.github.pig.admin.model.entity.SysRoleMenu; import com.github.pig.admin.service.SysRoleMenuService; -import com.xiaoleilu.hutool.collection.CollUtil; import com.xiaoleilu.hutool.util.StrUtil; import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java index 032efab7..8f0c9825 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java @@ -19,7 +19,6 @@ package com.github.pig.admin.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.github.pig.admin.mapper.SysUserMapper; @@ -39,19 +38,19 @@ import com.github.pig.common.constant.SecurityConstants; import com.github.pig.common.constant.enums.EnumSmsChannelTemplate; import com.github.pig.common.util.Query; import com.github.pig.common.util.R; -import com.github.pig.common.util.UserUtils; import com.github.pig.common.util.template.MobileMsgTemplate; import com.github.pig.common.vo.MenuVO; import com.github.pig.common.vo.SysRole; import com.github.pig.common.vo.UserVO; import com.xiaoleilu.hutool.collection.CollectionUtil; +import com.xiaoleilu.hutool.util.ArrayUtil; import com.xiaoleilu.hutool.util.RandomUtil; import com.xiaoleilu.hutool.util.StrUtil; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.redis.core.RedisTemplate; @@ -61,6 +60,7 @@ import org.springframework.stereotype.Service; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * @author lengleng @@ -68,20 +68,15 @@ import java.util.concurrent.TimeUnit; */ @Slf4j @Service +@AllArgsConstructor public class SysUserServiceImpl extends ServiceImpl implements SysUserService { private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); - @Autowired - private SysMenuService sysMenuService; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private SysUserMapper sysUserMapper; - @Autowired - private RabbitTemplate rabbitTemplate; - @Autowired - private SysUserRoleService sysUserRoleService; - @Autowired - private SysDeptRelationService sysDeptRelationService; + private final SysMenuService sysMenuService; + private final RedisTemplate redisTemplate; + private final SysUserMapper sysUserMapper; + private final RabbitTemplate rabbitTemplate; + private final SysUserRoleService sysUserRoleService; + private final SysDeptRelationService sysDeptRelationService; @Override public UserInfo findUserInfo(UserVO userVo) { @@ -92,32 +87,23 @@ public class SysUserServiceImpl extends ServiceImpl impl UserInfo userInfo = new UserInfo(); userInfo.setSysUser(sysUser); //设置角色列表 - List roleList = userVo.getRoleList(); - List roleNames = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(roleList)) { - for (SysRole sysRole : roleList) { - if (!StrUtil.equals(SecurityConstants.BASE_ROLE, sysRole.getRoleName())) { - roleNames.add(sysRole.getRoleName()); - } - } - } - String[] roles = roleNames.toArray(new String[roleNames.size()]); + List roleCodes = userVo.getRoleList().stream() + .filter(sysRole -> !StrUtil.equals(SecurityConstants.BASE_ROLE, sysRole.getRoleCode())) + .map(SysRole::getRoleCode) + .collect(Collectors.toList()); + String[] roles = ArrayUtil.toArray(roleCodes, String.class); userInfo.setRoles(roles); //设置权限列表(menu.permission) - Set menuVoSet = new HashSet<>(); - for (String role : roles) { - List menuVos = sysMenuService.findMenuByRoleName(role); - menuVoSet.addAll(menuVos); - } Set permissions = new HashSet<>(); - for (MenuVO menuVo : menuVoSet) { - if (StringUtils.isNotEmpty(menuVo.getPermission())) { - String permission = menuVo.getPermission(); - permissions.add(permission); - } - } - userInfo.setPermissions(permissions.toArray(new String[permissions.size()])); + Arrays.stream(roles).forEach(role -> { + List menuVos = sysMenuService.findMenuByRoleName(role); + List permissionList = menuVos.stream() + .filter(menuVo -> StringUtils.isNotEmpty(menuVo.getPermission())) + .map(MenuVO::getPermission).collect(Collectors.toList()); + permissions.addAll(permissionList); + }); + userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class)); return userInfo; } diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysZuulRouteServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysZuulRouteServiceImpl.java index deda469c..ff2ce027 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysZuulRouteServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysZuulRouteServiceImpl.java @@ -18,12 +18,12 @@ package com.github.pig.admin.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.github.pig.admin.mapper.SysZuulRouteMapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.github.pig.admin.mapper.SysZuulRouteMapper; +import com.github.pig.admin.service.SysZuulRouteService; import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.constant.MqQueueConstant; import com.github.pig.common.entity.SysZuulRoute; -import com.github.pig.admin.service.SysZuulRouteService; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; diff --git a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorDingTalkPropertiesConfig.java b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorDingTalkPropertiesConfig.java index 229520d1..80262135 100644 --- a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorDingTalkPropertiesConfig.java +++ b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorDingTalkPropertiesConfig.java @@ -20,9 +20,6 @@ package com.github.pig.monitor.config; import lombok.Data; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import java.util.ArrayList; -import java.util.List; - /** * @author lengleng * @date 2018/4/22 diff --git a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorPropertiesConfig.java b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorPropertiesConfig.java index aec065a4..cc20342e 100644 --- a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorPropertiesConfig.java +++ b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/config/MonitorPropertiesConfig.java @@ -18,13 +18,9 @@ package com.github.pig.monitor.config; import lombok.Data; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; -import java.util.ArrayList; -import java.util.List; - /** * @author lengleng * @date 2018/1/25 diff --git a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/filter/StatusChangeNotifier.java b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/filter/StatusChangeNotifier.java index 48f52709..78e8160f 100644 --- a/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/filter/StatusChangeNotifier.java +++ b/pig-visual/pig-monitor/src/main/java/com/github/pig/monitor/filter/StatusChangeNotifier.java @@ -20,7 +20,6 @@ package com.github.pig.monitor.filter; import com.alibaba.fastjson.JSONObject; import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.constant.MqQueueConstant; -import com.github.pig.common.constant.enums.EnumSmsChannel; import com.github.pig.common.constant.enums.EnumSmsChannelTemplate; import com.github.pig.common.util.template.MobileMsgTemplate; import com.github.pig.monitor.config.MonitorPropertiesConfig; diff --git a/pig-visual/pig-zipkin-elk/src/main/java/com/github/pig/zipkin/PigZipkinElkApplication.java b/pig-visual/pig-zipkin-elk/src/main/java/com/github/pig/zipkin/PigZipkinElkApplication.java index 42faaae7..d09ab8fa 100644 --- a/pig-visual/pig-zipkin-elk/src/main/java/com/github/pig/zipkin/PigZipkinElkApplication.java +++ b/pig-visual/pig-zipkin-elk/src/main/java/com/github/pig/zipkin/PigZipkinElkApplication.java @@ -20,7 +20,6 @@ package com.github.pig.zipkin; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; import zipkin.server.EnableZipkinServer; /** diff --git a/pom.xml b/pom.xml index 5bc4610a..36751d4f 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ UTF-8 UTF-8 1.8 - 1.2.0 + 1.3.0 1.5.15.RELEASE Edgware.SR4