shangke 2 anos atrás
pai
commit
4d7aa302d5

+ 2 - 2
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/core/filter/PhoneLoginAuthenticationFilter.java

@@ -59,9 +59,9 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
 		boolean isRegister = StringUtils.equals("1", isLessee) || StringUtils.equals("true", isLessee);
 		boolean isRegister = StringUtils.equals("1", isLessee) || StringUtils.equals("true", isLessee);
 
 
 		String clientId = request.getParameter("clientId").toUpperCase();
 		String clientId = request.getParameter("clientId").toUpperCase();
-		if ("EDUCATION".equals(clientId)) {
+		/*if ("EDUCATION".equals(clientId)) {
 			clientId = "SYSTEM";
 			clientId = "SYSTEM";
-		}
+		}*/
 		String deviceNum = request.getParameter("deviceNum");
 		String deviceNum = request.getParameter("deviceNum");
 
 
 		principal = principal.trim();
 		principal = principal.trim();

+ 1 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/core/filter/UsernameAuthenticationFilter.java

@@ -80,6 +80,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
 			if("EDUCATION".equals(clientId)){
 			if("EDUCATION".equals(clientId)){
 				//clientId = "SYSTEM";
 				//clientId = "SYSTEM";
 				List<String> collect = Arrays.stream(userInfo.getSysUser().getUserType().split(","))
 				List<String> collect = Arrays.stream(userInfo.getSysUser().getUserType().split(","))
+						.map(String::toUpperCase)
 						.collect(Collectors.toList());
 						.collect(Collectors.toList());
 
 
 				// 用户身份匹配标识
 				// 用户身份匹配标识

+ 30 - 2
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/core/provider/PhoneAuthenticationProvider.java

@@ -1,11 +1,14 @@
 package com.ym.mec.auth.core.provider;
 package com.ym.mec.auth.core.provider;
 
 
+import java.util.Arrays;
 import java.util.Date;
 import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
 
 
+import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.auth.web.controller.queryInfo.QRLoginDto;
 import com.ym.mec.auth.web.controller.queryInfo.QRLoginDto;
 import com.ym.mec.common.redis.service.RedisCache;
 import com.ym.mec.common.redis.service.RedisCache;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.InternalAuthenticationServiceException;
 import org.springframework.security.authentication.InternalAuthenticationServiceException;
 import org.springframework.security.authentication.LockedException;
 import org.springframework.security.authentication.LockedException;
@@ -46,7 +49,7 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
 
 
 	@Override
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	@Transactional(rollbackFor = Exception.class)
-	protected UserDetails retrieveUser(String username, Authentication authentication) throws AuthenticationException {
+	public UserDetails retrieveUser(String username, Authentication authentication) throws AuthenticationException {
 		LoginEntity loginEntity = (LoginEntity) authentication.getCredentials();
 		LoginEntity loginEntity = (LoginEntity) authentication.getCredentials();
 		if (loginEntity == null) {
 		if (loginEntity == null) {
 			throw new BadCredentialsException("Bad credentials");
 			throw new BadCredentialsException("Bad credentials");
@@ -88,6 +91,12 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
 		}
 		}
 
 
 		if (userInfo == null) {
 		if (userInfo == null) {
+
+			// 强制默认管理登录类型
+			if ("EDUCATION".equals(clientId)) {
+				clientId = "SYSTEM";
+			}
+
 			if (isRegister == false || StringUtils.equals("SYSTEM", clientId)) {
 			if (isRegister == false || StringUtils.equals("SYSTEM", clientId)) {
 				throw new LockedException("用户不存在");
 				throw new LockedException("用户不存在");
 			}
 			}
@@ -102,6 +111,25 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
 			if (user == null) {
 			if (user == null) {
 				throw new LockedException("用户不存在");
 				throw new LockedException("用户不存在");
 			}
 			}
+
+			// 管理端登录或学校端登录
+			if(SysUserType.EDUCATION.getCode().equals(clientId.toUpperCase())){
+
+				List<String> collect = Arrays.stream(userInfo.getSysUser().getUserType().split(","))
+						.map(String::toUpperCase)
+						.collect(Collectors.toList());
+
+				// 管理端登录身份
+				if (collect.contains(SysUserType.SYSTEM.getCode())) {
+					clientId = SysUserType.SYSTEM.getCode();
+				}
+
+				// 学校员工身份
+				if (collect.contains(SysUserType.SCHOOL.getCode())) {
+					clientId = SysUserType.SCHOOL.getCode();
+				}
+			}
+
 			//如果机构不一致,不允许跨机构注册
 			//如果机构不一致,不允许跨机构注册
 //			if(loginEntity.getTenantId() != null && loginEntity.getTenantId() != 0 &&
 //			if(loginEntity.getTenantId() != null && loginEntity.getTenantId() != 0 &&
 //					!loginEntity.getTenantId().equals(user.getTenantId())){
 //					!loginEntity.getTenantId().equals(user.getTenantId())){