wangwei пре 5 година
родитељ
комит
886be6c887

+ 44 - 1
src/main/java/cn/com/qmth/examcloud/bridge/modules/swjtu/controller/SwjtuController.java

@@ -1,7 +1,11 @@
 package cn.com.qmth.examcloud.bridge.modules.swjtu.controller;
 
+import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.google.common.collect.Maps;
 
+import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamScoreDataCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ScoreDataBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.request.GetFinalScoreDataReq;
@@ -30,12 +35,32 @@ public class SwjtuController {
 	ExamScoreDataCloudService examScoreDataCloudService;
 
 	@PostMapping("getScore")
-	public ResponseEntity<?> getScore(@RequestParam String studentCode,
+	public ResponseEntity<?> getScore(HttpServletRequest request, @RequestParam String studentCode,
 			@RequestParam(required = false) Long examId, @RequestParam String subjectCode,
 			@RequestParam(required = false, defaultValue = "true") boolean encrypt,
 			@RequestParam(required = false, defaultValue = "false") boolean detail) {
 
+		String authInfo = request.getHeader("auth-info");
+		Map<String, String> infoMap = buildInfoMap(authInfo);
+		String loginname = infoMap.get("loginname");
+		String password = infoMap.get("password");
+
 		Long rootOrgId = PropertyHolder.getLong("swjtu.rootOrgId", 0);
+		String loginnameConf = PropertyHolder.getString("swjtu.loginname");
+		String passwordConf = PropertyHolder.getString("swjtu.password");
+
+		if (StringUtils.isBlank(loginnameConf)) {
+			throw new StatusException("001001", "loginname is not configured");
+		}
+		if (StringUtils.isBlank(passwordConf)) {
+			throw new StatusException("001001", "password is not configured");
+		}
+
+		if (loginnameConf.equals(loginname) && passwordConf.equals(password)) {
+
+			ResponseEntity<?> entity = ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
+			return entity;
+		}
 
 		Map<String, Object> map = Maps.newHashMap();
 
@@ -68,4 +93,22 @@ public class SwjtuController {
 		return entity;
 	}
 
+	private static final String ENTRY_SPLITE = ";";
+
+	private static final String KV_SPLITE = "=";
+
+	private Map<String, String> buildInfoMap(String infoString) {
+		Map<String, String> infoMap = new HashMap<String, String>();
+		String[] values = StringUtils.split(infoString, ENTRY_SPLITE);
+		if (values != null && values.length > 0) {
+			for (String value : values) {
+				String[] pair = StringUtils.split(value, KV_SPLITE);
+				if (pair != null && pair.length == 2) {
+					infoMap.put(pair[0].trim(), pair[1].trim());
+				}
+			}
+		}
+		return infoMap;
+	}
+
 }