Explorar el Código

:bookmark: 发布一个版本。 v 1.6.1

冷冷 hace 7 años
padre
commit
83005acfc1
Se han modificado 29 ficheros con 313 adiciones y 104 borrados
  1. 2 0
      pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java
  2. 18 12
      pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java
  3. 2 22
      pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java
  4. 6 0
      pigx-common/pigx-common-security/pom.xml
  5. 35 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignTenantConfiguration.java
  6. 40 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignTenantInterceptor.java
  7. 62 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/filter/TenantIdTtlFilter.java
  8. 10 2
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java
  9. 2 2
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java
  10. 27 4
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java
  11. 2 0
      pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories
  12. 4 9
      pigx-common/pigx-common-transaction/src/main/java/com/pig4cloud/pigx/common/transaction/tx/springcloud/interceptor/TxManagerInterceptor.java
  13. 1 1
      pigx-config/src/main/resources/config/pigx-auth-dev.yml
  14. 1 1
      pigx-config/src/main/resources/config/pigx-codegen-dev.yml
  15. 2 2
      pigx-config/src/main/resources/config/pigx-daemon-dev.yml
  16. 1 1
      pigx-config/src/main/resources/config/pigx-upms-dev.yml
  17. 3 3
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java
  18. 5 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java
  19. 6 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java
  20. 39 1
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/MybatisPlusConfigurer.java
  21. 6 1
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java
  22. 5 16
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java
  23. 2 2
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysMenuMapper.java
  24. 3 2
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysMenuService.java
  25. 3 3
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysMenuServiceImpl.java
  26. 8 8
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java
  27. 11 12
      pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysMenuMapper.xml
  28. 6 0
      pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml
  29. 1 0
      pom.xml

+ 2 - 0
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java

@@ -20,6 +20,7 @@
 package com.pig4cloud.pigx.auth.config;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.pig4cloud.pigx.common.security.filter.TenantIdTtlFilter;
 import com.pig4cloud.pigx.common.security.mobile.MobileLoginSuccessHandler;
 import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer;
 import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService;
@@ -35,6 +36,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
 import org.springframework.security.crypto.factory.PasswordEncoderFactories;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.oauth2.provider.ClientDetailsService;
+import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter;
 import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
 import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
 

+ 18 - 12
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java

@@ -24,6 +24,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.pig4cloud.pigx.common.core.util.R;
 import com.pig4cloud.pigx.common.security.service.PigxUser;
+import com.pig4cloud.pigx.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.redis.core.ConvertingCursor;
 import org.springframework.data.redis.core.Cursor;
