mirror of https://gitee.com/maxjhandsome/pig
🔖 发布一个版本。代码重构 v1.3.0
This commit is contained in:
parent
569e4c43dc
commit
e62bc23b37
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TokenArgumentResolver implements HandlerMethodArgumentResolver {
|
|||
List<SysRole> 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);
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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日
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<SimpleGrantedAuthority> grantedAuthorityList = (List<SimpleGrantedAuthority>) authentication.getAuthorities();
|
||||
boolean hasPermission = false;
|
||||
List<SimpleGrantedAuthority> authorityList = (List<SimpleGrantedAuthority>) 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<MenuVO> urls = new HashSet<>();
|
||||
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
|
||||
if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) {
|
||||
authorityList.stream().filter(authority ->
|
||||
!StrUtil.equals(authority.getAuthority(), "ROLE_USER"))
|
||||
.forEach(authority -> {
|
||||
Set<MenuVO> menuVOSet = menuService.findMenuByRole(authority.getAuthority());
|
||||
if (CollUtil.isNotEmpty(menuVOSet)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SysRole> 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<? extends GrantedAuthority> getAuthorities() {
|
||||
List<GrantedAuthority> 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<SysRole> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
public void setRoleList(List<SysRole> roleList) {
|
||||
this.roleList = roleList;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<MenuTree> userMenu() {
|
||||
public List<MenuTree> userMenu(UserVO userVO) {
|
||||
// 获取符合条件得菜单
|
||||
Set<MenuVO> all = new HashSet<>();
|
||||
getRole().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleName(roleName)));
|
||||
List<MenuTree> 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<MenuTree> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> impl
|
|||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setSysUser(sysUser);
|
||||
//设置角色列表
|
||||
List<SysRole> roleList = userVo.getRoleList();
|
||||
List<String> 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<String> 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<MenuVO> menuVoSet = new HashSet<>();
|
||||
for (String role : roles) {
|
||||
List<MenuVO> menuVos = sysMenuService.findMenuByRoleName(role);
|
||||
menuVoSet.addAll(menuVos);
|
||||
}
|
||||
Set<String> 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<MenuVO> menuVos = sysMenuService.findMenuByRoleName(role);
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -37,7 +37,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<pig.version>1.2.0</pig.version>
|
||||
<pig.version>1.3.0</pig.version>
|
||||
<spring-boot.version>1.5.15.RELEASE</spring-boot.version>
|
||||
<spring-cloud.version>Edgware.SR4</spring-cloud.version>
|
||||
|
||||
|
|
Loading…
Reference in New Issue