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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
|
@ -38,6 +38,9 @@ public class UserDetailServiceImpl implements UserDetailsService {
|
||||||
@Override
|
@Override
|
||||||
public UserDetailsImpl loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetailsImpl loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
UserVO userVo = userService.findUserByUsername(username);
|
UserVO userVo = userService.findUserByUsername(username);
|
||||||
|
if (userVo == null) {
|
||||||
|
throw new UsernameNotFoundException("用户名不存在或者密码错误");
|
||||||
|
}
|
||||||
return new UserDetailsImpl(userVo);
|
return new UserDetailsImpl(userVo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class TokenArgumentResolver implements HandlerMethodArgumentResolver {
|
||||||
List<SysRole> sysRoleList = new ArrayList<>();
|
List<SysRole> sysRoleList = new ArrayList<>();
|
||||||
Arrays.stream(roles.split(",")).forEach(role -> {
|
Arrays.stream(roles.split(",")).forEach(role -> {
|
||||||
SysRole sysRole = new SysRole();
|
SysRole sysRole = new SysRole();
|
||||||
sysRole.setRoleName(role);
|
sysRole.setRoleCode(role);
|
||||||
sysRoleList.add(sysRole);
|
sysRoleList.add(sysRole);
|
||||||
});
|
});
|
||||||
userVO.setRoleList(sysRoleList);
|
userVO.setRoleList(sysRoleList);
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
package com.github.pig.common.bean.xss;
|
package com.github.pig.common.bean.xss;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.text.Normalizer.Form;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.text.Normalizer;
|
|
||||||
import java.text.Normalizer.Form;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML filtering utility for protecting against XSS (Cross Site Scripting).
|
* HTML filtering utility for protecting against XSS (Cross Site Scripting).
|
||||||
|
|
|
@ -17,15 +17,15 @@
|
||||||
|
|
||||||
package com.github.pig.common.entity;
|
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.activerecord.Model;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableId;
|
||||||
import com.baomidou.mybatisplus.annotations.TableName;
|
import com.baomidou.mybatisplus.annotations.TableName;
|
||||||
|
import com.baomidou.mybatisplus.enums.IdType;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -20,7 +20,6 @@ package com.github.pig.common.vo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ package com.github.pig.config;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.SpringCloudApplication;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.config.server.EnableConfigServer;
|
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||||
|
|
||||||
|
|
|
@ -18,33 +18,19 @@
|
||||||
package com.github.pig.gateway.component.filter;
|
package com.github.pig.gateway.component.filter;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.R;
|
||||||
import com.github.pig.common.util.exception.CheckedException;
|
|
||||||
import com.netflix.zuul.ZuulFilter;
|
import com.netflix.zuul.ZuulFilter;
|
||||||
import com.netflix.zuul.context.RequestContext;
|
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 com.xiaoleilu.hutool.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpMethod;
|
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 javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
* @date 2018年05月10日
|
* @date 2018年05月10日
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
package com.github.pig.gateway.component.filter;
|
package com.github.pig.gateway.component.filter;
|
||||||
|
|
||||||
import com.github.pig.common.bean.xss.XssHttpServletRequestWrapper;
|
import com.github.pig.common.bean.xss.XssHttpServletRequestWrapper;
|
||||||
import com.netflix.zuul.ZuulFilter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
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.github.pig.gateway.feign.MenuService;
|
||||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -17,12 +17,10 @@
|
||||||
|
|
||||||
package com.github.pig.gateway.service.impl;
|
package com.github.pig.gateway.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.toolkit.StringUtils;
|
|
||||||
import com.github.pig.common.vo.MenuVO;
|
import com.github.pig.common.vo.MenuVO;
|
||||||
import com.github.pig.gateway.feign.MenuService;
|
import com.github.pig.gateway.feign.MenuService;
|
||||||
import com.github.pig.gateway.service.PermissionService;
|
import com.github.pig.gateway.service.PermissionService;
|
||||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||||
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
|
||||||
import com.xiaoleilu.hutool.util.StrUtil;
|
import com.xiaoleilu.hutool.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -35,6 +33,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
|
@ -55,33 +54,28 @@ public class PermissionServiceImpl implements PermissionService {
|
||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
Object principal = authentication.getPrincipal();
|
Object principal = authentication.getPrincipal();
|
||||||
List<SimpleGrantedAuthority> grantedAuthorityList = (List<SimpleGrantedAuthority>) authentication.getAuthorities();
|
List<SimpleGrantedAuthority> authorityList = (List<SimpleGrantedAuthority>) authentication.getAuthorities();
|
||||||
boolean hasPermission = false;
|
AtomicBoolean hasPermission = new AtomicBoolean(false);
|
||||||
|
|
||||||
if (principal != null) {
|
if (principal != null) {
|
||||||
if (CollectionUtil.isEmpty(grantedAuthorityList)) {
|
if (CollUtil.isEmpty(authorityList)) {
|
||||||
log.warn("角色列表为空:{}", authentication.getPrincipal());
|
log.warn("角色列表为空:{}", authentication.getPrincipal());
|
||||||
return hasPermission;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<MenuVO> urls = new HashSet<>();
|
Set<MenuVO> urls = new HashSet<>();
|
||||||
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
|
authorityList.stream().filter(authority ->
|
||||||
if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) {
|
!StrUtil.equals(authority.getAuthority(), "ROLE_USER"))
|
||||||
|
.forEach(authority -> {
|
||||||
Set<MenuVO> menuVOSet = menuService.findMenuByRole(authority.getAuthority());
|
Set<MenuVO> menuVOSet = menuService.findMenuByRole(authority.getAuthority());
|
||||||
if (CollUtil.isNotEmpty(menuVOSet)) {
|
|
||||||
CollUtil.addAll(urls, menuVOSet);
|
CollUtil.addAll(urls, menuVOSet);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MenuVO menu : urls) {
|
urls.stream().filter(menu -> StrUtil.isNotEmpty(menu.getUrl())
|
||||||
if (StringUtils.isNotEmpty(menu.getUrl()) && antPathMatcher.match(menu.getUrl(), request.getRequestURI())
|
&& antPathMatcher.match(menu.getUrl(), request.getRequestURI())
|
||||||
&& request.getMethod().equalsIgnoreCase(menu.getMethod())) {
|
&& request.getMethod().equalsIgnoreCase(menu.getMethod()))
|
||||||
hasPermission = true;
|
.findFirst().ifPresent(menuVO -> hasPermission.set(true));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
return hasPermission.get();
|
||||||
}
|
|
||||||
return hasPermission;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
package com.github.pig.mc.listener;
|
||||||
|
|
||||||
import com.github.pig.common.constant.MqQueueConstant;
|
import com.github.pig.common.constant.MqQueueConstant;
|
||||||
import com.github.pig.common.util.template.DingTalkMsgTemplate;
|
|
||||||
import com.github.pig.mc.handler.DingTalkMessageHandler;
|
import com.github.pig.mc.handler.DingTalkMessageHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
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.admin.service.SysLogService;
|
||||||
import com.github.pig.common.constant.MqQueueConstant;
|
import com.github.pig.common.constant.MqQueueConstant;
|
||||||
import com.github.pig.common.entity.SysLog;
|
import com.github.pig.common.entity.SysLog;
|
||||||
import com.github.pig.common.util.UserUtils;
|
|
||||||
import com.github.pig.common.vo.LogVO;
|
import com.github.pig.common.vo.LogVO;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
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.mapper.EntityWrapper;
|
||||||
import com.baomidou.mybatisplus.plugins.Page;
|
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.model.entity.SysDict;
|
||||||
import com.github.pig.admin.service.SysDictService;
|
import com.github.pig.admin.service.SysDictService;
|
||||||
import com.github.pig.common.constant.CommonConstant;
|
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.constant.CommonConstant;
|
||||||
import com.github.pig.common.util.R;
|
import com.github.pig.common.util.R;
|
||||||
import com.github.pig.common.vo.MenuVO;
|
import com.github.pig.common.vo.MenuVO;
|
||||||
|
import com.github.pig.common.vo.UserVO;
|
||||||
import com.github.pig.common.web.BaseController;
|
import com.github.pig.common.web.BaseController;
|
||||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
|
@ -56,20 +57,20 @@ public class MenuController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 返回当前用户的树形菜单集合
|
* 返回当前用户的树形菜单集合
|
||||||
*
|
*
|
||||||
|
* @param userVO
|
||||||
* @return 当前用户的树形菜单
|
* @return 当前用户的树形菜单
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/userMenu")
|
@GetMapping(value = "/userMenu")
|
||||||
public List<MenuTree> userMenu() {
|
public List<MenuTree> userMenu(UserVO userVO) {
|
||||||
// 获取符合条件得菜单
|
// 获取符合条件得菜单
|
||||||
Set<MenuVO> all = new HashSet<>();
|
Set<MenuVO> all = new HashSet<>();
|
||||||
getRole().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleName(roleName)));
|
userVO.getRoleList().forEach(role -> all.addAll(sysMenuService.findMenuByRoleName(role.getRoleCode())));
|
||||||
List<MenuTree> menuTreeList = new ArrayList<>();
|
|
||||||
all.forEach(menuVo -> {
|
List<MenuTree> menuTreeList = all.stream().filter(vo -> CommonConstant.MENU
|
||||||
if (CommonConstant.MENU.equals(menuVo.getType())) {
|
.equals(vo.getType()))
|
||||||
menuTreeList.add(new MenuTree(menuVo));
|
.map(MenuTree::new)
|
||||||
}
|
.sorted(Comparator.comparingInt(MenuTree::getSort))
|
||||||
});
|
.collect(Collectors.toList());
|
||||||
CollUtil.sort(menuTreeList, Comparator.comparingInt(MenuTree::getSort));
|
|
||||||
return TreeUtil.bulid(menuTreeList, -1);
|
return TreeUtil.bulid(menuTreeList, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,17 @@
|
||||||
|
|
||||||
package com.github.pig.admin.controller;
|
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.mapper.EntityWrapper;
|
||||||
import com.baomidou.mybatisplus.plugins.Page;
|
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.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 com.github.pig.common.web.BaseController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
package com.github.pig.admin.model.entity;
|
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.activerecord.Model;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableId;
|
||||||
import com.baomidou.mybatisplus.annotations.TableName;
|
import com.baomidou.mybatisplus.annotations.TableName;
|
||||||
import com.baomidou.mybatisplus.enums.IdType;
|
import com.baomidou.mybatisplus.enums.IdType;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ package com.github.pig.admin.service;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.service.IService;
|
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.admin.model.entity.SysMenu;
|
||||||
import com.github.pig.common.vo.MenuVO;
|
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.mapper.EntityWrapper;
|
||||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
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.mapper.SysMenuMapper;
|
||||||
import com.github.pig.admin.model.dto.MenuTree;
|
|
||||||
import com.github.pig.admin.model.entity.SysMenu;
|
import com.github.pig.admin.model.entity.SysMenu;
|
||||||
import com.github.pig.admin.service.SysMenuService;
|
import com.github.pig.admin.service.SysMenuService;
|
||||||
import com.github.pig.common.constant.CommonConstant;
|
import com.github.pig.common.constant.CommonConstant;
|
||||||
import com.github.pig.common.util.Assert;
|
import com.github.pig.common.util.Assert;
|
||||||
import com.github.pig.common.vo.MenuVO;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
package com.github.pig.admin.service.impl;
|
package com.github.pig.admin.service.impl;
|
||||||
|
|
||||||
import com.github.pig.admin.mapper.SysOauthClientDetailsMapper;
|
|
||||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
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.model.entity.SysOauthClientDetails;
|
||||||
import com.github.pig.admin.service.SysOauthClientDetailsService;
|
import com.github.pig.admin.service.SysOauthClientDetailsService;
|
||||||
import org.springframework.stereotype.Service;
|
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.mapper.SysRoleMenuMapper;
|
||||||
import com.github.pig.admin.model.entity.SysRoleMenu;
|
import com.github.pig.admin.model.entity.SysRoleMenu;
|
||||||
import com.github.pig.admin.service.SysRoleMenuService;
|
import com.github.pig.admin.service.SysRoleMenuService;
|
||||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
|
||||||
import com.xiaoleilu.hutool.util.StrUtil;
|
import com.xiaoleilu.hutool.util.StrUtil;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
|
@ -19,7 +19,6 @@ package com.github.pig.admin.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
||||||
import com.baomidou.mybatisplus.plugins.Page;
|
import com.baomidou.mybatisplus.plugins.Page;
|
||||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||||
import com.github.pig.admin.mapper.SysUserMapper;
|
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.constant.enums.EnumSmsChannelTemplate;
|
||||||
import com.github.pig.common.util.Query;
|
import com.github.pig.common.util.Query;
|
||||||
import com.github.pig.common.util.R;
|
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.util.template.MobileMsgTemplate;
|
||||||
import com.github.pig.common.vo.MenuVO;
|
import com.github.pig.common.vo.MenuVO;
|
||||||
import com.github.pig.common.vo.SysRole;
|
import com.github.pig.common.vo.SysRole;
|
||||||
import com.github.pig.common.vo.UserVO;
|
import com.github.pig.common.vo.UserVO;
|
||||||
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
||||||
|
import com.xiaoleilu.hutool.util.ArrayUtil;
|
||||||
import com.xiaoleilu.hutool.util.RandomUtil;
|
import com.xiaoleilu.hutool.util.RandomUtil;
|
||||||
import com.xiaoleilu.hutool.util.StrUtil;
|
import com.xiaoleilu.hutool.util.StrUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
@ -61,6 +60,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
|
@ -68,20 +68,15 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||||
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
||||||
@Autowired
|
private final SysMenuService sysMenuService;
|
||||||
private SysMenuService sysMenuService;
|
private final RedisTemplate redisTemplate;
|
||||||
@Autowired
|
private final SysUserMapper sysUserMapper;
|
||||||
private RedisTemplate redisTemplate;
|
private final RabbitTemplate rabbitTemplate;
|
||||||
@Autowired
|
private final SysUserRoleService sysUserRoleService;
|
||||||
private SysUserMapper sysUserMapper;
|
private final SysDeptRelationService sysDeptRelationService;
|
||||||
@Autowired
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
|
||||||
@Autowired
|
|
||||||
private SysUserRoleService sysUserRoleService;
|
|
||||||
@Autowired
|
|
||||||
private SysDeptRelationService sysDeptRelationService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo findUserInfo(UserVO userVo) {
|
public UserInfo findUserInfo(UserVO userVo) {
|
||||||
|
@ -92,32 +87,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
UserInfo userInfo = new UserInfo();
|
UserInfo userInfo = new UserInfo();
|
||||||
userInfo.setSysUser(sysUser);
|
userInfo.setSysUser(sysUser);
|
||||||
//设置角色列表
|
//设置角色列表
|
||||||
List<SysRole> roleList = userVo.getRoleList();
|
List<String> roleCodes = userVo.getRoleList().stream()
|
||||||
List<String> roleNames = new ArrayList<>();
|
.filter(sysRole -> !StrUtil.equals(SecurityConstants.BASE_ROLE, sysRole.getRoleCode()))
|
||||||
if (CollectionUtil.isNotEmpty(roleList)) {
|
.map(SysRole::getRoleCode)
|
||||||
for (SysRole sysRole : roleList) {
|
.collect(Collectors.toList());
|
||||||
if (!StrUtil.equals(SecurityConstants.BASE_ROLE, sysRole.getRoleName())) {
|
String[] roles = ArrayUtil.toArray(roleCodes, String.class);
|
||||||
roleNames.add(sysRole.getRoleName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] roles = roleNames.toArray(new String[roleNames.size()]);
|
|
||||||
userInfo.setRoles(roles);
|
userInfo.setRoles(roles);
|
||||||
|
|
||||||
//设置权限列表(menu.permission)
|
//设置权限列表(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<>();
|
Set<String> permissions = new HashSet<>();
|
||||||
for (MenuVO menuVo : menuVoSet) {
|
Arrays.stream(roles).forEach(role -> {
|
||||||
if (StringUtils.isNotEmpty(menuVo.getPermission())) {
|
List<MenuVO> menuVos = sysMenuService.findMenuByRoleName(role);
|
||||||
String permission = menuVo.getPermission();
|
List<String> permissionList = menuVos.stream()
|
||||||
permissions.add(permission);
|
.filter(menuVo -> StringUtils.isNotEmpty(menuVo.getPermission()))
|
||||||
}
|
.map(MenuVO::getPermission).collect(Collectors.toList());
|
||||||
}
|
permissions.addAll(permissionList);
|
||||||
userInfo.setPermissions(permissions.toArray(new String[permissions.size()]));
|
});
|
||||||
|
userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class));
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
package com.github.pig.admin.service.impl;
|
package com.github.pig.admin.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
import com.github.pig.admin.mapper.SysZuulRouteMapper;
|
|
||||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
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.CommonConstant;
|
||||||
import com.github.pig.common.constant.MqQueueConstant;
|
import com.github.pig.common.constant.MqQueueConstant;
|
||||||
import com.github.pig.common.entity.SysZuulRoute;
|
import com.github.pig.common.entity.SysZuulRoute;
|
||||||
import com.github.pig.admin.service.SysZuulRouteService;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
|
@ -20,9 +20,6 @@ package com.github.pig.monitor.config;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
* @date 2018/4/22
|
* @date 2018/4/22
|
||||||
|
|
|
@ -18,13 +18,9 @@
|
||||||
package com.github.pig.monitor.config;
|
package com.github.pig.monitor.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
* @date 2018/1/25
|
* @date 2018/1/25
|
||||||
|
|
|
@ -20,7 +20,6 @@ package com.github.pig.monitor.filter;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.github.pig.common.constant.CommonConstant;
|
import com.github.pig.common.constant.CommonConstant;
|
||||||
import com.github.pig.common.constant.MqQueueConstant;
|
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.constant.enums.EnumSmsChannelTemplate;
|
||||||
import com.github.pig.common.util.template.MobileMsgTemplate;
|
import com.github.pig.common.util.template.MobileMsgTemplate;
|
||||||
import com.github.pig.monitor.config.MonitorPropertiesConfig;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
|
||||||
import zipkin.server.EnableZipkinServer;
|
import zipkin.server.EnableZipkinServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -37,7 +37,7 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<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-boot.version>1.5.15.RELEASE</spring-boot.version>
|
||||||
<spring-cloud.version>Edgware.SR4</spring-cloud.version>
|
<spring-cloud.version>Edgware.SR4</spring-cloud.version>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue