|
@@ -1,6 +1,8 @@
|
|
|
package com.ydd.system.service;
|
|
|
|
|
|
+import com.ydd.common.config.EnvConfig;
|
|
|
import com.ydd.common.constant.Constants;
|
|
|
+import com.ydd.common.core.domain.entity.SysUser;
|
|
|
import com.ydd.common.core.domain.model.LoginUser;
|
|
|
import com.ydd.common.core.redis.RedisCache;
|
|
|
import com.ydd.common.exception.CustomException;
|
|
@@ -10,9 +12,11 @@ import com.ydd.common.exception.user.UserNameDisableException;
|
|
|
import com.ydd.common.exception.user.UserPasswordNotMatchException;
|
|
|
import com.ydd.common.utils.MessageUtils;
|
|
|
import com.ydd.ecloud.core.enums.StatusEnum;
|
|
|
+import com.ydd.ecloud.core.utils.HttpContextUtils;
|
|
|
import com.ydd.framework.web.service.TokenService;
|
|
|
import com.ydd.system.manager.AsyncManager;
|
|
|
import com.ydd.system.manager.factory.AsyncFactory;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -21,6 +25,7 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 登录校验方法
|
|
@@ -42,6 +47,12 @@ public class SysLoginService
|
|
|
@Resource
|
|
|
private ISysUserService iSysUserService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ISysRoleService iSysRoleService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnvConfig envConfig;
|
|
|
+
|
|
|
/**
|
|
|
* 登录验证
|
|
|
*
|
|
@@ -76,6 +87,9 @@ public class SysLoginService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 登录域名校验
|
|
|
+ this.checkDomain(username);
|
|
|
+
|
|
|
// 用户验证
|
|
|
Authentication authentication = null;
|
|
|
try
|
|
@@ -102,4 +116,31 @@ public class SysLoginService
|
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|
|
|
}
|
|
|
+
|
|
|
+ private void checkDomain(String username) {
|
|
|
+ String serverName = HttpContextUtils.getHttpServletRequest().getServerName();
|
|
|
+ if (serverName != null && !serverName.contains("localhost")) {
|
|
|
+ SysUser sysUser = iSysUserService.selectUserByUserName(username);
|
|
|
+ if (sysUser != null) {
|
|
|
+ List<Integer> roleIdList = iSysRoleService.selectRoleListByUserId(sysUser.getUserId());
|
|
|
+ if (CollectionUtils.isNotEmpty(roleIdList)) {
|
|
|
+ Long roleId = Long.parseLong(roleIdList.get(0).toString());
|
|
|
+ // 外部角色
|
|
|
+ if (Constants.EXTERNAL_ROLE_IDS.contains(roleId)) {
|
|
|
+ if (!serverName.contains(Constants.getExternalDomain(envConfig.getProfiles()))) {
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, "用户不存在!"));
|
|
|
+ throw new CustomException("用户不存在!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 内部角色
|
|
|
+ if (!serverName.contains(Constants.getInSideDomain(envConfig.getProfiles()))) {
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, "用户不存在!"));
|
|
|
+ throw new CustomException("用户不存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|