|
@@ -11,7 +11,10 @@ import org.springframework.stereotype.Service;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.ByteUtil;
|
|
import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
|
|
import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.SHA256;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.StringUtil;
|
|
import cn.com.qmth.examcloud.commons.base.util.UUID;
|
|
import cn.com.qmth.examcloud.commons.base.util.UUID;
|
|
import cn.com.qmth.examcloud.commons.web.CommonPropKeys;
|
|
import cn.com.qmth.examcloud.commons.web.CommonPropKeys;
|
|
import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
|
|
import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
|
|
@@ -23,9 +26,12 @@ 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.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.ThirdPartyAccessDao;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccess;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccessPK;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
@@ -60,6 +66,9 @@ public class AuthServiceImpl implements AuthService {
|
|
@Autowired
|
|
@Autowired
|
|
StudentRepo studentRepo;
|
|
StudentRepo studentRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ ThirdPartyAccessDao thirdPartyAccessDao;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public User login(LoginInfo loginInfo) {
|
|
public User login(LoginInfo loginInfo) {
|
|
|
|
|
|
@@ -210,4 +219,43 @@ public class AuthServiceImpl implements AuthService {
|
|
return user;
|
|
return user;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public User thirdPartyAccess(long orgId, String loginName, String appId, String timestamp,
|
|
|
|
+ String token) throws StatusException {
|
|
|
|
+ ThirdPartyAccess thirdPartyAccess = thirdPartyAccessDao
|
|
|
|
+ .findOne(new ThirdPartyAccessPK(orgId, appId));
|
|
|
|
+
|
|
|
|
+ if (null == thirdPartyAccess) {
|
|
|
|
+ throw new StatusException("B-001201", "第三方系统接入信息未配置");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ long timestampLong = 0L;
|
|
|
|
+ try {
|
|
|
|
+ timestampLong = Long.parseLong(timestamp);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new StatusException("B-001202", "timestamp错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Math.abs(System.currentTimeMillis() - timestampLong) > thirdPartyAccess
|
|
|
|
+ .getTimeRange()) {
|
|
|
|
+ throw new StatusException("B-001203", "timestamp超出时间差范围");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String secretKey = thirdPartyAccess.getSecretKey();
|
|
|
|
+ String joinStr = StringUtil.join(loginName, orgId, appId, timestamp, secretKey);
|
|
|
|
+ byte[] bytes = SHA256.encode(joinStr);
|
|
|
|
+ String hexAscii = ByteUtil.toHexAscii(bytes);
|
|
|
|
+
|
|
|
|
+ if (!hexAscii.equals(token)) {
|
|
|
|
+ throw new StatusException("B-001204", "token校验失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserEntity user = userRepo.findByRootOrgIdAndLoginName(orgId, loginName);
|
|
|
|
+ if (user == null) {
|
|
|
|
+ throw new StatusException("B-001205", "用户不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|