Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeSyncUniversalController.java
@@ -48,9 +48,7 @@ public String applyCode(@RequestParam("dataString")String dataString, @RequestParam("dataType")String dataType, HttpServletRequest request) { String result=""; try { ThreadLocal<HttpServletRequest> threadLocal = new ThreadLocal<>(); threadLocal.set(request); universalInterfaceI.setThreadLocal(threadLocal); this.setHttpToThreadLocal(request); result = universalInterfaceI.applyCode(dataString, dataType); }catch (Throwable e){ e.printStackTrace(); @@ -67,9 +65,10 @@ * @throws Throwable */ @PostMapping("/syncData") public String syncData(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType) { public String syncData(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType, HttpServletRequest request) { String result=""; try { this.setHttpToThreadLocal(request); result= universalInterfaceI.syncEditData(dataString,dataType); }catch (Throwable e){ e.printStackTrace();; @@ -86,9 +85,10 @@ * @throws Throwable */ @PostMapping("/queryClassify") public String queryClassify(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType) throws Throwable { public String queryClassify(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType, HttpServletRequest request) throws Throwable { String result=""; try { this.setHttpToThreadLocal(request); result = universalInterfaceI.queryClassify(dataString, dataType); }catch (Throwable e){ e.printStackTrace(); @@ -105,9 +105,10 @@ * @throws Throwable */ @PostMapping("/queryData") public String queryData(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType) throws Throwable { public String queryData(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType, HttpServletRequest request) throws Throwable { String result=""; try { this.setHttpToThreadLocal(request); result= universalInterfaceI.queryData(dataString,dataType); }catch (Throwable e){ e.printStackTrace(); @@ -124,9 +125,10 @@ * @throws Throwable */ @PostMapping("/queryClassifyRule") public String queryClassifyRule(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType) throws Throwable { public String queryClassifyRule(@RequestParam("dataString")String dataString,@RequestParam("dataType")String dataType, HttpServletRequest request) throws Throwable { String result=""; try { this.setHttpToThreadLocal(request); result= universalInterfaceI.queryClassifyRule(dataString,dataType); }catch (Throwable e){ e.printStackTrace(); @@ -135,4 +137,14 @@ return result; } /** * 设置request,到ThreadLocal中 * @param request */ public void setHttpToThreadLocal(HttpServletRequest request){ ThreadLocal<HttpServletRequest> threadLocal = new ThreadLocal<>(); threadLocal.set(request); universalInterfaceI.setThreadLocal(threadLocal); } } Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java
@@ -5,12 +5,17 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import static com.vci.ubcs.starter.util.AESUtils.aesDecrypt; import static com.vci.ubcs.starter.util.AESUtils.aesEncrypt; @@ -19,16 +24,21 @@ * @author ludc * @date 2023/9/12 9:07 */ @RestController @Controller @RequestMapping("/passwordFree") @Api(value = "免密登录接口", tags = "免密登录接口") @Slf4j public class PasswordFreeLoginController { // 别人调用我们的单点重定向的地址 @Value("${password-free.sso-redirect-addr}") private String ssoRedirectAddr; @Resource private IPasswordFreeLoginService passwordFreeLoginService; @PostMapping("/login") @ResponseBody public R passwordFreeLogin(@RequestParam("userName") String username, HttpServletRequest request) { boolean status; try { @@ -46,16 +56,19 @@ * @throws Exception */ @GetMapping("/ssoLogin") public ModelAndView oaSsoLogin(HttpServletRequest request, ModelAndView model){ public String oaSsoLogin(HttpServletRequest request) throws IOException { String token; try { token = passwordFreeLoginService.ssoFreeLogin(request); }catch (Exception e){ throw new ServiceException("单点登录获取token失败:"+e.getMessage()); } model.addObject("token",token); model.setViewName("sso"); return model; // response.setHeader("tokenInfo",token); // response.setCharacterEncoding("utf-8"); // response.setContentType("application/json"); request.setAttribute("tokenInfo",token); //response.sendRedirect(ssoRedirectAddr); return "forward:/sso"; } } Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java
@@ -168,10 +168,11 @@ @Override public String ssoFreeLogin(ServletRequest servletRequest) throws Exception { HttpServletRequest request = (HttpServletRequest) servletRequest; String content = request.getHeader("empCode"); if(Func.isBlank(content)){ throw new ServiceException("未获取到empCode参数"); } // String content = request.getHeader("empCode"); String content = "test"; // if(Func.isBlank(content)){ // throw new ServiceException("未获取到empCode参数"); // } //加密 String str1 = aesEncrypt(content, clientId); String str2 = aesEncrypt(str1, secretKey);