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