| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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.model.BisInspAllRlationPers;
- import cn.com.goldenwater.dcproj.service.HblxCasService;
- import cn.com.goldenwater.dcproj.service.SdTCasService;
- import cn.com.goldenwater.dcproj.utils.HttpClientUtils;
- import cn.com.goldenwater.id.util.UuidUtil;
- import com.alibaba.fastjson.JSON;
- import io.swagger.annotations.Api;
- import net.sf.json.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import java.util.HashMap;
- import java.util.Map;
- @Api(value = "山东单点登录", tags = "山东单点登录")
- @RestController
- @RequestMapping("/cas/hblx")
- public class HbLanXinCasController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Value("${hblx.auth.baseurl}")
- private String hbLxBaseUrl;
- @Value("${hblx.auth.client_appid}")
- private String hbLxClientAppid;
- @Value("${hblx.auth.client_screct}")
- private String hbLxClientScrect;
- @Autowired
- HblxCasService hblxCasService;
- @RequestMapping(value = "/validateTicketKey1", method = RequestMethod.GET)
- public BaseResponse<Object> code(@RequestParam(value = "code", required = false) String code,HttpServletRequest request) throws Exception {
- //获取应用访问token
- Map<String, String> headerParams = new HashMap<>();
- headerParams.put("", "");
- Map<String, String> params = new HashMap<>();
- params.put("grant_type", "client_credential");
- params.put("appid", hbLxClientAppid);
- params.put("secret", hbLxClientScrect);
- String ret = HttpClientUtils.simpleGetInvoke(hbLxBaseUrl + "/v1/apptoken/create", params);
- logger.info("sessionId ret-------------------------" + ret + "-------------------------");
- String appToken = JSONObject.fromObject(JSONObject.fromObject(ret).get("data")).get("appToken").toString();
- //获取人员访问token
- Map<String, String> headerParams_1 = new HashMap<>();
- headerParams_1.put("", "");
- Map<String, String> params_1 = new HashMap<>();
- params_1.put("app_token", appToken);
- params_1.put("grant_type", "authorization_code");
- params_1.put("code", code);
- String ret1 = HttpClientUtils.simpleGetInvoke(hbLxBaseUrl + "/v1/usertoken/create", params_1);
- logger.info("sessionId ret-------------------------" + ret1 + "-------------------------");
- String userToken = JSONObject.fromObject(JSONObject.fromObject(ret1).get("data")).get("userToken").toString();
- String staffId = JSONObject.fromObject(JSONObject.fromObject(ret1).get("data")).get("staffId").toString();
- //根据token获取用户信息
- Map<String, String> tokenParam = new HashMap<>();
- tokenParam.put("app_token", appToken);
- String user = HttpClientUtils.simpleGetInvoke(hbLxBaseUrl + "/v1/staffs/"+staffId+"/infor/fetch", tokenParam);
- logger.info("-----------------------------get user " + user + "-----------------------------");
- String userInfo = JSONObject.fromObject(user).get("data").toString();
- Map<String, Object> ssoUserMap = jsonToMap(userInfo);
- logger.info("---------------sso login-------------------------------");
- if (ssoUserMap != null) {
- logger.info("---------------sso user not null -------------------------------");
- ssoUserMap.put("staffId",staffId);
- BisInspAllRlationPers bisInspAllRlationPers = hblxCasService.validateUser(ssoUserMap);
- if (bisInspAllRlationPers == null) {
- return buildFailResponse(1001, "登陆名或密码错误", "", "");
- } else {
- logger.info("---------------sso user null -------------------------------");
- String uuid = UuidUtil.uuid();
- bisInspAllRlationPers = hblxCasService.validateTicket(bisInspAllRlationPers, uuid, request);
- logger.info("---------------sso add -------------------------------");
- return buildSuccessResponse(bisInspAllRlationPers, uuid);
- }
- } else {
- logger.info("---------------sso no user -------------------------------");
- return buildFailResponse("无法获取用户信息");
- }
- }
- public Map<String, Object> jsonToMap(String json) {
- Map<String, Object> map = new HashMap<>();
- map = JSON.parseObject(JSON.parse(json).toString(), HashMap.class);
- return map;
- }
- }
|