Commit be0ec07f by shiwenbo

authcInfo接口增加currentRegionalCompany信息的返回

parent add51102
......@@ -34,11 +34,6 @@ import com.beecode.inz.authentication.util.LoginLogUtil;
@Component
public class RESTAppAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
/**
* 登录时区域公司的参数key
*/
private final static String REQUEST_CURRENTREGIONALCOMPANY_KEY = "currentRegionalCompany";
@Autowired
private TenantUserService tenantUserService;
@Autowired
......@@ -61,9 +56,6 @@ public class RESTAppAuthenticationSuccessHandler extends SimpleUrlAuthentication
request.getSession().setAttribute("mobile", true);
request.getSession().setMaxInactiveInterval(30*24*60*60);
//构建当前用户数据集
buildCurrentUserDatas(request);
loginLog.setTenantId(tenantUser.getTenantId());
loginLogService.insert(loginLog);
......@@ -83,25 +75,6 @@ public class RESTAppAuthenticationSuccessHandler extends SimpleUrlAuthentication
}
}
/**
* 构造当前用户数据集
*/
private void buildCurrentUserDatas(HttpServletRequest request) {
HttpSession session = request.getSession();
//获取当前用户区域公司参数,存入当前用户数据集(session)
String currentRegionalCompany = obtainCurrentRegionalCompany(request);
Map<String, String > datas = new ConcurrentHashMap<>();
datas.put(REQUEST_CURRENTREGIONALCOMPANY_KEY, currentRegionalCompany);
//目前数据集只存了用户区域公司
session.setAttribute(AuthcConstants.CURRENTUSERDATAS, datas);
}
private String obtainCurrentRegionalCompany(HttpServletRequest request) {
return request.getParameter(REQUEST_CURRENTREGIONALCOMPANY_KEY);
}
public LoginLog getLoginLog(HttpServletRequest request){
LoginLog loginLog=new LoginLog();
String userAgent = request.getHeader(LoginLogConstants.USER_AGENT);
......
......@@ -2,10 +2,13 @@ package com.beecode.inz.authentication.handler;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,6 +35,11 @@ import com.beecode.inz.authentication.util.LoginLogUtil;
@Component
public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
/**
* 登录时区域公司的参数key
*/
private final static String REQUEST_CURRENTREGIONALCOMPANY_KEY = "currentRegionalCompany";
@Autowired
private TenantUserService tenantUserService;
@Autowired
......@@ -52,6 +60,10 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
request.getSession().setAttribute(AuthcConstants.SESSION_TENANTID, tenant);
request.getSession().setAttribute(AuthcConstants.USERNAME, tenantUser.getUsername());
request.getSession().setAttribute(AuthcConstants.USERID, tenantUser.getUserId());
//构建当前用户数据集
buildCurrentUserDatas(request);
loginLog.setTenantId(tenantUser.getTenantId());
loginLogService.insert(loginLog);
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
......@@ -69,9 +81,27 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
} finally {
}
}
/**
* 构造当前用户数据集
*/
private void buildCurrentUserDatas(HttpServletRequest request) {
HttpSession session = request.getSession();
//获取当前用户区域公司参数,存入当前用户数据集(session)
String currentRegionalCompany = obtainCurrentRegionalCompany(request);
Map<String, String > datas = new ConcurrentHashMap<>();
datas.put(REQUEST_CURRENTREGIONALCOMPANY_KEY, currentRegionalCompany);
//目前数据集只存了用户区域公司
session.setAttribute(AuthcConstants.CURRENTUSERDATAS, datas);
}
private String obtainCurrentRegionalCompany(HttpServletRequest request) {
return request.getParameter("regionalCompany");
}
public LoginLog getLoginLog(HttpServletRequest request){
LoginLog loginLog=new LoginLog();
String userAgent = request.getHeader(LoginLogConstants.USER_AGENT);
......
package com.beecode.inz.common.web;
import java.util.Map;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
......@@ -11,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.beecode.bap.staff.BapContext;
import com.beecode.bcp.User;
import com.beecode.bcp.authz.Identity;
import com.beecode.bcp.core.context.AminoContext;
......@@ -21,6 +25,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RestController
public class AuthcInfoController {
@Autowired
private BapContext bapContext;
@Autowired
private ObjectMapper objectMapper;
......@@ -55,6 +62,13 @@ public class AuthcInfoController {
authcInfoObject.put(AminoContextConstants.CURRENTORG, objectMapper.writeValueAsString(org));
if (null != identity)
authcInfoObject.put(AminoContextConstants.CURRENTIDENTITY, objectMapper.writeValueAsString(identity));
Map<String, String> map = bapContext.getCurrentUserDatas();
String currentRegionalCompany = map.get("currentRegionalCompany");
authcInfoObject.put("currentRegionalCompany", currentRegionalCompany);
return new ResponseEntity<String>(authcInfoObject.toString(), headers, HttpStatus.OK);
}
/**
......
......@@ -13,6 +13,7 @@ import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.inz.common.internal.scene.FollowerQueryScene;
import com.beecode.inz.query.exception.SceneExecuteException;
import com.beecode.inz.query.scene.SceneExecuteContext;
import com.xyst.dinas.biz.enumeration.OrganizationTypeEnum;
public class XystDinasCommonAllScene extends FollowerQueryScene {
......@@ -20,22 +21,18 @@ public class XystDinasCommonAllScene extends FollowerQueryScene {
public void execute(SceneExecuteContext context) throws SceneExecuteException {
KObject currentRegionalCompany = this.getCurrentLoginRegionalCompany();
if(null == currentRegionalCompany || currentRegionalCompany.isNull()){
throw new SceneExecuteException("无法获取当前登录区域公司");
throw new SceneExecuteException("无法获取当前登录组织机构");
}
CriteriaBuilder builder = context.getCriteriaBuilder();
Predicate p0 = addCurrentRegionalCompanyQuery(context, builder);
Predicate p0 = builder.equal(context.getRoot().get("regionalCompany").get("id"), currentRegionalCompany.getUuid("id"));
if(currentRegionalCompany.getString("type").equals("REGIONAL_COMPANY")) {
if(currentRegionalCompany.getString("type").equals(OrganizationTypeEnum.REGIONAL_COMPANY.name())) {
context.getCriteriaQuery().and(p0);
}
}
protected Predicate addCurrentRegionalCompanyQuery(SceneExecuteContext context, CriteriaBuilder builder) {
return builder.equal(context.getRoot().get("regionalCompany").get("id"), getCurrentLoginRegionalCompany().getUuid("id"));
}
/**
* 获取当前登录的区域公司
......@@ -45,7 +42,7 @@ public class XystDinasCommonAllScene extends FollowerQueryScene {
String currentRegionalCompany = (String) ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest().getSession().getAttribute("currentRegionalCompany");
if (null == currentRegionalCompany || currentRegionalCompany.trim().length() == 0 ) {
throw new RuntimeException("从session中获取区域公司失败");
throw new RuntimeException("从session中获取组织机构失败");
}
KClass kClass = Amino.getApplicationMetadataContext().getBean("com.xyst.dinas.biz.datamodel.Organization",
KClass.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment