| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.annotation.IpWhitelist; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginBody; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.RSAPublicKeyExample; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.view.RedirectView; |
| | | |
| | | import javax.annotation.security.PermitAll; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.net.URI; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 单点登录方法 |
| | | * 单点登录方法(需要配置IP白名单) |
| | | * 需要在sys_config表的sys.ip.whitelis中,加入IP才能访问该方法 |
| | | * |
| | | * @param loginBody 单点登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @PostMapping("/SSOLogin") |
| | | public AjaxResult SSOLogin(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | @IpWhitelist |
| | | @GetMapping("/SSOLogin") |
| | | public RedirectView SSOLogin(@RequestParam String userName, @RequestParam String orgid, @RequestParam(required = false) String deptId) { |
| | | RedirectView redirectView = new RedirectView(); |
| | | // 生成令牌 |
| | | if (StringUtils.isEmpty(loginBody.getUsername()) || StringUtils.isEmpty(loginBody.getOrgid())) { |
| | | return AjaxResult.error("用户名或组织机构或部门不能为空"); |
| | | if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(orgid)) { |
| | | throw new BaseException("用户名或组织机构或部门不能为空"); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(loginBody.getDeptId())) { |
| | | loginBody.setDeptId(null); |
| | | } |
| | | String userName = loginBody.getUsername(); |
| | | if (isEncryp == 1) { |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | userName = rsaPublicKeyExample.decryptedData(loginBody.getUsername(), pri_key); |
| | | userName = rsaPublicKeyExample.decryptedData(userName, pri_key); |
| | | } |
| | | String token = loginService.loginByUserName(userName + "&" + loginBody.getOrgid() + "&" + loginBody.getDeptId()); |
| | | String token = loginService.loginByUserName(userName + "&" + orgid + "&" + deptId); |
| | | if (StringUtils.isEmpty(token)) { |
| | | return AjaxResult.error("登陆失败"); |
| | | throw new BaseException("登陆失败"); |
| | | } |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | redirectView.setUrl("http://127.0.0.1:8091/loginSSO?token=" + token + "&orgid=" + orgid + "&orgname=''" + "&ZuHuID=''&deptCode=''&redirect=''"); |
| | | redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY); |
| | | return redirectView; |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getToken") |
| | | public void getToken(HttpServletResponse response) throws IOException { |
| | | // 生成或获取token |