b05c9fdfed6eeb1b10a915de9dec30d89d501e8b.svn-base 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package cn.com.goldenwater.dcproj.controller.sso;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dao.GwComFileDao;
  5. import cn.com.goldenwater.dcproj.model.*;
  6. import cn.com.goldenwater.dcproj.param.CountryParam;
  7. import cn.com.goldenwater.dcproj.param.GwComFileParam;
  8. import cn.com.goldenwater.dcproj.param.TacProvincePblmInfoParam;
  9. import cn.com.goldenwater.dcproj.param.TacProvincePblmMendInfoParam;
  10. import cn.com.goldenwater.dcproj.service.*;
  11. import cn.com.goldenwater.dcproj.utils.DateUtils;
  12. import cn.com.goldenwater.dcproj.utils.DecryptUtil;
  13. import cn.com.goldenwater.dcproj.utils.XinJiangEncryptionUtil;
  14. import cn.com.goldenwater.dcproj.utils.http.SsoHttpHelper;
  15. import cn.com.goldenwater.id.util.UuidUtil;
  16. import com.alibaba.fastjson.JSON;
  17. import com.dcxx.framework.watermanagesdk.SSOSdk;
  18. import com.dcxx.framework.watermanagesdk.model.ResponseMessage;
  19. import com.dcxx.framework.watermanagesdk.utils.EncryptHelper;
  20. import com.dcxx.framework.watermanagesdk.utils.JsonHelper;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiParam;
  23. import net.sf.json.JSONArray;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.context.annotation.ComponentScan;
  29. import org.springframework.http.HttpEntity;
  30. import org.springframework.http.HttpHeaders;
  31. import org.springframework.http.MediaType;
  32. import org.springframework.scheduling.annotation.Scheduled;
  33. import org.springframework.web.bind.annotation.*;
  34. import org.springframework.web.client.RestTemplate;
  35. import scala.Int;
  36. import javax.servlet.http.HttpServletRequest;
  37. import java.net.URLEncoder;
  38. import java.util.*;
  39. /**
  40. * @author hanxi
  41. * @date 2020-07-09
  42. */
  43. @Api(value = "水管理用户单点登录", tags = "水管理用户单点登录")
  44. @RestController
  45. @RequestMapping("/sso")
  46. @ComponentScan(basePackages =
  47. {"com.dcxx.framework.watermanagesdk.config"})
  48. public class SsoController extends BaseController {
  49. @Autowired
  50. private SsoService ssoService;
  51. @Autowired
  52. private SsoHttpHelper ssoHttpHelper;
  53. @Value("${watermanage.appkey}")
  54. private String appkey;
  55. @Value("${watermanage.appsecret}")
  56. private String appsecret;
  57. @Value("${watermanage.baseurl}")
  58. private String baseurl;
  59. @Autowired
  60. TacAttPawpBaseService tacAttPawpBaseService;
  61. @Autowired
  62. TacProvincePblmInfoService tacProvincePblmInfoService;
  63. @Autowired
  64. GwComFileDao gwComFileDao;
  65. @Autowired
  66. TacProvincePblmMendInfoService tacProvincePblmMendInfoService;
  67. /**
  68. * @param
  69. * @return java.lang.String
  70. * @Description 验证水管平台的票据信息,返回验证得到的用户信息
  71. * @Date 2020/7/14
  72. **/
  73. @RequestMapping("/validateTicket")
  74. public BaseResponse<Object> validateTicket(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
  75. SSOSdk ssoSdk = new SSOSdk();
  76. //获取到水管平台生成的临时票据ticket
  77. // ticket = "ticket_abcdefg12345678_test";
  78. Map<String, Object> ssoUserMap = ssoSdk.validateSsoTicket(ticket);
  79. //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
  80. if (ssoUserMap != null) {
  81. BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateUser(ssoUserMap);
  82. if (bisInspAllRlationPers == null) {
  83. return buildFailResponse(1001, "登陆名或密码错误", "", "");
  84. } else {
  85. String uuid = UuidUtil.uuid();
  86. bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
  87. return buildSuccessResponse(bisInspAllRlationPers, uuid);
  88. }
  89. } else {
  90. return buildFailResponse("无法获取用户信息");
  91. }
  92. }
  93. /**
  94. * 验证青海
  95. *
  96. * @param ticket
  97. * @param request
  98. * @return
  99. * @throws Exception
  100. */
  101. @RequestMapping("/validateQhUser")
  102. public BaseResponse<Object> validateQhUser(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
  103. ticket = URLEncoder.encode(ticket, "UTF-8");
  104. Map<String, String> mapSso = DecryptUtil.decrypt(ticket);
  105. //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
  106. if (mapSso != null) {
  107. BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateQhUser(mapSso);
  108. if (bisInspAllRlationPers == null) {
  109. return buildFailResponse(1001, "登陆名或密码错误或用户不存在", "", "");
  110. } else {
  111. String uuid = UuidUtil.uuid();
  112. bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
  113. return buildSuccessResponse(bisInspAllRlationPers, uuid);
  114. }
  115. } else {
  116. return buildFailResponse("获取用户信息失败");
  117. }
  118. }
  119. /**
  120. * 新疆兵团单点登录
  121. */
  122. @RequestMapping("validateXjbtUser")
  123. public BaseResponse<Object> validateXjbtUser(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
  124. Map<String, String> mapSso = XinJiangEncryptionUtil.decrypt(ticket);
  125. //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
  126. if (mapSso != null) {
  127. BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateXjbtUser(mapSso);
  128. if (bisInspAllRlationPers == null) {
  129. return buildFailResponse(1001, "登陆名、密码错误或用户不存在", "", "");
  130. } else {
  131. String uuid = UuidUtil.uuid();
  132. bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
  133. return buildSuccessResponse(bisInspAllRlationPers, uuid);
  134. }
  135. } else {
  136. return buildFailResponse("获取用户信息失败");
  137. }
  138. }
  139. /**
  140. * @param mapData 水管平台请求的参数{
  141. * "sign": "4abd3329c3b811e9993d005056bf5ab4",
  142. * "nonce": "abcd1234",
  143. * "timestamp": 1566352910152,
  144. * "encrypt": "AES({\"userName\":\"zhangsan\",\"passWord\":\"123456\"},appSecret )"
  145. * }
  146. * @Description 未绑定用户验证信息
  147. **/
  148. // @PostMapping(value = "/loginValidate", produces = "application/json;charset=UTF-8")
  149. // public ResponseMessage loginValidate(@RequestBody Map<String, Object> mapData) {
  150. // ResponseMessage responseMessage = new ResponseMessage(0);
  151. //// try {
  152. //// Map<String, Object> responseMap = ssoService.loginValidate(mapData);
  153. // String sign = mapData.get("sign").toString();
  154. // //随机数
  155. // String nonce = mapData.get("nonce").toString();
  156. // //时间戳
  157. // Long timestamp = Long.valueOf(mapData.get("timestamp").toString());
  158. // //加密消息
  159. // String encrypt = mapData.get("encrypt").toString();
  160. // SSOSdk ssoSdk = new SSOSdk();
  161. // String mySign = ssoSdk.genernateLoginValidateSign(appsecret, nonce, encrypt, timestamp);
  162. // //验证签名正确性
  163. // if (!mySign.equals(sign.toLowerCase())) {
  164. // responseMessage.setStatus(402005);
  165. // responseMessage.setErrmsg("登录验证签名不正确");
  166. // return responseMessage;
  167. // }
  168. // BisInspAllRlationPersZj bisInspAllRlationPersZj = ssoService.loginValidate(encrypt);
  169. // if (bisInspAllRlationPersZj == null) {
  170. // responseMessage.setStatus(402001);
  171. // responseMessage.setErrmsg("用户不存在");
  172. // return responseMessage;
  173. // } else {
  174. // //本业务系统用户体系校验用户名及密码
  175. // BisInspAllRlationPersParam allRlationPersParam = new BisInspAllRlationPersParam();
  176. // allRlationPersParam.setPersName(userNamePram);
  177. // BisInspAllRlationPers bisInspAllRlationPers = bisInspAllRlationPersService.getBy(allRlationPersParam);
  178. // if (bisInspAllRlationPers == null) {
  179. // logger.info("未绑定用户水利监督用户数据验证信息无:");
  180. // responseMessage.setStatus(402001);
  181. // responseMessage.setErrmsg("用户不存在");
  182. // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
  183. // } else if (StringUtils.isBlank(bisInspAllRlationPers.getPwd()) && !bisInspAllRlationPers.getPwd().equals(passWordPram)) {
  184. // responseMessage.setStatus(402002);
  185. // responseMessage.setErrmsg("密码不正确");
  186. // logger.info("未绑定用户水利监督用户数据验证信息密码错误:");
  187. // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
  188. // }
  189. // LoginValidateResponse loginValidateResponse = responseUser(by);
  190. // responseMessage.setMessage(loginValidateResponse);
  191. // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
  192. // }
  193. // } catch (Exception e) {
  194. // responseMessage.setStatus(-1);
  195. // responseMessage.setErrmsg("系统异常,请联系管理员");
  196. // return responseMessage;
  197. // }
  198. // return responseMessage;
  199. // }
  200. }