【fix sonar】CasClientController.java文件 CasClientController.java文件
This commit is contained in:
+9
-8
@@ -51,16 +51,17 @@ public class CasClientController {
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
|
||||
@Value("${cas.prefixUrl}")
|
||||
private String prefixUrl;
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/validateLogin")
|
||||
public Object validateLogin(@RequestParam(name="ticket") String ticket,
|
||||
@RequestParam(name="service") String service,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
String MULTI_DEPART = "multi_depart";
|
||||
Result<JSONObject> result = new Result<JSONObject>();
|
||||
log.info("Rest api login.");
|
||||
try {
|
||||
@@ -92,18 +93,18 @@ public class CasClientController {
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
obj.put("departs", departs);
|
||||
if (departs == null || departs.size() == 0) {
|
||||
obj.put("multi_depart", 0);
|
||||
obj.put(MULTI_DEPART, 0);
|
||||
} else if (departs.size() == 1) {
|
||||
sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
|
||||
obj.put("multi_depart", 1);
|
||||
obj.put(MULTI_DEPART, 1);
|
||||
} else {
|
||||
obj.put("multi_depart", 2);
|
||||
obj.put(MULTI_DEPART, 2);
|
||||
}
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", sysUser);
|
||||
result.setResult(obj);
|
||||
result.setMessage("登录成功");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
result.setSuccess(false);
|
||||
result.setMessage(e.getMessage());
|
||||
@@ -111,5 +112,5 @@ public class CasClientController {
|
||||
return new HttpEntity<>(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+8
-8
@@ -17,17 +17,17 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
public class CASServiceUtil {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String serviceUrl = "https://cas.8f8.com.cn:8443/cas/p3/serviceValidate";
|
||||
String service = "http://localhost:3003/user/login";
|
||||
String ticket = "ST-5-1g-9cNES6KXNRwq-GuRET103sm0-DESKTOP-VKLS8B3";
|
||||
String res = getSTValidate(serviceUrl,ticket, service);
|
||||
|
||||
|
||||
System.out.println("---------res-----"+res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证ST
|
||||
*/
|
||||
@@ -38,14 +38,14 @@ public class CASServiceUtil {
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
HttpResponse response = httpclient.execute(httpget);
|
||||
String res = readResponse(response);
|
||||
return res == null ? null : (res == "" ? null : res);
|
||||
return res == null ? null : ("".equals(res) ? null : res);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 读取 response body 内容为字符串
|
||||
*
|
||||
@@ -62,8 +62,8 @@ public class CASServiceUtil {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建模拟客户端(针对 https 客户端禁用 SSL 验证)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user