| | |
| | | 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; |
| | |
| | | * @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 { |
| | |
| | | * @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"; |
| | | } |
| | | |
| | | } |