|
|
@@ -1,6 +1,9 @@
|
|
|
package com.uas.platform.b2c.common.account.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.account.entity.UserSpace;
|
|
|
+import com.uas.account.entity.UserSpaceDetail;
|
|
|
+import com.uas.account.entity.UserView;
|
|
|
import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserLoginTimeDao;
|
|
|
@@ -10,6 +13,7 @@ import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.account.model.UserLoginTime;
|
|
|
import com.uas.platform.b2c.common.account.service.SigninLogService;
|
|
|
import com.uas.platform.b2c.common.account.service.UserService;
|
|
|
+import com.uas.platform.b2c.common.account.support.LocalSSOHelp;
|
|
|
import com.uas.platform.b2c.common.account.v2.service.EnterpriseService;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.core.util.AgentUtils;
|
|
|
@@ -63,12 +67,19 @@ public class SecurityController {
|
|
|
@Autowired
|
|
|
private EnterpriseService enterpriseService;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private EnterpriseDao enterpriseDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private LocalSSOHelp localSSOServicImpl;
|
|
|
+
|
|
|
@Autowired
|
|
|
private UserDao userDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private LocalSSOHelp localSSOHelp;
|
|
|
|
|
|
|
|
|
private final DeviceResolver deviceResolver = new LiteDeviceResolver();
|
|
|
@@ -130,7 +141,7 @@ public class SecurityController {
|
|
|
redirectUrl = request.getContextPath() + "/login/proxy";
|
|
|
}*/
|
|
|
ModelMap map = new ModelMap("content", redirectUrl);
|
|
|
- map.put("baseUrl","/login/other");
|
|
|
+ map.put("baseUrl","/newLogin/other");
|
|
|
return map;
|
|
|
}
|
|
|
/**
|
|
|
@@ -236,6 +247,24 @@ public class SecurityController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @Description: 设置实名认证;
|
|
|
+ * @author pengzh
|
|
|
+ * @date 2018/3/12 16:43
|
|
|
+ * @param request, response, returnUrl
|
|
|
+ * @return org.springframework.ui.ModelMap
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/realNameAuth/page")
|
|
|
+ @ResponseBody
|
|
|
+ public ModelMap RealNameAuth(HttpServletRequest request, HttpServletResponse response, String returnUrl) throws IOException {
|
|
|
+ request.getSession().setAttribute(SSOConfig.SSOReferer, returnUrl );
|
|
|
+ String realNameAuthUrl = localSSOHelp.getRealNameAuthUrl(request,returnUrl);
|
|
|
+ return new ModelMap("content", realNameAuthUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取跨域登录的参数
|
|
|
*
|
|
|
@@ -319,7 +348,7 @@ public class SecurityController {
|
|
|
* @param request
|
|
|
* @param response
|
|
|
*/
|
|
|
- @RequestMapping(value = "/login/other")
|
|
|
+ @RequestMapping(value = "/newLogin/other")
|
|
|
@ResponseBody
|
|
|
public String afterCrossLogin(HttpServletRequest request, HttpServletResponse response, UserAccount userAccount, Integer maxage) {
|
|
|
String callback =request.getParameter("jsoncallback");
|
|
|
@@ -352,6 +381,46 @@ public class SecurityController {
|
|
|
return "successCallback({success:'0'})";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 其他地点登录后 同步登录状态
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/login/other")
|
|
|
+ @ResponseBody
|
|
|
+ public String afterCrossOldLogin(HttpServletRequest request, HttpServletResponse response, UserView userView, Integer maxage) {
|
|
|
+ String callback =request.getParameter("jsoncallback");
|
|
|
+ response.setContentType("text/html;charset=UTF-8");
|
|
|
+ if (userView != null && userView.getUid() != null) {
|
|
|
+ SSOToken tk = new SSOToken();
|
|
|
+ tk.setUid(userView.getUid());
|
|
|
+ tk.setTime(System.currentTimeMillis());
|
|
|
+ tk.setData(JSON.toJSONString(userView));
|
|
|
+ if (null != maxage) {
|
|
|
+ request.setAttribute("sso_cookie_maxage", maxage);
|
|
|
+ }
|
|
|
+ SSOHelper.setSSOCookie(request, response, tk, true);
|
|
|
+ response.setHeader("P3P","CP='IDCDSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'");
|
|
|
+
|
|
|
+ response.setHeader("P3P","CP=\"CURaADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSPCOR\"");
|
|
|
+ User user = getOldUserByToken(tk);
|
|
|
+ if (user != null) {
|
|
|
+ if (!user.getUserPwd().equals(FlexJsonUtils.fromJson(tk.getData(), com.uas.account.entity.User.class).getPassword())){
|
|
|
+ return "successCallback({success:'0'})";
|
|
|
+ }
|
|
|
+ user.setIp(AgentUtils.getIp(request));
|
|
|
+ request.getSession().setAttribute("user", user);
|
|
|
+ SystemSession.setUser(user);
|
|
|
+ log(request, user);
|
|
|
+ }
|
|
|
+
|
|
|
+ return "successCallback({success:'1'})";
|
|
|
+ }
|
|
|
+ return "successCallback({success:'0'})";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取跨域登录的参数
|
|
|
*
|
|
|
@@ -385,6 +454,7 @@ public class SecurityController {
|
|
|
private User getUserByToken(SSOToken token) {
|
|
|
User authedUser = null;
|
|
|
if (token.getData() != null) {
|
|
|
+ //com.uas.account.entity.User
|
|
|
UserAccount tokenUser = FlexJsonUtils.fromJson(token.getData(), UserAccount.class);
|
|
|
if (tokenUser.getMobile() != null) {
|
|
|
// UID表示所有系统公认的唯一标识,这里统一使用手机号
|
|
|
@@ -450,6 +520,78 @@ public class SecurityController {
|
|
|
return authedUser;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private User getOldUserByToken(SSOToken token) {
|
|
|
+ User authedUser = null;
|
|
|
+ if (token.getData() != null) {
|
|
|
+ com.uas.account.entity.User tokenUser = FlexJsonUtils.fromJson(token.getData(), com.uas.account.entity.User.class);
|
|
|
+ if (tokenUser.getUid() != null) {
|
|
|
+ // UID表示所有系统公认的唯一标识,这里统一使用手机号
|
|
|
+ authedUser = userService.findUserByUserTel(tokenUser.getUid());
|
|
|
+ } else if (tokenUser.getDialectUID() != null) {
|
|
|
+ // dialectUID表示client系统自己的唯一标识,比如user_uu,手机号没设置的情况下使用
|
|
|
+ authedUser = userService.findUserByUserUU(Long.parseLong(tokenUser.getDialectUID()));
|
|
|
+ } else {
|
|
|
+ logger.error(String.format("invalid user %s, please set uid or dialectUID", tokenUser.getName()));
|
|
|
+ }
|
|
|
+ if (authedUser != null && authedUser.getEnterprises() != null) {
|
|
|
+ // 企业资料在client系统自己的唯一标识,比如en_uu
|
|
|
+ if (tokenUser.getSpaceDialectUID() != null) {
|
|
|
+ // 如果企业不存在则更新该企业
|
|
|
+ for (Enterprise enterprise : authedUser.getEnterprises()) {
|
|
|
+ if (enterprise.getUu().equals(Long.parseLong(tokenUser.getSpaceDialectUID()))){
|
|
|
+ authedUser.setEnterprise(enterprise);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null == authedUser.getEnterprise()) {
|
|
|
+ Enterprise newEnterprise = enterpriseDao.findByUu(Long.parseLong(tokenUser.getSpaceDialectUID()));
|
|
|
+ if (null == newEnterprise) {
|
|
|
+ UserSpaceDetail userSpaceDetail = null;
|
|
|
+ try {
|
|
|
+ userSpaceDetail = com.uas.account.util.AccountUtils.findByBusinessCode(tokenUser.getSpaceUID());
|
|
|
+ } catch (Exception e) { }
|
|
|
+ UserSpace userSpace = new UserSpace();
|
|
|
+ userSpace.setDialectUID(tokenUser.getSpaceDialectUID());
|
|
|
+ if (null != userSpaceDetail) {
|
|
|
+ enterpriseService.update(userSpace,userSpaceDetail);
|
|
|
+ }
|
|
|
+ newEnterprise = enterpriseDao.findByUu(Long.parseLong(tokenUser.getSpaceDialectUID()));
|
|
|
+ authedUser.setEnterprise(newEnterprise);
|
|
|
+ } else {
|
|
|
+ authedUser.getEnterprises().add(newEnterprise);
|
|
|
+ userDao.save(authedUser);
|
|
|
+ authedUser.setEnterprise(newEnterprise);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (tokenUser.getSpaceUID() != null) {
|
|
|
+ for (Enterprise enterprise : authedUser.getEnterprises()) {
|
|
|
+ // 企业资料在所有系统公认的唯一标识,这里使用商业登记证号
|
|
|
+ if (tokenUser.getSpaceUID().equals(enterprise.getEnBussinessCode())) {
|
|
|
+ authedUser.setEnterprise(enterprise);
|
|
|
+ //保存登录时间
|
|
|
+ List<UserLoginTime> userLoginTimeList = userLoginTimeDao.findByUserUUAndEnUU(authedUser.getUserUU(),enterprise.getUu());
|
|
|
+ UserLoginTime userLoginTime;
|
|
|
+ if (!CollectionUtils.isEmpty(userLoginTimeList)){
|
|
|
+ userLoginTime = userLoginTimeList.get(0);
|
|
|
+ }else {
|
|
|
+ userLoginTime = new UserLoginTime();
|
|
|
+ userLoginTime.setUserUU(authedUser.getUserUU());
|
|
|
+ userLoginTime.setEnUU(enterprise.getUu());
|
|
|
+ }
|
|
|
+ userLoginTime.setLoginTime(System.currentTimeMillis());
|
|
|
+ try {
|
|
|
+ userLoginTimeDao.save(userLoginTime);
|
|
|
+ }catch (Exception e){}
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return authedUser;
|
|
|
+ }
|
|
|
/**
|
|
|
* 记录登录日志
|
|
|
* @param request
|