|
@@ -883,10 +883,9 @@ public class ExamServiceImpl implements ExamService {
|
|
public boolean getIpLimited(String realIp, Long examId, User accessUser) {
|
|
public boolean getIpLimited(String realIp, Long examId, User accessUser) {
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
DynamicEnum ipLimit = manager.getByName("IP_LIMIT");
|
|
DynamicEnum ipLimit = manager.getByName("IP_LIMIT");
|
|
|
|
+
|
|
//是否开启Ip限制
|
|
//是否开启Ip限制
|
|
Boolean ipLimited = getExamLimitProperty(examId, ipLimit.getId(), false);
|
|
Boolean ipLimited = getExamLimitProperty(examId, ipLimit.getId(), false);
|
|
-
|
|
|
|
-
|
|
|
|
if (ipLimited) {
|
|
if (ipLimited) {
|
|
//整体控制
|
|
//整体控制
|
|
DynamicEnum ipTotalLimit = manager.getByName("IP_TOTAL_LIMIT");
|
|
DynamicEnum ipTotalLimit = manager.getByName("IP_TOTAL_LIMIT");
|
|
@@ -894,46 +893,58 @@ public class ExamServiceImpl implements ExamService {
|
|
if (totalLimit) {
|
|
if (totalLimit) {
|
|
//在白名单中
|
|
//在白名单中
|
|
int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(),realIp);
|
|
int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(),realIp);
|
|
- if (count>0) {
|
|
|
|
- //学习中心访问控制
|
|
|
|
- DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
|
|
- Boolean centerLimit = getExamLimitProperty(examId,ipCenterLimit.getId(), false);
|
|
|
|
- if (centerLimit) {
|
|
|
|
- StudentCacheBean studentCache = CacheHelper.getStudent(accessUser.getUserId());
|
|
|
|
- Long orgId = studentCache.getOrgId();
|
|
|
|
- String key = "IP_" + orgId;
|
|
|
|
- String value = redisClient.get(key, String.class);
|
|
|
|
- //机构是否在时间范围内登陆过
|
|
|
|
- if (value != null) {
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- Set<String> userKeyList = JsonUtil.fromJson(value, Set.class);
|
|
|
|
-
|
|
|
|
- for (String userKey : userKeyList) {
|
|
|
|
- User curUser = redisClient.get(userKey, User.class);
|
|
|
|
- if (null != curUser) {
|
|
|
|
- String clientIp = curUser.getClientIp();
|
|
|
|
- if (null != clientIp) {
|
|
|
|
- // IP取前三段
|
|
|
|
- clientIp = clientIp.substring(0, clientIp.lastIndexOf(".") + 1);
|
|
|
|
- if (!realIp.startsWith(clientIp)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //在黑名单中
|
|
|
|
+ int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
|
+ if (count > 0){
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
|
|
+ //学习中心访问控制
|
|
|
|
+ DynamicEnum ipCenterLimit = manager.getByName("IP_CENTER_LIMIT");
|
|
|
|
+ Boolean centerLimit = getExamLimitProperty(examId,ipCenterLimit.getId(), false);
|
|
|
|
+ if (centerLimit) {
|
|
|
|
+ StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
|
|
|
|
+ Long orgId = studentCache.getOrgId();
|
|
|
|
+ String key = "IP_" + orgId;
|
|
|
|
+ String value = redisClient.get(key, String.class);
|
|
|
|
+ //机构是否在时间范围内登陆过
|
|
|
|
+ if (value != null) {
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ Set<String> userKeyList = JsonUtil.fromJson(value, Set.class);
|
|
|
|
+
|
|
|
|
+ for (String userKey : userKeyList) {
|
|
|
|
+ User curUser = redisClient.get(userKey, User.class);
|
|
|
|
+ if (null != curUser) {
|
|
|
|
+ String clientIp = curUser.getClientIp();
|
|
|
|
+ if (null != clientIp) {
|
|
|
|
+ // IP取前三段
|
|
|
|
+ clientIp = clientIp.substring(0, clientIp.lastIndexOf(".") + 1);
|
|
|
|
+ if (!realIp.startsWith(clientIp)) {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- //不在黑名单中
|
|
|
|
- int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId,IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
|
- return count > 0;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|