@@ -128,19 +129,14 @@ public class PigxTokenEndpoint {
 
 			if (authentication instanceof UsernamePasswordAuthenticationToken) {
 				UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication;
-
-				if (authenticationToken.getPrincipal() instanceof PigxUser) {
-					PigxUser user = (PigxUser) authenticationToken.getPrincipal();
-					map.put("user_id", user.getId() + "");
-					map.put("user_name", user.getUsername() + "");
+				if (extractToken(map, authenticationToken.getPrincipal())) {
+					continue;
 				}
 			} else if (authentication instanceof PreAuthenticatedAuthenticationToken) {
 				//刷新token方式
 				PreAuthenticatedAuthenticationToken authenticationToken = (PreAuthenticatedAuthenticationToken) authentication;
-				if (authenticationToken.getPrincipal() instanceof PigxUser) {
-					PigxUser user = (PigxUser) authenticationToken.getPrincipal();
-					map.put("user_id", user.getId() + "");
-					map.put("user_name", user.getUsername() + "");
+				if (extractToken(map, authenticationToken.getPrincipal())) {
+					continue;
 				}
 			}
 			list.add(map);
@@ -152,12 +148,22 @@ public class PigxTokenEndpoint {
 		return result;
 	}
 
+	private boolean extractToken(Map<String, String> map, Object principal) {
+		if (principal instanceof PigxUser) {
+			PigxUser user = (PigxUser) principal;
+			if (!user.getTenantId().equals(SecurityUtils.getTenantId())) {
+				return true;
+			}
+			map.put("user_id", user.getId() + "");
+			map.put("user_name", user.getUsername() + "");
+		}
+		return false;
+	}
+
 	private List<String> findKeysForPage(String patternKey, int pageNum, int pageSize) {
 		ScanOptions options = ScanOptions.scanOptions().match(patternKey).build();
 		RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer();
-		Cursor cursor = (Cursor) redisTemplate.executeWithStickyConnection(redisConnection -> {
-			return new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize);
-		});
+		Cursor cursor = (Cursor) redisTemplate.executeWithStickyConnection(redisConnection -> new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize));
 		List<String> result = new ArrayList<>();
 		int tmpIndex = 0;
 		int startIndex = (pageNum - 1) * pageSize;

+ 2 - 22
pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java

@@ -25,19 +25,9 @@ package com.pig4cloud.pigx.common.core.constant;
  */
 public interface CommonConstant {
 	/**
-	 * token请求头名称
+	 * header 中租户ID
 	 */
-	String REQ_HEADER = "Authorization";
-
-	/**
-	 * token分割符
-	 */
-	String TOKEN_SPLIT = "Bearer ";
-
-	/**
-	 * jwt签名
-	 */
-	String SIGN_KEY = "PIG";
+	String TENANT_ID = "TENANT_ID";
 	/**
 	 * 删除
 	 */
@@ -76,14 +66,4 @@ public interface CommonConstant {
 	 * JSON 资源
 	 */
 	String CONTENT_TYPE = "application/json; charset=utf-8";
-
-	/**
-	 * 阿里大鱼
-	 */
-	String ALIYUN_SMS = "aliyun_sms";
-
-	/**
-	 * 路由信息Redis保存的key
-	 */
-	String ROUTE_KEY = "_ROUTE_KEY";
 }

+ 6 - 0
pigx-common/pigx-common-security/pom.xml

@@ -51,5 +51,11 @@
 			<artifactId>pigx-upms-api</artifactId>
 			<version>${pigx.version}</version>
 		</dependency>
+		<!--TTL-->
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>transmittable-thread-local</artifactId>
+			<version>${ttl.version}</version>
+		</dependency>
 	</dependencies>
 </project>

+ 35 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignTenantConfiguration.java

@@ -0,0 +1,35 @@
+/*
+ *    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.pig4cloud.pigx.common.security.feign;
+
+import feign.RequestInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author lengleng
+ * @date 2018/9/14
+ * feign 租户信息拦截
+ */
+@Configuration
+public class PigxFeignTenantConfiguration {
+	@Bean
+	public RequestInterceptor PigxFeignTenantInterceptor() {
+		return new PigxFeignTenantInterceptor();
+	}
+}

+ 40 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignTenantInterceptor.java

@@ -0,0 +1,40 @@
+/*
+ *    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.pig4cloud.pigx.common.security.feign;
+
+import com.pig4cloud.pigx.common.core.constant.CommonConstant;
+import com.pig4cloud.pigx.common.security.util.SecurityUtils;
+import feign.RequestInterceptor;
+import feign.RequestTemplate;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author lengleng
+ * @date 2018/9/14
+ */
+@Slf4j
+public class PigxFeignTenantInterceptor implements RequestInterceptor {
+	@Override
+	public void apply(RequestTemplate requestTemplate) {
+		if (SecurityUtils.getTenantId() == null) {
+			log.error("TTL 中的 租户ID为空,feign拦截器 >> 增强失败");
+			return;
+		}
+		requestTemplate.header(CommonConstant.TENANT_ID, SecurityUtils.getTenantId().toString());
+	}
+}

+ 62 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/filter/TenantIdTtlFilter.java

@@ -0,0 +1,62 @@
+/*
+ *    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.pig4cloud.pigx.common.security.filter;
+
+import cn.hutool.core.util.StrUtil;
+import com.pig4cloud.pigx.common.core.constant.CommonConstant;
+import com.pig4cloud.pigx.common.security.util.SecurityUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.GenericFilterBean;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author lengleng
+ * @date 2018/9/13
+ */
+@Slf4j
+@Component
+@Order(Ordered.HIGHEST_PRECEDENCE)
+public class TenantIdTtlFilter extends GenericFilterBean {
+
+	@Override
+	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+		HttpServletRequest request = (HttpServletRequest) servletRequest;
+		HttpServletResponse response = (HttpServletResponse) servletResponse;
+
+		String tenantId = request.getHeader(CommonConstant.TENANT_ID);
+		log.debug("获取header中的租户ID为:{}", tenantId);
+
+		if (StrUtil.isNotBlank(tenantId)) {
+			SecurityUtils.setTenantId(Integer.parseInt(tenantId));
+		} else {
+			SecurityUtils.setTenantId(1);
+		}
+
+		filterChain.doFilter(request, response);
+	}
+}

+ 10 - 2
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java

@@ -41,12 +41,19 @@ public class PigxUser extends User {
 	@Getter
 	private Integer deptId;
 
+	/**
+	 * 租户ID
+	 */
+	@Getter
+	private Integer tenantId;
+
 	/**
 	 * Construct the <code>User</code> with the details required by
 	 * {@link DaoAuthenticationProvider}.
 	 *
 	 * @param id                    用户ID
 	 * @param deptId                部门ID
+	 * @param tenantId              租户ID
 	 * @param username              the username presented to the
 	 *                              <code>DaoAuthenticationProvider</code>
 	 * @param password              the password that should be presented to the
@@ -61,9 +68,10 @@ public class PigxUser extends User {
 	 * @throws IllegalArgumentException if a <code>null</code> value was passed either as
 	 *                                  a parameter or as an element in the <code>GrantedAuthority</code> collection
 	 */
-	public PigxUser(Integer id, Integer deptId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
+	public PigxUser(Integer id, Integer deptId, Integer tenantId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
 		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
 		this.id = id;
-		this.deptId = id;
+		this.deptId = deptId;
+		this.tenantId = tenantId;
 	}
 }

+ 2 - 2
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java

@@ -90,7 +90,7 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
 		Set<String> dbAuthsSet = new HashSet<>();
 		if (ArrayUtil.isNotEmpty(info.getRoles())) {
 			// 获取角色
-			Arrays.stream(info.getRoles()).forEach(role -> dbAuthsSet.add(SecurityConstants.ROLE + role));
+			Arrays.stream(info.getRoles()).forEach(roleId -> dbAuthsSet.add(SecurityConstants.ROLE + roleId));
 			// 获取资源
 			dbAuthsSet.addAll(Arrays.asList(info.getPermissions()));
 
@@ -101,7 +101,7 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
 		boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL);
 		// 构造security用户
 
-		return new PigxUser(user.getUserId(), user.getDeptId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
+		return new PigxUser(user.getUserId(), user.getDeptId(), user.getTenantId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
 			true, true, true, authorities);
 	}
 }

+ 27 - 4
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/SecurityUtils.java

@@ -21,6 +21,7 @@ package com.pig4cloud.pigx.common.security.util;
 
 
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.ttl.TransmittableThreadLocal;
 import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
 import com.pig4cloud.pigx.common.security.service.PigxUser;
 import org.springframework.security.core.Authentication;
@@ -38,6 +39,7 @@ import java.util.List;
  * @author L.cm
  */
 public class SecurityUtils {
+	private static final ThreadLocal<Integer> THREAD_LOCAL_TENANT = new TransmittableThreadLocal<>();
 
 	/**
 	 * 获取Authentication
@@ -82,14 +84,35 @@ public class SecurityUtils {
 	 *
 	 * @return 角色集合
 	 */
-	public static List<String> getRoles() {
+	public static List<Integer> getRoles() {
 		Authentication authentication = getAuthentication();
 		Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
 
-		List<String> roles = new ArrayList<>();
+		List<Integer> roleIds = new ArrayList<>();
 		authorities.stream()
 			.filter(granted -> StrUtil.startWith(granted.getAuthority(), SecurityConstants.ROLE))
-			.forEach(granted -> roles.add(StrUtil.removePrefix(granted.getAuthority(), SecurityConstants.ROLE)));
-		return roles;
+			.forEach(granted -> {
+				String id = StrUtil.removePrefix(granted.getAuthority(), SecurityConstants.ROLE);
+				roleIds.add(Integer.parseInt(id));
+			});
+		return roleIds;
+	}
+
+	/**
+	 * TTL 设置租户ID
+	 *
+	 * @param tenantId
+	 */
+	public static void setTenantId(Integer tenantId) {
+		THREAD_LOCAL_TENANT.set(tenantId);
+	}
+
+	/**
+	 * 获取TTL中的租户ID
+	 *
+	 * @return
+	 */
+	public static Integer getTenantId() {
+		return THREAD_LOCAL_TENANT.get();
 	}
 }

+ 2 - 0
pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories

@@ -1,9 +1,11 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+  com.pig4cloud.pigx.common.security.filter.TenantIdTtlFilter,\
   com.pig4cloud.pigx.common.security.component.PermissionService,\
   com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler,\
   com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint,\
   com.pig4cloud.pigx.common.security.component.PigxResourceServerTokenRelayAutoConfiguration,\
   com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration,\
+  com.pig4cloud.pigx.common.security.feign.PigxFeignTenantConfiguration,\
   com.pig4cloud.pigx.common.security.service.PigxUserDetailsServiceImpl,\
   com.pig4cloud.pigx.common.security.social.QqSocialConfig,\
   com.pig4cloud.pigx.common.security.social.WxSocialConfig

+ 4 - 9
pigx-common/pigx-common-transaction/src/main/java/com/pig4cloud/pigx/common/transaction/tx/springcloud/interceptor/TxManagerInterceptor.java

@@ -28,8 +28,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import javax.servlet.http.HttpServletRequest;
 
 /**
- *@author LCN on 2017/6/7.
- *
+ * @author LCN on 2017/6/7.
  * @author LCN
  * @since 4.1.0
  */
@@ -41,13 +40,9 @@ public class TxManagerInterceptor {
 	private AspectBeforeService aspectBeforeService;
 
 	public Object around(ProceedingJoinPoint point) throws Throwable {
-		String groupId = null;
-		try {
-			RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
-			HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
-			groupId = request.getHeader("tx-group");
-		} catch (Exception e) {
-		}
+		RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
+		HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
+		String groupId = request.getHeader("tx-group");
 		return aspectBeforeService.around(groupId, point);
 	}
 }

+ 1 - 1
pigx-config/src/main/resources/config/pigx-auth-dev.yml

@@ -5,4 +5,4 @@ spring:
     driver-class-name: com.mysql.jdbc.Driver
     username: root
     password:  Bjyjht2017!@#
-    url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
+    url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false

+ 1 - 1
pigx-config/src/main/resources/config/pigx-codegen-dev.yml

@@ -13,7 +13,7 @@ spring:
     driver-class-name: com.mysql.jdbc.Driver
     username: root
     password:  Bjyjht2017!@#
-    url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
+    url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
   jackson:
     time-zone: GMT+8
     date-format: yyyy-MM-dd HH:mm:ss

+ 2 - 2
pigx-config/src/main/resources/config/pigx-daemon-dev.yml

@@ -14,11 +14,11 @@ spring:
     driver-class-name: com.mysql.jdbc.Driver
     username: root
     password:  Bjyjht2017!@#
-    url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
+    url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
   elasticjob:
     # 分布式任务协调依赖zookeeper
     zookeeper:
-      server-lists: 127.0.0.1:13181
+      server-lists: 114.116.45.246:13181
       namespace: pigx-daemon
     # 普通任务
     simples:

+ 1 - 1
pigx-config/src/main/resources/config/pigx-upms-dev.yml

@@ -13,7 +13,7 @@ spring:
     driver-class-name: com.mysql.jdbc.Driver
     username: root
     password:  Bjyjht2017!@#
-    url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
+    url: jdbc:mysql://114.116.30.176:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
 
 # mybaits 模块配置
 mybatis-plus:

+ 3 - 3
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java

@@ -46,7 +46,7 @@ public class UserInfo implements Serializable {
 	/**
 	 * 角色集合
 	 */
-	private String[] roles;
+	private Integer[] roles;
 
 	public SysUser getSysUser() {
 		return sysUser;
@@ -64,11 +64,11 @@ public class UserInfo implements Serializable {
 		this.permissions = permissions;
 	}
 
-	public String[] getRoles() {
+	public Integer[] getRoles() {
 		return roles;
 	}
 
-	public void setRoles(String[] roles) {
+	public void setRoles(Integer[] roles) {
 		this.roles = roles;
 	}
 }

+ 5 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java

@@ -87,6 +87,11 @@ public class SysUser implements Serializable {
 	 */
 	private Integer deptId;
 
+	/**
+	 * 租户ID
+	 */
+	private Integer tenantId;
+
 	/**
 	 * 微信openid
 	 */

+ 6 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java

@@ -86,6 +86,12 @@ public class UserVO implements Serializable {
 	 * 部门ID
 	 */
 	private Integer deptId;
+
+	/**
+	 * 租户ID
+	 */
+	private Integer tenantId;
+
 	/**
 	 * 部门名称
 	 */

+ 39 - 1
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/MybatisPlusConfigurer.java

@@ -19,19 +19,33 @@
 
 package com.pig4cloud.pigx.admin.config;
 
+import cn.hutool.core.util.ArrayUtil;
 import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.plugins.parser.ISqlParser;
+import com.baomidou.mybatisplus.plugins.parser.tenant.TenantHandler;
+import com.baomidou.mybatisplus.plugins.parser.tenant.TenantSqlParser;
 import com.pig4cloud.pigx.common.core.datascope.DataScopeInterceptor;
+import com.pig4cloud.pigx.common.security.util.SecurityUtils;
+import lombok.extern.slf4j.Slf4j;
+import net.sf.jsqlparser.expression.Expression;
+import net.sf.jsqlparser.expression.LongValue;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author lengleng
  * @date 2017/10/29
  */
+@Slf4j
 @Configuration
 @MapperScan("com.pig4cloud.pigx.admin.mapper")
 public class MybatisPlusConfigurer {
+	private static final String[] IGNORETABLES = new String[]{"sys_dept_relation", "sys_role_dept", "sys_role_menu", "sys_user_role"};
+
 	/**
 	 * 分页插件
 	 *
@@ -39,7 +53,31 @@ public class MybatisPlusConfigurer {
 	 */
 	@Bean
 	public PaginationInterceptor paginationInterceptor() {
-		return new PaginationInterceptor();
+		PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
+		List<ISqlParser> sqlParserList = new ArrayList<>();
+		TenantSqlParser tenantSqlParser = new TenantSqlParser();
+		tenantSqlParser.setTenantHandler(new TenantHandler() {
+			@Override
+			public Expression getTenantId() {
+				Integer tenantId = SecurityUtils.getTenantId();
+				log.error("当前租户为 >> {}", tenantId);
+				return new LongValue(tenantId);
+			}
+
+			@Override
+			public String getTenantIdColumn() {
+				return "tenant_id";
+			}
+
+			@Override
+			public boolean doTableFilter(String tableName) {
+				log.error("当前租户表为 >> {}", tableName);
+				return ArrayUtil.contains(IGNORETABLES, tableName);
+			}
+		});
+		sqlParserList.add(tenantSqlParser);
+		paginationInterceptor.setSqlParserList(sqlParserList);
+		return paginationInterceptor;
 	}
 
 	/**

+ 6 - 1
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java

@@ -20,22 +20,27 @@
 package com.pig4cloud.pigx.admin.config;
 
 import com.pig4cloud.pigx.common.security.component.BaseResourceServerConfigurerAdapter;
+import com.pig4cloud.pigx.common.security.filter.TenantIdTtlFilter;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
+import org.springframework.security.web.access.channel.ChannelProcessingFilter;
 
 /**
  * @author lengleng
  * @date 2018/6/22
  */
+@Slf4j
 @Configuration
 @EnableResourceServer
 @EnableGlobalMethodSecurity(prePostEnabled = true)
 public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
 	@Override
 	public void configure(HttpSecurity http) throws Exception {
-		http.authorizeRequests()
+		http
+			.authorizeRequests()
 			.antMatchers("/actuator/**"
 				, "/user/info/*"
 				, "/social/info/**"

+ 5 - 16
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java

@@ -46,17 +46,6 @@ public class MenuController {
 	@Autowired
 	private SysMenuService sysMenuService;
 
-	/**
-	 * 通过角色名称查询用户菜单
-	 *
-	 * @param role 角色名称
-	 * @return 菜单列表
-	 */
-	@GetMapping("/findMenuByRole/{role}")
-	public List<MenuVO> findMenuByRole(@PathVariable String role) {
-		return sysMenuService.findMenuByRoleCode(role);
-	}
-
 	/**
 	 * 返回当前用户的树形菜单集合
 	 *
@@ -66,7 +55,7 @@ public class MenuController {
 	public List<MenuTree> userMenu() {
 		// 获取符合条件得菜单
 		Set<MenuVO> all = new HashSet<>();
-		SecurityUtils.getRoles().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleCode(roleName)));
+		SecurityUtils.getRoles().forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
 		List<MenuTree> menuTreeList = new ArrayList<>();
 		all.forEach(menuVo -> {
 			if (CommonConstant.MENU.equals(menuVo.getType())) {
@@ -92,12 +81,12 @@ public class MenuController {
 	/**
 	 * 返回角色的菜单集合
 	 *
-	 * @param roleName 角色名称
+	 * @param roleId 角色ID
 	 * @return 属性集合
 	 */
-	@GetMapping("/roleTree/{roleName}")
-	public List<Integer> roleTree(@PathVariable String roleName) {
-		List<MenuVO> menus = sysMenuService.findMenuByRoleCode(roleName);
+	@GetMapping("/roleTree/{roleId}")
+	public List<Integer> roleTree(@PathVariable Integer roleId) {
+		List<MenuVO> menus = sysMenuService.findMenuByRoleId(roleId);
 		List<Integer> menuList = new ArrayList<>();
 		for (MenuVO menuVo : menus) {
 			menuList.add(menuVo.getMenuId());

+ 2 - 2
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysMenuMapper.java

@@ -38,10 +38,10 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
 	/**
 	 * 通过角色编号查询菜单
 	 *
-	 * @param role 角色编号
+	 * @param roleId 角色ID
 	 * @return
 	 */
-	List<MenuVO> findMenuByRoleCode(String role);
+	List<MenuVO> findMenuByRoleId(Integer roleId);
 
 	/**
 	 * 通过角色ID查询权限

+ 3 - 2
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysMenuService.java

@@ -23,6 +23,7 @@ package com.pig4cloud.pigx.admin.service;
 import com.baomidou.mybatisplus.service.IService;
 import com.pig4cloud.pigx.admin.api.entity.SysMenu;
 import com.pig4cloud.pigx.admin.api.vo.MenuVO;
+import io.swagger.models.auth.In;
 
 import java.util.List;
 
@@ -38,10 +39,10 @@ public interface SysMenuService extends IService<SysMenu> {
 	/**
 	 * 通过角色编号查询URL 权限
 	 *
-	 * @param role 角色编号
+	 * @param roleId 角色ID
 	 * @return 菜单列表
 	 */
-	List<MenuVO> findMenuByRoleCode(String role);
+	List<MenuVO> findMenuByRoleId(Integer roleId);
 
 	/**
 	 * 级联删除菜单

+ 3 - 3
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysMenuServiceImpl.java

@@ -47,9 +47,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
 	private SysMenuMapper sysMenuMapper;
 
 	@Override
-	@Cacheable(value = "menu_details", key = "#role  + '_menu'")
-	public List<MenuVO> findMenuByRoleCode(String role) {
-		return sysMenuMapper.findMenuByRoleCode(role);
+	@Cacheable(value = "menu_details", key = "#roleId  + '_menu'")
+	public List<MenuVO> findMenuByRoleId(Integer roleId) {
+		return sysMenuMapper.findMenuByRoleId(roleId);
 	}
 
 	@Override

+ 8 - 8
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java

@@ -78,7 +78,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 	 * @return
 	 */
 	@Override
-	@Cacheable(value = "user_details", key = "#username",unless = "#result == null")
+	@Cacheable(value = "user_details", key = "#username", unless="#result == null")
 	public UserInfo findUserInfo(String type, String username) {
 		SysUser condition = new SysUser();
 		if (EnumLoginType.PWD.getType().equals(type)) {
@@ -91,22 +91,22 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 		SysUser sysUser = this.selectOne(new EntityWrapper<>(condition));
 		if (sysUser == null) {
 			return null;
-		}
+		} 
 
 		UserInfo userInfo = new UserInfo();
 		userInfo.setSysUser(sysUser);
-		//设置角色列表
+		//设置角色列表  (ID)
 		List<SysRole> roleList = sysRoleService.findRolesByUserId(sysUser.getUserId());
-		List<String> roleCodes = new ArrayList<>();
+		List<Integer> roleIds = new ArrayList<>();
 		if (CollUtil.isNotEmpty(roleList)) {
-			roleList.forEach(sysRole -> roleCodes.add(sysRole.getRoleCode()));
+			roleList.forEach(sysRole -> roleIds.add(sysRole.getRoleId()));
 		}
-		userInfo.setRoles(ArrayUtil.toArray(roleCodes, String.class));
+		userInfo.setRoles(ArrayUtil.toArray(roleIds, Integer.class));
 
 		//设置权限列表(menu.permission)
 		Set<MenuVO> menuVoSet = new HashSet<>();
-		for (String role : roleCodes) {
-			List<MenuVO> menuVos = sysMenuService.findMenuByRoleCode(role);
+		for (Integer roleId : roleIds) {
+			List<MenuVO> menuVos = sysMenuService.findMenuByRoleId(roleId);
 			menuVoSet.addAll(menuVos);
 		}
 		Set<String> permissions = new HashSet<>();

+ 11 - 12
pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysMenuMapper.xml

@@ -53,18 +53,17 @@
 	</resultMap>
 
 	<!--通过角色查询菜单信息-->
-	<select id="findMenuByRoleCode" resultMap="MenuVoResultMap">
-        SELECT
-            sys_menu.*
-        FROM
-        sys_role
-        LEFT JOIN sys_role_menu ON sys_role_menu.role_id = sys_role.role_id
-        LEFT JOIN sys_menu ON sys_menu.menu_id = sys_role_menu.menu_id
-        WHERE
-        sys_role.del_flag = 0
-        AND sys_menu.del_flag = 0
-        AND sys_role.role_code = #{role}
-        ORDER BY sys_menu.sort DESC
+	<select id="findMenuByRoleId" resultMap="MenuVoResultMap">
+		SELECT
+			sys_menu.*
+		FROM
+			sys_menu
+		LEFT JOIN sys_role_menu ON sys_menu.menu_id = sys_role_menu.menu_id
+		WHERE
+			sys_menu.del_flag = 0
+		AND sys_role_menu.role_id = #{roleId}
+		ORDER BY
+			sys_menu.sort DESC
     </select>
 
 	<!--通过角色ID 查询权限-->

+ 6 - 0
pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -29,6 +29,7 @@
 		<result column="avatar" property="avatar"/>
 		<result column="salt" property="salt"/>
 		<result column="dept_id" property="deptId"/>
+		<result column="tenant_id" property="tenantId"/>
 		<result column="wx_openid" property="wxOpenid"/>
 		<result column="qq_openid" property="qqOpenid"/>
 		<result column="create_time" property="createTime"/>
@@ -50,6 +51,7 @@
 		<result column="uupdate_time" property="updateTime"/>
 		<result column="udel_flag" property="delFlag"/>
 		<result column="deptId" property="deptId"/>
+		<result column="tenantId" property="tenantId"/>
 		<result column="deptName" property="deptName"/>
 		<collection property="roleList" ofType="com.pig4cloud.pigx.admin.api.entity.SysRole">
 			<id column="role_id" property="roleId"/>
@@ -76,6 +78,7 @@
             `user`.update_time AS uupdate_time,
             `user`.del_flag AS udel_flag,
             `user`.dept_id AS deptId,
+            `user`.tenant_id AS tenantId,
             r.role_id,
             r.role_name,
             r.role_code,
@@ -106,6 +109,7 @@
             `user`.create_time AS ucreate_time,
             `user`.update_time AS uupdate_time,
             `user`.del_flag AS udel_flag,
+            `user`.tenant_id AS tenantId,
             r.role_id,
             r.role_name,
             r.role_code,
@@ -136,6 +140,7 @@
 		`user`.create_time AS ucreate_time,
 		`user`.update_time AS uupdate_time,
 		`user`.del_flag AS udel_flag,
+		`user`.tenant_id AS tenantId,
 		r.role_id,
 		r.role_name,
 		r.role_code,
@@ -165,6 +170,7 @@
 		 	   avatar,
 		 	   salt,
 		 	   dept_id,
+		 	   tenant_id,
 		 	   wx_openid,
 		 	   qq_openid,
 		 	   create_time,

+ 1 - 0
pom.xml

@@ -53,6 +53,7 @@
 		<velocity.version>1.7</velocity.version>
 		<lcn.version>4.1.0</lcn.version>
 		<jasypt.version>2.1.0</jasypt.version>
+		<ttl.version>2.6.1</ttl.version>
 		<elastic-job-lite.version>2.1.5</elastic-job-lite.version>
 		<security.oauth.version>2.3.3.RELEASE</security.oauth.version>
 		<jackson.modules>2.9.6</jackson.modules>