|
@@ -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())){
|