sso 单点登陆 客户端 登录

 

 

 

	/*
	 * 用于处理通过开放平台登陆请求
	 * */
	@RequestMapping("/ssologin")
	public String ssologin(ModelMap modelMap, HttpServletRequest request) throws Exception{
		LoginSituation loginSituation = LoginSituation.Failure;

		//从数据中的配置表,获取SSO服务器地址
		String ssoURL = sysConfigService.getSsoDomainName();
		String uId = request.getParameter("uId");
		String uName = request.getParameter("uName");
		String token = request.getParameter("token");

		if(uId == null || uName == null || token == null){
			System.out.println("SSO用户信息有误!");
			return "/ssoerror/error_userinfo";
		}	
		JSONObject jo = new JSONObject();
		jo.put("uId", uId);
		jo.put("uName", uName);
		jo.put("token", token);
		System.out.println("jsonObject:" + jo);
		String postXML = jo.toString();
		
		//向SSO服务器发送请求
		String result = HttpPostUtil.post(postXML, ssoURL);
		if(result == null || result.trim().equals("")){
			return "/ssoerror/error_disconnect";
		}
		//从SSO服务器返回的响应消息获取“resultCode”字段
		JSONObject jo2 = JSONObject.fromObject(result);
		String resultCode = jo2.getString("resultCode");
		System.out.println("resultCode=" + resultCode);
		if(resultCode !=null && "200".equals(resultCode.trim())){
			//封装sso单点登陆用户信息
			LoginInfo loginInfo = new LoginInfo();
//			uName += "@open"; //在SSO用户名后加“@open”以区分是本地用户还是SSO用户
			loginInfo.setLoginName(uName);
			loginInfo.setPassword(uName);//密码默认与用户名相同
			//验证sso单点登陆用户信息
			loginSituation = loginService.userSsologin(loginInfo, modelMap, request);
			request.getSession().setAttribute("loginSituation", loginSituation);
		}
		//SSO验证失败
		else if(resultCode !=null && "400".equals(resultCode.trim())){
			System.out.println("验证失败!");
//			loginSituation = LoginSituation.Failure;
			return "/ssoerror/error_validation";
		}		
		//返回验证通过的页面
		return getViewByLoginSituation(loginSituation);
//		return loginSituation.getIntCode();
	}

 

你可能感兴趣的:(SSO,登录,客户端,单点登陆)