| | |
| | | package com.ruoyi.web.controller.sso; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | |
| | | import com.ruoyi.framework.web.service.SysLoginService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.smartor.domain.SSOTokenResponse; |
| | | import com.smartor.domain.SSOUserInfo; |
| | | import com.smartor.domain.ServiceSubtask; |
| | | import com.smartor.domain.VO.ServiceSubtaskVO; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | | import com.smartor.service.IServiceSubtaskService; |
| | | import com.smartor.service.impl.ServiceSubtaskServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.*; |
| | | import org.springframework.http.client.SimpleClientHttpRequestFactory; |
| | | |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.servlet.view.RedirectView; |
| | | import org.springframework.web.util.UriComponentsBuilder; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * SSO单点登录控制器 |
| | |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | private final RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private IServiceSubtaskService serviceSubtaskService; |
| | | |
| | | public SSOController() { |
| | | // 配置RestTemplate超时 |
| | |
| | | } |
| | | |
| | | /** |
| | | * ssoGoServiceSubtaskList |
| | | */ |
| | | @PostMapping("ssoGoServiceSubtaskList") |
| | | public RedirectView ssoGoServiceSubtaskList(@RequestBody SysUser sysUserVo) { |
| | | // 重定向地址对象(重定向地址 |
| | | RedirectView redirectView = new RedirectView(); |
| | | String path = sysConfigService.selectConfigByKey("sys.qddz"); |
| | | String userName = sysUserVo.getUserName(); |
| | | String orgid = sysUserVo.getOrgid(); |
| | | String campusid = sysUserVo.getCampusid(); |
| | | Long deptId = sysUserVo.getDeptId(); |
| | | List<String> deptCodes = sysUserVo.getDeptCodes(); |
| | | List<String> wardCodes = sysUserVo.getWardCodes(); |
| | | try { |
| | | if (StringUtils.isEmpty(path)) { |
| | | throw new BaseException("请配置前端地址"); |
| | | } |
| | | if(ObjectUtils.isEmpty(deptId)){ |
| | | SysDept sysDeptVo = new SysDept(); |
| | | sysDeptVo.setOrgid(orgid); |
| | | sysDeptVo.setCampusid(campusid); |
| | | if(CollectionUtils.isNotEmpty(deptCodes)){ |
| | | sysDeptVo.setDeptType("1"); |
| | | sysDeptVo.setDeptCodes(deptCodes); |
| | | }else { |
| | | sysDeptVo.setDeptType("2"); |
| | | sysDeptVo.setDeptCodes(wardCodes); |
| | | } |
| | | List<SysDept> sysDepts = sysDeptService.selectSysDeptList(sysDeptVo); |
| | | if(CollectionUtils.isNotEmpty(sysDepts)){ |
| | | deptId = sysDepts.get(0).getDeptId(); |
| | | } |
| | | } |
| | | String loginToken = loginService.loginByUserName(userName + "&" + orgid + "&null" + "&" + campusid); |
| | | String redirectUrl = path + "/loginSSO?token=" + loginToken + |
| | | "&orgid=" + orgid + "&campusid=" + campusid + |
| | | "&deptId=" + deptId + "&orgname=null&ZuHuID=null&deptCode=null"; |
| | | log.info("【SSO登录】重定向地址:{}", redirectUrl); |
| | | return buildRedirect(redirectUrl); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("SSO登录失败", e); |
| | | redirectView.setUrl(path + "/login?error=sso_failed"); |
| | | return redirectView; |
| | | |
| | | } |
| | | } |
| | | /** |
| | | * 构建重定向视图 |
| | | */ |
| | | private RedirectView buildRedirect(String url) { |