| | |
| | | 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 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单点登录控制器 |
| | |
| | | private ISysConfigService sysConfigService; |
| | | |
| | | private final RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private IServiceSubtaskService serviceSubtaskService; |
| | | |
| | | public SSOController() { |
| | | // 配置RestTemplate超时 |
| | |
| | | @GetMapping("ssoGoServiceSubtaskList") |
| | | public RedirectView ssoGoServiceSubtaskList(@RequestParam(value = "code", required = false) String code, |
| | | @RequestParam(value = "sfzh", required = false) String sfzh) { |
| | | // 重定向地址对象(重定向地址 |
| | | RedirectView redirectView = new RedirectView(); |
| | | |
| | | log.info("收到ssoGoServiceSubtaskList请求,开始重定向到授权服务器,code = {}, sfzh = {}",code, sfzh); |
| | | String path = sysConfigService.selectConfigByKey("sys.qddz"); |
| | | String redirectUri = "https://9.208.2.190:8092/prod-api/sso/ssoLoginLyra"; |
| | |
| | | String clientSecret = "suifangxt"; |
| | | String scope = "openid"; |
| | | |
| | | ServiceSubtaskEntity subtask = new ServiceSubtaskEntity(); |
| | | subtask.setSfzh(sfzh); |
| | | subtask.setSort(0); |
| | | List<ServiceSubtask> serviceSubtaskList = serviceSubtaskService.selectServiceSubtaskList(subtask); |
| | | ServiceSubtask serviceSubtask = null; |
| | | if(CollectionUtils.isNotEmpty(serviceSubtaskList)){ |
| | | serviceSubtask = serviceSubtaskList.get(0); |
| | | }else { |
| | | redirectView.setUrl(path + "/login?error=sso_failed"); |
| | | return redirectView; |
| | | } |
| | | |
| | | // String authorizeUrl = lyraPath + "/mediinfo-lyra-authserver/connect/authorize"; |
| | | String accessTokenUrl = lyraPath + "/mediinfo-lyra-authserver/connect/token"; |
| | | String userInfoUrl = lyraPath + "/mediinfo-lyra-authserver/connect/userinfo"; |
| | | // 重定向地址对象(重定向地址 |
| | | RedirectView redirectView = new RedirectView(); |
| | | try { |
| | | SSOTokenResponse accessToken = getAccessTokenLyra(code, accessTokenUrl, clientId, clientSecret, redirectUri,true); |
| | | log.info("获取到的token:" + accessToken); |
| | |
| | | return buildRedirect(path + "/login"); |
| | | } |
| | | |
| | | String redirectUrl = path + "/loginSSO?token=" + loginToken + "&orgid=" + orgid + |
| | | "&sfzh=" + sfzh + "&orgname=null&ZuHuID=null&deptCode=null"; |
| | | String voiceType = (StringUtils.isNotEmpty(serviceSubtask.getType()) |
| | | && serviceSubtask.getType().equals("1")) ? "1" : "0"; |
| | | String redirectUrl = path + "/loginSSO?token=" + loginToken + |
| | | "&orgid=" + orgid + "&campusid=" + serviceSubtask.getCampusid() + |
| | | "&taskid=" + serviceSubtask.getTaskid() + "&patid=" + serviceSubtask.getPatid() + |
| | | "&id=" + serviceSubtask.getId() + "&voiceType=" + voiceType + |
| | | "&visitCount=" + serviceSubtask.getVisitCount() + "&sfzh=" + sfzh + |
| | | "&orgname=null&ZuHuID=null&deptCode=null"; |
| | | log.info("【SSO登录】重定向地址:{}", redirectUrl); |
| | | return buildRedirect(redirectUrl); |
| | | |