| | |
| | | * @author ludc |
| | | * @date 2023/9/12 9:07 |
| | | */ |
| | | @Controller |
| | | @RestController |
| | | @RequestMapping("/passwordFree") |
| | | @Api(value = "免密登录接口", tags = "免密登录接口") |
| | | @Slf4j |
| | |
| | | @Value("${password-free.sso-redirect-addr}") |
| | | private String ssoRedirectAddr; |
| | | |
| | | @Value("${password-free.client-id:a104c4fd2f0e4958}") |
| | | private String clientId;//应用ID |
| | | |
| | | @Value("${password-free.secret-key:9fbd170bd83eb869}") |
| | | private String secretKey;//应用秘钥 |
| | | |
| | | @Resource |
| | | private IPasswordFreeLoginService passwordFreeLoginService; |
| | | |
| | | @PostMapping("/login") |
| | | @ResponseBody |
| | | public R passwordFreeLogin(@RequestParam("userName") String username, HttpServletRequest request) { |
| | | boolean status; |
| | | try { |
| | |
| | | |
| | | /** |
| | | * 单点登录 |
| | | * @param request |
| | | * @param empCode |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @GetMapping("/ssoLogin") |
| | | public String oaSsoLogin(HttpServletRequest request,HttpServletResponse response, RedirectAttributes redirectAttributes) throws IOException, ServletException { |
| | | public String oaSsoLogin(@RequestParam("empCode") String empCode){ |
| | | String token; |
| | | try { |
| | | token = passwordFreeLoginService.ssoFreeLogin(request); |
| | | token = passwordFreeLoginService.ssoFreeLogin(empCode); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("单点登录获取token失败:"+e.getMessage()); |
| | | } |
| | | redirectAttributes.addFlashAttribute("tokenInfo",token); |
| | | return "redirect:"+ssoRedirectAddr; |
| | | return token; |
| | | } |
| | | |
| | | /** |
| | | * 单点登录 |
| | | * @param empCode |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @GetMapping("/test") |
| | | public String test(@RequestParam("empCode") String empCode){ |
| | | String enStr2; |
| | | try { |
| | | // 加密 |
| | | String pwdfree = aesEncrypt("pwdfree", secretKey); |
| | | String pwdfree2 = aesEncrypt(pwdfree, clientId); |
| | | // 解密 |
| | | String enStr1 = aesDecrypt(empCode, secretKey); |
| | | enStr2 = aesDecrypt(enStr1, clientId); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("单点登录获取token失败:"+e.getMessage()); |
| | | } |
| | | return enStr2; |
| | | } |
| | | |
| | | } |