| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- package cn.com.goldenwater.dcproj.controller.sso;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.dao.GwComFileDao;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.param.CountryParam;
- import cn.com.goldenwater.dcproj.param.GwComFileParam;
- import cn.com.goldenwater.dcproj.param.TacProvincePblmInfoParam;
- import cn.com.goldenwater.dcproj.param.TacProvincePblmMendInfoParam;
- import cn.com.goldenwater.dcproj.service.*;
- import cn.com.goldenwater.dcproj.utils.DateUtils;
- import cn.com.goldenwater.dcproj.utils.DecryptUtil;
- import cn.com.goldenwater.dcproj.utils.XinJiangEncryptionUtil;
- import cn.com.goldenwater.dcproj.utils.http.SsoHttpHelper;
- import cn.com.goldenwater.id.util.UuidUtil;
- import com.alibaba.fastjson.JSON;
- import com.dcxx.framework.watermanagesdk.SSOSdk;
- import com.dcxx.framework.watermanagesdk.model.ResponseMessage;
- import com.dcxx.framework.watermanagesdk.utils.EncryptHelper;
- import com.dcxx.framework.watermanagesdk.utils.JsonHelper;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiParam;
- import net.sf.json.JSONArray;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.http.HttpEntity;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.MediaType;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.client.RestTemplate;
- import scala.Int;
- import javax.servlet.http.HttpServletRequest;
- import java.net.URLEncoder;
- import java.util.*;
- /**
- * @author hanxi
- * @date 2020-07-09
- */
- @Api(value = "水管理用户单点登录", tags = "水管理用户单点登录")
- @RestController
- @RequestMapping("/sso")
- @ComponentScan(basePackages =
- {"com.dcxx.framework.watermanagesdk.config"})
- public class SsoController extends BaseController {
- @Autowired
- private SsoService ssoService;
- @Autowired
- private SsoHttpHelper ssoHttpHelper;
- @Value("${watermanage.appkey}")
- private String appkey;
- @Value("${watermanage.appsecret}")
- private String appsecret;
- @Value("${watermanage.baseurl}")
- private String baseurl;
- @Autowired
- TacAttPawpBaseService tacAttPawpBaseService;
- @Autowired
- TacProvincePblmInfoService tacProvincePblmInfoService;
- @Autowired
- GwComFileDao gwComFileDao;
- @Autowired
- TacProvincePblmMendInfoService tacProvincePblmMendInfoService;
- /**
- * @param
- * @return java.lang.String
- * @Description 验证水管平台的票据信息,返回验证得到的用户信息
- * @Date 2020/7/14
- **/
- @RequestMapping("/validateTicket")
- public BaseResponse<Object> validateTicket(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
- SSOSdk ssoSdk = new SSOSdk();
- //获取到水管平台生成的临时票据ticket
- // ticket = "ticket_abcdefg12345678_test";
- Map<String, Object> ssoUserMap = ssoSdk.validateSsoTicket(ticket);
- //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
- if (ssoUserMap != null) {
- BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateUser(ssoUserMap);
- if (bisInspAllRlationPers == null) {
- return buildFailResponse(1001, "登陆名或密码错误", "", "");
- } else {
- String uuid = UuidUtil.uuid();
- bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
- return buildSuccessResponse(bisInspAllRlationPers, uuid);
- }
- } else {
- return buildFailResponse("无法获取用户信息");
- }
- }
- /**
- * 验证青海
- *
- * @param ticket
- * @param request
- * @return
- * @throws Exception
- */
- @RequestMapping("/validateQhUser")
- public BaseResponse<Object> validateQhUser(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
- ticket = URLEncoder.encode(ticket, "UTF-8");
- Map<String, String> mapSso = DecryptUtil.decrypt(ticket);
- //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
- if (mapSso != null) {
- BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateQhUser(mapSso);
- if (bisInspAllRlationPers == null) {
- return buildFailResponse(1001, "登陆名或密码错误或用户不存在", "", "");
- } else {
- String uuid = UuidUtil.uuid();
- bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
- return buildSuccessResponse(bisInspAllRlationPers, uuid);
- }
- } else {
- return buildFailResponse("获取用户信息失败");
- }
- }
- /**
- * 新疆兵团单点登录
- */
- @RequestMapping("validateXjbtUser")
- public BaseResponse<Object> validateXjbtUser(@RequestParam(value = "ticket", required = false) String ticket, HttpServletRequest request) throws Exception {
- Map<String, String> mapSso = XinJiangEncryptionUtil.decrypt(ticket);
- //得到水管平台返回的用户信息后,业务系统可根据实际需求进行下一步处理
- if (mapSso != null) {
- BisInspAllRlationPers bisInspAllRlationPers = ssoService.validateXjbtUser(mapSso);
- if (bisInspAllRlationPers == null) {
- return buildFailResponse(1001, "登陆名、密码错误或用户不存在", "", "");
- } else {
- String uuid = UuidUtil.uuid();
- bisInspAllRlationPers = ssoService.validateTicket(bisInspAllRlationPers, uuid, request);
- return buildSuccessResponse(bisInspAllRlationPers, uuid);
- }
- } else {
- return buildFailResponse("获取用户信息失败");
- }
- }
- /**
- * @param mapData 水管平台请求的参数{
- * "sign": "4abd3329c3b811e9993d005056bf5ab4",
- * "nonce": "abcd1234",
- * "timestamp": 1566352910152,
- * "encrypt": "AES({\"userName\":\"zhangsan\",\"passWord\":\"123456\"},appSecret )"
- * }
- * @Description 未绑定用户验证信息
- **/
- // @PostMapping(value = "/loginValidate", produces = "application/json;charset=UTF-8")
- // public ResponseMessage loginValidate(@RequestBody Map<String, Object> mapData) {
- // ResponseMessage responseMessage = new ResponseMessage(0);
- //// try {
- //// Map<String, Object> responseMap = ssoService.loginValidate(mapData);
- // String sign = mapData.get("sign").toString();
- // //随机数
- // String nonce = mapData.get("nonce").toString();
- // //时间戳
- // Long timestamp = Long.valueOf(mapData.get("timestamp").toString());
- // //加密消息
- // String encrypt = mapData.get("encrypt").toString();
- // SSOSdk ssoSdk = new SSOSdk();
- // String mySign = ssoSdk.genernateLoginValidateSign(appsecret, nonce, encrypt, timestamp);
- // //验证签名正确性
- // if (!mySign.equals(sign.toLowerCase())) {
- // responseMessage.setStatus(402005);
- // responseMessage.setErrmsg("登录验证签名不正确");
- // return responseMessage;
- // }
- // BisInspAllRlationPersZj bisInspAllRlationPersZj = ssoService.loginValidate(encrypt);
- // if (bisInspAllRlationPersZj == null) {
- // responseMessage.setStatus(402001);
- // responseMessage.setErrmsg("用户不存在");
- // return responseMessage;
- // } else {
- // //本业务系统用户体系校验用户名及密码
- // BisInspAllRlationPersParam allRlationPersParam = new BisInspAllRlationPersParam();
- // allRlationPersParam.setPersName(userNamePram);
- // BisInspAllRlationPers bisInspAllRlationPers = bisInspAllRlationPersService.getBy(allRlationPersParam);
- // if (bisInspAllRlationPers == null) {
- // logger.info("未绑定用户水利监督用户数据验证信息无:");
- // responseMessage.setStatus(402001);
- // responseMessage.setErrmsg("用户不存在");
- // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
- // } else if (StringUtils.isBlank(bisInspAllRlationPers.getPwd()) && !bisInspAllRlationPers.getPwd().equals(passWordPram)) {
- // responseMessage.setStatus(402002);
- // responseMessage.setErrmsg("密码不正确");
- // logger.info("未绑定用户水利监督用户数据验证信息密码错误:");
- // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
- // }
- // LoginValidateResponse loginValidateResponse = responseUser(by);
- // responseMessage.setMessage(loginValidateResponse);
- // return JSONObject.parseObject(JSON.toJSONString(responseMessage));
- // }
- // } catch (Exception e) {
- // responseMessage.setStatus(-1);
- // responseMessage.setErrmsg("系统异常,请联系管理员");
- // return responseMessage;
- // }
- // return responseMessage;
- // }
- }
|