|
@@ -7,7 +7,8 @@ import com.ghsc.partybuild.service.RoleService;
|
|
import com.ghsc.partybuild.service.UserService;
|
|
import com.ghsc.partybuild.service.UserService;
|
|
import com.ghsc.partybuild.shiro.JwtUtils;
|
|
import com.ghsc.partybuild.shiro.JwtUtils;
|
|
import com.ghsc.partybuild.util.RemoteHelper;
|
|
import com.ghsc.partybuild.util.RemoteHelper;
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
+import com.ghsc.partybuild.util.StringUtils;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,11 +21,13 @@ import javax.servlet.http.Cookie;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
@Controller
|
|
@Controller
|
|
@RequestMapping(value = "/")
|
|
@RequestMapping(value = "/")
|
|
public class AppController {
|
|
public class AppController {
|
|
@@ -47,14 +50,13 @@ public class AppController {
|
|
@Autowired
|
|
@Autowired
|
|
RemoteHelper remoteHelper;
|
|
RemoteHelper remoteHelper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private StringUtils stringUtils;
|
|
|
|
+
|
|
public AppController() {
|
|
public AppController() {
|
|
logger = LoggerFactory.getLogger(this.getClass());
|
|
logger = LoggerFactory.getLogger(this.getClass());
|
|
}
|
|
}
|
|
|
|
|
|
- @GetMapping("mobile")
|
|
|
|
- public String Wechat(){
|
|
|
|
- return "redirect:/mobile/index.html";
|
|
|
|
- }
|
|
|
|
|
|
|
|
@GetMapping("")
|
|
@GetMapping("")
|
|
public String Web(HttpServletRequest request, HttpServletResponse response) {
|
|
public String Web(HttpServletRequest request, HttpServletResponse response) {
|
|
@@ -62,132 +64,18 @@ public class AppController {
|
|
return "redirect:/app/main/index.html";
|
|
return "redirect:/app/main/index.html";
|
|
}
|
|
}
|
|
|
|
|
|
- @GetMapping("jxCasLogin")
|
|
|
|
- public String JXCasLogin(HttpServletRequest request, HttpServletResponse response,@RequestParam(required=false)String ticket) {
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
-
|
|
|
|
- String casUrlParam=URLEncoder.encode(appConfig.jxLocationUrl,"UTF-8");
|
|
|
|
-
|
|
|
|
- if (StringUtils.isBlank(ticket)) {
|
|
|
|
- //lyuapSever
|
|
|
|
- String casLoginUrl = "redirect:" + appConfig.jxCasUrl + "/lyuapServer/login?service=" + casUrlParam;
|
|
|
|
- logger.info("JXCasLogin,casLoginUrl:" + casLoginUrl);
|
|
|
|
- return casLoginUrl;
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- String validateUrl=appConfig.jxCasUrl+"/lyuapServer/serviceValidate";
|
|
|
|
- logger.info("JXCasLogin,ticket:" + ticket);
|
|
|
|
- Map<String,String> mapParams=new HashMap<>();
|
|
|
|
- mapParams.put("ticket",ticket);
|
|
|
|
- mapParams.put("service",appConfig.jxLocationUrl);
|
|
|
|
- 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("JXCasLogin,userId:" + userId);
|
|
|
|
-
|
|
|
|
- CfUsers User=userService.getUserByKey(userId);
|
|
|
|
- if(StringUtils.isBlank(User.getUserid())) {
|
|
|
|
- User = userService.getUserByOAName(userId);
|
|
|
|
- }
|
|
|
|
- if (User != null && 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(), "login");
|
|
|
|
- return "redirect:/app/main/index.html";
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- logger.info("JXCasLogin,单点登陆失败!");
|
|
|
|
- return "redirect:/app/main/index.html";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }catch (Exception ex){
|
|
|
|
-
|
|
|
|
- return "单点验证错误:"+ex.getMessage();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //return "redirect:/app/main/index.html";
|
|
|
|
|
|
+ @GetMapping("web")
|
|
|
|
+ public String Web() {
|
|
|
|
+ return "redirect:/mobile/index.html";
|
|
}
|
|
}
|
|
- /*
|
|
|
|
- @GetMapping("KongLogin")
|
|
|
|
- public String KongLogin(HttpServletRequest request, HttpServletResponse response){
|
|
|
|
- String jstoken = request.getHeader("Kong-Access-Token");
|
|
|
|
- String errToken = request.getHeader("Kong-Access-Token-Error");
|
|
|
|
-
|
|
|
|
- response.addHeader("Pragma", "no-cache");
|
|
|
|
- response.addHeader("Cache-Control", "no-cache");
|
|
|
|
-
|
|
|
|
- if(StringUtils.isNotBlank(jstoken)) {
|
|
|
|
- try {
|
|
|
|
- int firstPeriod = jstoken.indexOf('.');
|
|
|
|
- int lastPeriod = jstoken.lastIndexOf('.');
|
|
|
|
- jstoken = jstoken.substring(firstPeriod + 1, lastPeriod);
|
|
|
|
- if (firstPeriod > 0 && lastPeriod > firstPeriod) {
|
|
|
|
- String tokenDecode = Charset.forName("UTF-8").decode(ByteBuffer.wrap
|
|
|
|
- (Base64.getUrlDecoder().decode(jstoken))).toString();
|
|
|
|
- logger.info("KongLogin,tekenDecode:" + tokenDecode);
|
|
|
|
- JsonNode result = JsonMapper.GetJsonNode(tokenDecode);
|
|
|
|
-
|
|
|
|
- CfUsers User = userService.getUserByOAName(result.get("user_name").asText());
|
|
|
|
-
|
|
|
|
- if (StringUtils.isBlank(User.getUsername())) {
|
|
|
|
- User = userService.getUserByMobile(result.get("mobile").asText());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (User != null && 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(), "login");
|
|
|
|
- return "redirect:/app/main/index.html";
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- return "无该用户";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (Exception ex) {
|
|
|
|
-
|
|
|
|
- logger.error("KongLogin", ex);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(StringUtils.isNotBlank(errToken)){
|
|
|
|
- String tokenDecode = Charset.forName("UTF-8").decode(ByteBuffer.wrap
|
|
|
|
- (Base64.getUrlDecoder().decode(errToken))).toString();
|
|
|
|
-
|
|
|
|
- return tokenDecode;
|
|
|
|
- }
|
|
|
|
|
|
+ @GetMapping("mobile")
|
|
|
|
+ public String mobile(String routePath, String code) throws UnsupportedEncodingException {
|
|
|
|
+ log.info("mobile:routePath=" + routePath + ",code=" + code);
|
|
|
|
+ if (!stringUtils.IsNullOrEmpty(routePath))
|
|
|
|
+ return "redirect:/mobile/index.html/#/index?routePath=" + URLEncoder.encode(routePath, "UTF-8") + "&code=" + code;
|
|
|
|
|
|
- return "redirect:/app/main/index.html";
|
|
|
|
|
|
+ return "redirect:/mobile/index.html/#/index?code=" + (!stringUtils.IsNullOrEmpty(code) ? code : "");
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
+
|
|
}
|
|
}
|