|
@@ -59,13 +59,25 @@ public class AppController {
|
|
|
|
|
|
|
|
|
@GetMapping("")
|
|
|
- public String Web(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ public String app(HttpServletRequest request, HttpServletResponse response, String ticket) {
|
|
|
+ if (appConfig.isPortalLogin && !stringUtils.IsNullOrEmpty(ticket)) {
|
|
|
+ if (portalLogin(request, response, ticket)) {
|
|
|
+ return "redirect:/app/main/index.html/#/portalLogin";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return "redirect:/app/main/index.html";
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@GetMapping("web")
|
|
|
- public String Web() {
|
|
|
+ public String web(HttpServletRequest request, HttpServletResponse response, String ticket) {
|
|
|
+ if (appConfig.isPortalLogin && !stringUtils.IsNullOrEmpty(ticket)) {
|
|
|
+ if (portalLogin(request, response, ticket)) {
|
|
|
+ return "redirect:/app/main/index.html/#/portalLogin";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return "redirect:/app/main/index.html";
|
|
|
}
|
|
|
|
|
@@ -78,4 +90,60 @@ public class AppController {
|
|
|
return "redirect:/mobile/index.html/#/index?code=" + (!stringUtils.IsNullOrEmpty(code) ? code : "");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 单点登录,验证ticket
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param ticket
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean portalLogin(HttpServletRequest request, HttpServletResponse response, String ticket) {
|
|
|
+ Boolean result = false;
|
|
|
+ try {
|
|
|
+ String validateUrl = appConfig.portal_oauthUrl + "/lyuapServer/serviceValidate";
|
|
|
+ logger.info("JXCasLogin,ticket:" + ticket);
|
|
|
+ Map<String, String> mapParams = new HashMap<>();
|
|
|
+ mapParams.put("ticket", ticket);
|
|
|
+ mapParams.put("service", appConfig.portal_webUrl);
|
|
|
+ FileInputStream streamCer = new FileInputStream(appConfig.certPath + "/lyuap.cer");
|
|
|
+ String reqData = remoteHelper.SSLGet(mapParams, validateUrl, "UTF-8", streamCer);
|
|
|
+ //String reqData="<cas:authenticationSuccess><cas:user>2001001www</cas:user><cas:attributes>...</cas:attributes></cas:authenticationSuccess>";
|
|
|
+ int i = reqData.indexOf("<cas:user>");
|
|
|
+ int j = reqData.indexOf("</cas:user>");
|
|
|
+
|
|
|
+ String userId = reqData.substring(i + "<cas:user>".length(), j);
|
|
|
+
|
|
|
+ logger.info("PortalLogin,userId:" + userId);
|
|
|
+
|
|
|
+ CfUsers User = userService.getUserByKey(userId);
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isBlank(User.getUserid())) {
|
|
|
+ User = userService.getUserByOAName(userId);
|
|
|
+ }
|
|
|
+ if (User != null && org.apache.commons.lang3.StringUtils.isNotBlank(User.getUsername())) {
|
|
|
+
|
|
|
+ Cookie cookie = new Cookie(jwtUtils.getTokenName(), jwtUtils.generateToken(User.getUserid()));
|
|
|
+ cookie.setHttpOnly(true);
|
|
|
+ cookie.setPath("/");
|
|
|
+ response.addCookie(cookie);
|
|
|
+
|
|
|
+ List<HashMap<String, Object>> roleList = this.roleService.getRoleByUserName(User.getUsername());
|
|
|
+ if (roleList == null || roleList.isEmpty()) {
|
|
|
+ this.roleService.insertUserRole(User.getUsername(), "0b45886a-a8db-4f85-af76-61a8ea7c1dab");
|
|
|
+ }
|
|
|
+ userService.loginForceStatu(User.getUserid(), 0);
|
|
|
+ logService.log("用户单点登录", User.getUserid(), "PortalLogin");
|
|
|
+
|
|
|
+ result = true;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.info("PortalLogin,单点登陆失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error("单点登陆异常:" + ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|