|
|
@@ -1,6 +1,8 @@
|
|
|
package com.uas.platform.b2c.common.account.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserLoginTimeDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.account.model.UserInfo;
|
|
|
import com.uas.platform.b2c.common.account.model.UserLoginTime;
|
|
|
@@ -8,6 +10,11 @@ import com.uas.platform.b2c.common.account.service.RoleService;
|
|
|
import com.uas.platform.b2c.common.account.service.UserService;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
+import com.uas.platform.core.util.AgentUtils;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
+import com.uas.sso.SSOHelper;
|
|
|
+import com.uas.sso.SSOToken;
|
|
|
+import com.uas.sso.entity.UserAccount;
|
|
|
import net.sf.ehcache.CacheManager;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.repository.query.Param;
|
|
|
@@ -18,6 +25,8 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.List;
|
|
|
@@ -45,18 +54,17 @@ public class AuthenticationController {
|
|
|
}
|
|
|
User sysUser = SystemSession.getUser();
|
|
|
//List<UserQuestion> userQuestion = userQuestionService.findUserQuestionByUserUUOrderBySortAsc(sysUser.getUserUU());
|
|
|
- User user = userService.findUserByUserUU(sysUser.getUserUU());
|
|
|
- user.setEnterprise(sysUser.getEnterprise());
|
|
|
- if (user.getEnterprise() != null ) {
|
|
|
- if (!StringUtils.isEmpty(user.getEnterprise().getEnAdminuu()) && user.getEnterprise().getEnAdminuu().equals(user.getUserUU())) {
|
|
|
- user.setIssys(Constant.YES);
|
|
|
+// User user = userService.findUserByUserUU(sysUser.getUserUU());
|
|
|
+// user.setEnterprise(sysUser.getEnterprise());
|
|
|
+ if (sysUser.getEnterprise() != null ) {
|
|
|
+ if (!StringUtils.isEmpty(sysUser.getEnterprise().getEnAdminuu()) && sysUser.getEnterprise().getEnAdminuu().equals(sysUser.getUserUU())) {
|
|
|
+ sysUser.setIssys(Constant.YES);
|
|
|
} else {
|
|
|
- user.setIssys(Constant.NO);
|
|
|
+ sysUser.setIssys(Constant.NO);
|
|
|
}
|
|
|
}
|
|
|
- request.getSession().setAttribute("user", user);
|
|
|
- UserInfo userInfo = new UserInfo(user);
|
|
|
- Integer hasQuestion = user.getHasQuestion();
|
|
|
+ UserInfo userInfo = new UserInfo(sysUser);
|
|
|
+ Integer hasQuestion = sysUser.getHasQuestion();
|
|
|
if (hasQuestion != null && hasQuestion ==1) {
|
|
|
userInfo.setHaveUserQuestion(true);
|
|
|
userInfo.setSecLevel((short) (1 + userInfo.getSecLevel()));
|
|
|
@@ -93,10 +101,51 @@ public class AuthenticationController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/{enUU}")
|
|
|
@ResponseBody
|
|
|
- public void switchEnterprise(@PathVariable("enUU") long enUU, HttpServletRequest request) {
|
|
|
+ public void switchEnterprise(@PathVariable("enUU") long enUU, HttpServletRequest request, HttpServletResponse response) {
|
|
|
userService.saveLoginTime(enUU);
|
|
|
User user = userService.switchEnterprise(enUU);
|
|
|
- request.getSession().setAttribute("user", user);
|
|
|
+
|
|
|
+ SSOToken token = (SSOToken)SSOHelper.getToken(request);
|
|
|
+ UserAccount tokenUser = FlexJsonUtils.fromJson(token.getData(), UserAccount.class);
|
|
|
+ if (enUU == 0L) {
|
|
|
+ tokenUser.setSpaceUU(null);
|
|
|
+ } else {
|
|
|
+ tokenUser.setSpaceUU(enUU);
|
|
|
+ }
|
|
|
+ token.setData(FlexJsonUtils.toJson(tokenUser));
|
|
|
+ // 设置cookie
|
|
|
+ SSOHelper.setSSOCookie(request, response, token, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private User getUserByToken(SSOToken token) {
|
|
|
+ User authedUser = null;
|
|
|
+ if (token.getData() != null) {
|
|
|
+ UserAccount tokenUser = FlexJsonUtils.fromJson(token.getData(), UserAccount.class);
|
|
|
+ if (!StringUtils.isEmpty(tokenUser.getUserUU())) {
|
|
|
+ // dialectUID表示client系统自己的唯一标识,比如user_uu,手机号没设置的情况下使用
|
|
|
+ authedUser = userService.findUserByUserUU(tokenUser.getUserUU());
|
|
|
+ } else if (!StringUtils.isEmpty(tokenUser.getMobile())) {
|
|
|
+ // UID表示所有系统公认的唯一标识,这里统一使用手机号
|
|
|
+ authedUser = userService.findUserByUserTel(tokenUser.getMobile());
|
|
|
+ } else {
|
|
|
+// logger.error(String.format("invalid user %s, please set uid or dialectUID", tokenUser.getVipName()));
|
|
|
+ }
|
|
|
+ if (authedUser != null && authedUser.getEnterprises() != null) {
|
|
|
+ // 企业资料在client系统自己的唯一标识,比如en_uu
|
|
|
+ if (tokenUser.getSpaceUU() != null) {
|
|
|
+ authedUser.setCurrentEnterprise(tokenUser.getSpaceUU());
|
|
|
+ } else if (tokenUser.getBusinessCode() != null) {
|
|
|
+ for (Enterprise enterprise : authedUser.getEnterprises()) {
|
|
|
+ // 企业资料在所有系统公认的唯一标识,这里使用商业登记证号
|
|
|
+ if (tokenUser.getBusinessCode().equals(enterprise.getEnBussinessCode())) {
|
|
|
+ authedUser.setEnterprise(enterprise);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return authedUser;
|
|
|
}
|
|
|
|
|
|
/**
|