org.jeecg.modules.cas.util.XmlUtils Java Examples

The following examples show how to use org.jeecg.modules.cas.util.XmlUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CasClientController.java    From jeecg-cloud with Apache License 2.0 4 votes vote down vote up
@GetMapping("/validateLogin")
public Object validateLogin(@RequestParam(name="ticket") String ticket,
							@RequestParam(name="service") String service,
							HttpServletRequest request,
							HttpServletResponse response) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	log.info("Rest api login.");
	try {
		String validateUrl = prefixUrl+"/p3/serviceValidate";
		String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
		log.info("res."+res);
		final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
		if(StringUtils.isNotEmpty(error)) {
			throw new Exception(error);
		}
		final String principal = XmlUtils.getTextForElement(res, "user");
		if (StringUtils.isEmpty(principal)) {
            throw new Exception("No principal was found in the response from the CAS server.");
        }
		log.info("-------token----username---"+principal);
	    //1. 校验用户是否有效
  		SysUser sysUser = sysUserService.getUserByName(principal);
  		result = sysUserService.checkUserIsEffective(sysUser);
  		if(!result.isSuccess()) {
  			return result;
  		}
 		String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
 		// 设置超时时间
 		redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
 		redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
  		//获取用户部门信息
		JSONObject obj = new JSONObject();
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		obj.put("departs", departs);
		if (departs == null || departs.size() == 0) {
			obj.put("multi_depart", 0);
		} else if (departs.size() == 1) {
			sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
			obj.put("multi_depart", 1);
		} else {
			obj.put("multi_depart", 2);
		}
		obj.put("token", token);
		obj.put("userInfo", sysUser);
		result.setResult(obj);
		result.success("登录成功");
  		
	} catch (Exception e) {
		//e.printStackTrace();
		result.error500(e.getMessage());
	}
	return new HttpEntity<>(result);
}
 
Example #2
Source File: CasClientController.java    From jeecg-boot-with-activiti with MIT License 4 votes vote down vote up
@GetMapping("/validateLogin")
public Object validateLogin(@RequestParam(name="ticket") String ticket,
							@RequestParam(name="service") String service,
							HttpServletRequest request,
							HttpServletResponse response) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	log.info("Rest api login.");
	try {
		String validateUrl = prefixUrl+"/p3/serviceValidate";
		String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
		log.info("res."+res);
		final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
		if(StringUtils.isNotEmpty(error)) {
			throw new Exception(error);
		}
		final String principal = XmlUtils.getTextForElement(res, "user");
		if (StringUtils.isEmpty(principal)) {
            throw new Exception("No principal was found in the response from the CAS server.");
        }
		log.info("-------token----username---"+principal);
	    //1. 校验用户是否有效
  		SysUser sysUser = sysUserService.getUserByName(principal);
  		result = sysUserService.checkUserIsEffective(sysUser);
  		if(!result.isSuccess()) {
  			return result;
  		}
 		String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
 		// 设置超时时间
 		redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
 		redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
  		//获取用户部门信息
		JSONObject obj = new JSONObject();
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		obj.put("departs", departs);
		if (departs == null || departs.size() == 0) {
			obj.put("multi_depart", 0);
		} else if (departs.size() == 1) {
			sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
			obj.put("multi_depart", 1);
		} else {
			obj.put("multi_depart", 2);
		}
		obj.put("token", token);
		obj.put("userInfo", sysUser);
		result.setResult(obj);
		result.success("登录成功");
  		
	} catch (Exception e) {
		//e.printStackTrace();
		result.error500(e.getMessage());
	}
	return new HttpEntity<>(result);
}
 
Example #3
Source File: CasClientController.java    From teaching with Apache License 2.0 4 votes vote down vote up
@GetMapping("/validateLogin")
public Object validateLogin(@RequestParam(name="ticket") String ticket,
							@RequestParam(name="service") String service,
							HttpServletRequest request,
							HttpServletResponse response) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	log.info("Rest api login.");
	try {
		String validateUrl = prefixUrl+"/p3/serviceValidate";
		String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
		log.info("res."+res);
		final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
		if(StringUtils.isNotEmpty(error)) {
			throw new Exception(error);
		}
		final String principal = XmlUtils.getTextForElement(res, "user");
		if (StringUtils.isEmpty(principal)) {
            throw new Exception("No principal was found in the response from the CAS server.");
        }
		log.info("-------token----username---"+principal);
	    //1. 校验用户是否有效
  		SysUser sysUser = sysUserService.getUserByName(principal);
  		result = sysUserService.checkUserIsEffective(sysUser);
  		if(!result.isSuccess()) {
  			return result;
  		}
 		String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
 		// 设置超时时间
 		redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
 		redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
  		//获取用户部门信息
		JSONObject obj = new JSONObject();
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		obj.put("departs", departs);
		if (departs == null || departs.size() == 0) {
			obj.put("multi_depart", 0);
		} else if (departs.size() == 1) {
			sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
			obj.put("multi_depart", 1);
		} else {
			obj.put("multi_depart", 2);
		}
		obj.put("token", token);
		obj.put("userInfo", sysUser);
		result.setResult(obj);
		result.success("登录成功");
  		
	} catch (Exception e) {
		//e.printStackTrace();
		result.error500(e.getMessage());
	}
	return new HttpEntity<>(result);
}
 
Example #4
Source File: CasClientController.java    From jeecg-boot with Apache License 2.0 4 votes vote down vote up
@GetMapping("/validateLogin")
public Object validateLogin(@RequestParam(name="ticket") String ticket,
							@RequestParam(name="service") String service,
							HttpServletRequest request,
							HttpServletResponse response) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	log.info("Rest api login.");
	try {
		String validateUrl = prefixUrl+"/p3/serviceValidate";
		String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
		log.info("res."+res);
		final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
		if(StringUtils.isNotEmpty(error)) {
			throw new Exception(error);
		}
		final String principal = XmlUtils.getTextForElement(res, "user");
		if (StringUtils.isEmpty(principal)) {
            throw new Exception("No principal was found in the response from the CAS server.");
        }
		log.info("-------token----username---"+principal);
	    //1. 校验用户是否有效
  		SysUser sysUser = sysUserService.getUserByName(principal);
  		result = sysUserService.checkUserIsEffective(sysUser);
  		if(!result.isSuccess()) {
  			return result;
  		}
 		String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
 		// 设置超时时间
 		redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
 		redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
  		//获取用户部门信息
		JSONObject obj = new JSONObject();
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		obj.put("departs", departs);
		if (departs == null || departs.size() == 0) {
			obj.put("multi_depart", 0);
		} else if (departs.size() == 1) {
			sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
			obj.put("multi_depart", 1);
		} else {
			obj.put("multi_depart", 2);
		}
		obj.put("token", token);
		obj.put("userInfo", sysUser);
		result.setResult(obj);
		result.success("登录成功");
  		
	} catch (Exception e) {
		//e.printStackTrace();
		result.error500(e.getMessage());
	}
	return new HttpEntity<>(result);
}