|
@@ -23,10 +23,10 @@ import cn.com.qmth.examcloud.commons.base.util.UUID;
|
|
|
import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.Role;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.UserType;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.enums.AccountType;
|
|
|
-import cn.com.qmth.examcloud.core.basic.base.enums.UserType;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
@@ -117,6 +117,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
}
|
|
|
|
|
|
User user = new User();
|
|
|
+ Long orgId = null;
|
|
|
|
|
|
// 常规账户登录
|
|
|
if (AccountType.COMMON_LOGIN_NAME.name().equals(accountType)) {
|
|
@@ -132,11 +133,10 @@ public class AuthServiceImpl implements AuthService {
|
|
|
throw new StatusException("B-001003", "密码错误");
|
|
|
}
|
|
|
user.setUserId(userEntity.getId());
|
|
|
- user.setUserType(UserType.COMMON.getCode());
|
|
|
+ user.setUserType(UserType.COMMON);
|
|
|
user.setDisplayName(userEntity.getLoginName() + " (" + userEntity.getName() + ")");
|
|
|
user.setRootOrgId(userEntity.getRootOrgId());
|
|
|
- user.setRootOrgName(rootOrg.getName());
|
|
|
- user.setOrgId(userEntity.getOrgId());
|
|
|
+ orgId = userEntity.getOrgId();
|
|
|
|
|
|
List<Role> roleList = getUserRoles(userEntity.getId());
|
|
|
user.setRoleList(roleList);
|
|
@@ -162,14 +162,11 @@ public class AuthServiceImpl implements AuthService {
|
|
|
throw new StatusException("B-001003", "密码错误");
|
|
|
}
|
|
|
|
|
|
- user.setStudentId(student.getId());
|
|
|
- user.setUserType(UserType.STUDENT.getCode());
|
|
|
- user.setStudentCode(student.getStudentCode());
|
|
|
- user.setIdentityNumber(student.getIdentityNumber());
|
|
|
+ user.setUserId(student.getId());
|
|
|
+ user.setUserType(UserType.STUDENT);
|
|
|
user.setRootOrgId(student.getRootOrgId());
|
|
|
- user.setRootOrgName(rootOrg.getName());
|
|
|
- user.setOrgId(student.getOrgId());
|
|
|
user.setDisplayName(student.getName());
|
|
|
+ orgId = student.getOrgId();
|
|
|
|
|
|
List<Role> roleList = Lists.newArrayList();
|
|
|
Role role = new Role(8L, "STUDENT", "学生");
|
|
@@ -180,9 +177,8 @@ public class AuthServiceImpl implements AuthService {
|
|
|
user.setClientIp(loginInfo.getClientIp());
|
|
|
|
|
|
OrgEntity org = null;
|
|
|
- if (null != user.getOrgId()) {
|
|
|
- org = orgRepo.findOne(user.getOrgId());
|
|
|
- user.setOrgName(org.getName());
|
|
|
+ if (null != orgId) {
|
|
|
+ org = orgRepo.findOne(orgId);
|
|
|
}
|
|
|
|
|
|
boolean isLcUser = isLcUser(user);
|
|
@@ -197,7 +193,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
setSession(user);
|
|
|
|
|
|
if (isLcUser) {
|
|
|
- setSecurityIp(user);
|
|
|
+ setSecurityIp(user, orgId);
|
|
|
}
|
|
|
|
|
|
return user;
|
|
@@ -208,9 +204,10 @@ public class AuthServiceImpl implements AuthService {
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
* @param user
|
|
|
+ * @param orgId
|
|
|
*/
|
|
|
- private void setSecurityIp(User user) {
|
|
|
- String key = "IP_" + user.getOrgId();
|
|
|
+ private void setSecurityIp(User user, Long orgId) {
|
|
|
+ String key = "IP_" + orgId;
|
|
|
|
|
|
String clientIp = user.getClientIp();
|
|
|
if (StringUtils.isBlank(clientIp)) {
|
|
@@ -269,13 +266,9 @@ public class AuthServiceImpl implements AuthService {
|
|
|
*/
|
|
|
private String buildUserKey(User user) {
|
|
|
Long rootOrgId = user.getRootOrgId();
|
|
|
- String userType = user.getUserType();
|
|
|
- String key = null;
|
|
|
- if (UserType.COMMON.getCode().equals(userType)) {
|
|
|
- key = StringUtil.join("U_", userType, "_", rootOrgId, "_", user.getUserId());
|
|
|
- } else if (UserType.STUDENT.getCode().equals(userType)) {
|
|
|
- key = StringUtil.join("U_", userType, "_", rootOrgId, "_", user.getStudentId());
|
|
|
- }
|
|
|
+ UserType userType = user.getUserType();
|
|
|
+ String key = StringUtil.join("U_", userType.getCode(), "_", rootOrgId, "_",
|
|
|
+ user.getUserId());
|
|
|
return key;
|
|
|
}
|
|
|
|
|
@@ -348,15 +341,10 @@ public class AuthServiceImpl implements AuthService {
|
|
|
}
|
|
|
|
|
|
User user = new User();
|
|
|
+ user.setUserType(UserType.COMMON);
|
|
|
user.setUserId(userEntity.getId());
|
|
|
user.setDisplayName(userEntity.getLoginName());
|
|
|
user.setRootOrgId(userEntity.getRootOrgId());
|
|
|
- user.setRootOrgName(rootOrg.getName());
|
|
|
- user.setOrgId(userEntity.getOrgId());
|
|
|
- if (null != user.getOrgId()) {
|
|
|
- OrgEntity org = orgRepo.findOne(user.getOrgId());
|
|
|
- user.setOrgName(org.getName());
|
|
|
- }
|
|
|
|
|
|
List<Role> roleList = getUserRoles(userEntity.getId());
|
|
|
user.setRoleList(roleList);
|
|
@@ -377,7 +365,6 @@ public class AuthServiceImpl implements AuthService {
|
|
|
user.setToken(UUID.randomUUID());
|
|
|
String key = buildUserKey(user);
|
|
|
user.setKey(key);
|
|
|
- user.setUserToken(key + ":" + user.getToken());
|
|
|
|
|
|
int sessionTimeout = PropertiesUtil.getInt(PropKeys.SESSION_TIMEOUT, 3600);
|
|
|
Integer sessionTimeoutCache = redisClient.get("$_SESSION_TIMEOUT", Integer.class);
|