Commit 3c5ab77e by WeiCong

完成光大e结算用户初始化逻辑

增加e结算登陆上下文
parent b4e8040c
......@@ -136,7 +136,7 @@
<orderEntry type="module-library">
<library name="Maven: org.freemarker:freemarker:1.0.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/src/main/webapp/WEB-INF/lib/freemarker.jar!/" />
<root url="jar://$MODULE_DIR$/e-lib/eps-business.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
......
......@@ -21,7 +21,7 @@
</repositories>
<properties>
<project.build.sourceEncoding>GBK</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-dependency-plugin.version>3.2.0</maven-dependency-plugin.version>
<maven-jar-plugin_version>3.2.0</maven-jar-plugin_version>
<spring.version>5.1.3.RELEASE</spring.version>
......@@ -194,6 +194,13 @@
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/freemarker.jar</systemPath>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/e-lib/eps-business.jar</systemPath>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
......
package cn.com.brilliance.eibs.auth;
import org.sss.common.impl.AbstractLoginContext;
import org.sss.common.model.IMenuItem;
import java.sql.Connection;
import java.util.Map;
/**
* 光大e结算版本
*/
public class ELoginContext extends AbstractLoginContext {
private String userId;
private String needSign="no";
public ELoginContext(String userId) {
this.userId = userId;
}
@Override
public String getLoginUser() {
return this.userId;
}
@Override
public boolean auth(Connection arg0, Map arg1) {
return true;
}
@Override
public IMenuItem getMenu() {
return null;
}
@Override
protected String getParameter(Map map, String key) {
if (map == null) {
return null;
}
Object o = map.get(key);
if (o == null) {
return null;
} else if (o instanceof String) {
return (String) o;
} else if (o instanceof String[]) {
return ((String[]) o)[0];
} else {
return o.toString();
}
}
@Override
public Object getValue(String key) {
if ("usrinr".equals(key)) {
return userId;
}
if("needSign".equals(key)){
return needSign;
}
return null;
}
@Override
public boolean login(Connection arg0, Map arg1) {
return true;
}
}
......@@ -31,30 +31,12 @@ public class EmptyLoginContext extends AbstractLoginContext {
}
@Override
protected String getParameter(Map map, String key) {
if (map == null){
return null;
}
Object o = map.get(key);
if (o == null){
return null;
}
else if (o instanceof String){
return (String) o;
}
else if (o instanceof String[]){
return ((String[]) o)[0];
}
else{
return o.toString();
}
protected String getParameter(Map arg0, String arg1) {
return null;
}
@Override
public Object getValue(String key) {
if ("usrinr".equals(key)){
return userId;
}
public Object getValue(String arg0) {
return null;
}
......
package org.sss.module.pojo;
import com.brilliance.eibs.etrade.module.Sysmod;
import log.Log;
import log.LogFactory;
import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.beanutils.MethodUtils;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.sss.common.model.Argument;
import org.sss.common.model.IModule;
import org.sss.common.model.IModuleRoot;
import org.sss.module.hibernate.HibernateUtils;
import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.util.PropertyUtil;
import org.sss.presentation.noui.util.StringUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -21,6 +25,7 @@ import java.util.Map;
*/
public class PreHandle {
public final static ThreadLocal<String> USRINR = new ThreadLocal<String>();
private static final Log log = LogFactory.getLog(PreHandle.class);
private static HashMap<String, String[]> config = new HashMap<String, String[]>();
......@@ -79,7 +84,7 @@ public class PreHandle {
log.warn("执行sureBtn预处理方法,需要两个参数:'Module名称'和'待跳转的交易名称'");
return;
}
if(paramsMap.get("__inr")==null){
if (paramsMap.get("__inr") == null) {
log.warn("执行sureBtn预处理方法,params中需要__inr关键字对应的模型inr");
return;
}
......@@ -87,11 +92,41 @@ public class PreHandle {
String toTrs = (String) otherParams[1];
String packageName = ((AbstractPOJOImpl) ctx.getSupport()).getPackageName(toTrs);
String className = packageName + "." + toTrs.substring(0, 1).toUpperCase() + toTrs.substring(1);
IModuleRoot root = (IModuleRoot) ConstructorUtils.invokeConstructor(Class.forName(className), new Object[]{toTrs, new Sysmod()}
Class clazz = Class.forName(AbstractPOJOImpl.modulePackageName + ".Sysmod");
IModuleRoot root = (IModuleRoot) ConstructorUtils.invokeConstructor(Class.forName(className),
new Object[]{toTrs, (IModule) ConstructorUtils.invokeConstructor(clazz, new Object[0])}
, new Class[]{String.class, IModule.class});
IModule grp = (IModule) ctx.getSession().getBaseObject(root, grpNam + "\\rec");
ctx.getSupport().get(grp, new Argument[]{new Argument("inr", paramsMap.get("__inr"))});
ctx.getError();
ctx.getSession().storeData("com.brilliance." + toTrs + ".ref", grp);
}
public static boolean initUserInr(String cid, String oid) {
Session session = HibernateUtils.openSession(null);
String ptySql = "select inr,ptytyp from pty where (ptytyp='2' or PTYTYP='1') and cid=?";
SQLQuery sqlQuery = session.createSQLQuery(ptySql);
sqlQuery.setString((int) 0, cid);
sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<Map> ptyLst = sqlQuery.list();
if (ptyLst == null || ptyLst.size() == 0) {
return false;
}
Map ptyRs = ptyLst.get(0);
String ptyinr = (String) ptyRs.get("INR");
String usrSql = "select inr,lgnnam,oprnam from usr where oid=? and ptyinr=?";
sqlQuery = session.createSQLQuery(usrSql);
sqlQuery.setString((int) 0, oid);
sqlQuery.setString(1, ptyinr);
sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<Map> usrLst = sqlQuery.list();
if (usrLst == null || usrLst.size() == 0) {
return false;
}
Map usrRs = usrLst.get(0);
USRINR.set((String) usrRs.get("INR"));
session.close();
return true;
}
}
package org.sss.presentation.noui.api.request;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
public class NoUiRequest {
private HttpServletRequest httpRequest;
private String token;
private String userId;
private String terminalType;// WEB APP
private String mappingUrl;
private boolean openSource;
private Map<String, ?> paramsMap = new HashMap<String, Object>();
private Map<String, ?> paginationMap = new HashMap<String, Object>();
private Map<String, ?> dataMap = new HashMap<String, Object>();
private Map<String, ?> saveDisplayMap = new HashMap<String, Object>();
private boolean isSecurity=false;
private String reqUrl;
private String trnName;
public NoUiRequest() {
}
public NoUiRequest(HttpServletRequest request, String mappingUrl, Map<String, ?> requestData) {
String tokenId = request.getHeader("token");
String userId = request.getHeader("userId");
String terminalType = request.getHeader("terminalType");
String security=request.getHeader("security");
this.token = tokenId;
this.userId = userId;
this.terminalType = terminalType;
this.mappingUrl = mappingUrl;
String[] mappingArgs = mappingUrl.split("/");
if(mappingArgs.length>1){
this.trnName = mappingArgs[mappingArgs.length - 2];
if(request.getRequestURI().indexOf(this.trnName)>0){
this.reqUrl=request.getRequestURI().substring(request.getRequestURI().indexOf(this.trnName)-1);
}else{
this.reqUrl=mappingUrl;
}
}
if(!StringUtil.isEmpty(security)){
this.isSecurity=true;
}
if (request.getRequestURI().indexOf(NoUiContextManager.openSourcePrefix + "/") >= 0) {
this.openSource = true; //开放访问路径
}
if (requestData != null) {
this.paramsMap = (Map<String, ?>) requestData.get(Constants.PARAMS);
this.dataMap = (Map<String, ?>) requestData.get(Constants.DATA);
this.saveDisplayMap = (Map<String, ?>) requestData.get(Constants.DISPLAY);
this.paginationMap = (Map<String, ?>) requestData.get(Constants.PAGINATION);
if (this.paramsMap == null)
this.paramsMap = new HashMap<String, Object>();
if (this.dataMap == null)
this.dataMap = new HashMap<String, Object>();
if (this.saveDisplayMap == null)
this.saveDisplayMap = new HashMap<String, Object>();
if (this.paginationMap == null)
this.paginationMap = new HashMap<>();
}
}
public boolean isOpenSource() {
return this.openSource;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getMappingUrl() {
return mappingUrl;
}
public void setMappingUrl(String mappingUrl) {
this.mappingUrl = mappingUrl;
}
public HttpServletRequest getHttpRequest() {
return httpRequest;
}
public void setHttpRequest(HttpServletRequest httpRequest) {
this.httpRequest = httpRequest;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getTerminalType() {
return terminalType;
}
public void setTerminalType(String terminalType) {
this.terminalType = terminalType;
}
public Map<String, ?> getParamsMap() {
return paramsMap;
}
public void setParamsMap(Map<String, ?> paramsMap) {
this.paramsMap = paramsMap;
}
public Map<String, ?> getDataMap() {
return dataMap;
}
public void setDataMap(Map<String, ?> dataMap) {
this.dataMap = dataMap;
}
public Map<String, ?> getSaveDisplayMap() {
return saveDisplayMap;
}
public void setSaveDisplayMap(Map<String, ?> saveDisplayMap) {
this.saveDisplayMap = saveDisplayMap;
}
public boolean isSecurity() {
return isSecurity;
}
public String getReqUrl() {
return reqUrl;
}
public String getTrnName() {
return trnName;
}
public Map<String, ?> getPaginationMap() {
return paginationMap;
}
public void setPaginationMap(Map<String, ?> paginationMap) {
this.paginationMap = paginationMap;
}
}
package org.sss.presentation.noui.api.request;
import org.sss.module.pojo.PreHandle;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
public class NoUiRequest {
private HttpServletRequest httpRequest;
private String token;
private String userId;
private String terminalType;// WEB APP
private String mappingUrl;
private boolean openSource;
private Map<String, ?> paramsMap = new HashMap<String, Object>();
private Map<String, ?> paginationMap = new HashMap<String, Object>();
private Map<String, ?> dataMap = new HashMap<String, Object>();
private Map<String, ?> headMap = new HashMap<String, Object>();
private Map<String, ?> saveDisplayMap = new HashMap<String, Object>();
private boolean isSecurity = false;
private String reqUrl;
private String trnName;
private String cid;
private String oid;
public NoUiRequest() {
}
public NoUiRequest(HttpServletRequest request, String mappingUrl, Map<String, ?> requestData) {
String tokenId = request.getHeader("token");
String userId = request.getHeader("userId");
String terminalType = request.getHeader("terminalType");
String security = request.getHeader("security");
//光大e结算改造
this.cid = request.getHeader(Constants.CIFNO);
this.oid = request.getHeader(Constants.USERID);
this.token = tokenId;
if (!StringUtil.isEmpty(cid)) {
String inr = PreHandle.USRINR.get();
if (!StringUtil.isEmpty(inr)) {
this.userId = inr;
PreHandle.USRINR.remove();
}
} else {
this.userId = userId;
}
this.terminalType = terminalType;
this.mappingUrl = mappingUrl;
String[] mappingArgs = mappingUrl.split("/");
if (mappingArgs.length > 1) {
this.trnName = mappingArgs[mappingArgs.length - 2];
if (request.getRequestURI().indexOf(this.trnName) > 0) {
this.reqUrl = request.getRequestURI().substring(request.getRequestURI().indexOf(this.trnName) - 1);
} else {
this.reqUrl = mappingUrl;
}
}
if (!StringUtil.isEmpty(security)) {
this.isSecurity = true;
}
if (request.getRequestURI().indexOf(NoUiContextManager.openSourcePrefix + "/") >= 0) {
this.openSource = true; //开放访问路径
}
if (requestData != null) {
this.paramsMap = (Map<String, ?>) requestData.get(Constants.PARAMS);
this.dataMap = (Map<String, ?>) requestData.get(Constants.DATA);
this.headMap = (Map<String, ?>) requestData.get(Constants.HEAD);
this.saveDisplayMap = (Map<String, ?>) requestData.get(Constants.DISPLAY);
this.paginationMap = (Map<String, ?>) requestData.get(Constants.PAGINATION);
if (this.paramsMap == null) {
this.paramsMap = new HashMap<String, Object>();
}
if (this.dataMap == null) {
this.dataMap = new HashMap<String, Object>();
}
if (this.saveDisplayMap == null) {
this.saveDisplayMap = new HashMap<String, Object>();
}
if (this.paginationMap == null) {
this.paginationMap = new HashMap<>();
}
if (this.headMap == null) {
this.headMap = new HashMap<>();
}
}
}
public boolean isOpenSource() {
return this.openSource;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getMappingUrl() {
return mappingUrl;
}
public void setMappingUrl(String mappingUrl) {
this.mappingUrl = mappingUrl;
}
public HttpServletRequest getHttpRequest() {
return httpRequest;
}
public void setHttpRequest(HttpServletRequest httpRequest) {
this.httpRequest = httpRequest;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getTerminalType() {
return terminalType;
}
public void setTerminalType(String terminalType) {
this.terminalType = terminalType;
}
public Map<String, ?> getParamsMap() {
return paramsMap;
}
public void setParamsMap(Map<String, ?> paramsMap) {
this.paramsMap = paramsMap;
}
public Map<String, ?> getDataMap() {
return dataMap;
}
public void setDataMap(Map<String, ?> dataMap) {
this.dataMap = dataMap;
}
public Map<String, ?> getSaveDisplayMap() {
return saveDisplayMap;
}
public void setSaveDisplayMap(Map<String, ?> saveDisplayMap) {
this.saveDisplayMap = saveDisplayMap;
}
public boolean isSecurity() {
return isSecurity;
}
public String getReqUrl() {
return reqUrl;
}
public String getTrnName() {
return trnName;
}
public Map<String, ?> getPaginationMap() {
return paginationMap;
}
public void setPaginationMap(Map<String, ?> paginationMap) {
this.paginationMap = paginationMap;
}
public Map<String, ?> getHeadMap() {
return headMap;
}
public void setHeadMap(Map<String, ?> headMap) {
this.headMap = headMap;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
}
......@@ -5,6 +5,7 @@ import java.nio.charset.Charset;
public class Constants {
public final static String PARAMS = "params";
public final static String DATA = "data";
public final static String HEAD = "head";
public final static String DISPLAY = "display";
public final static String ENCODING = "UTF-8";
public static final Charset ENCODING_CHARSET = Charset.forName(ENCODING);
......@@ -25,4 +26,8 @@ public class Constants {
public static final String PAGINATION_INDEX = "index";
public static final String PAGINATION_PAGESIZE = "pageSize";
public static final String PAGINATION_TOTAL = "total";
//光大e结算新增常量
public static final String CIFNO = "cifno";
public static final String USERID = "userid";
}
package org.sss.presentation.noui.context;
import cn.com.brilliance.eibs.auth.ELoginContext;
import cn.com.brilliance.eibs.auth.EmptyLoginContext;
import log.Log;
import log.LogFactory;
......@@ -10,51 +11,52 @@ import org.sss.common.model.IModuleSession;
import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.presentation.noui.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class NoUiContextManager {
private static final Log log = LogFactory.getLog(NoUiContextManager.class);
public static String dbType = "hibernate";
public static String loginContextName = "cn.com.brilliance.eibs.auth.DatabaseLoginContext";
public static String openSourcePrefix = "openservice";
public static String everybody = "#Everybody#";
public static List<String> openTransactions = new ArrayList<String>();
private static final Log log = LogFactory.getLog(NoUiContextManager.class);
public static String dbType = "hibernate";
public static String loginContextName = "cn.com.brilliance.eibs.auth.DatabaseLoginContext";
public static String openSourcePrefix = "openservice";
public static String everybody = "#Everybody#";
public static List<String> openTransactions = new ArrayList<String>();
public static NoUiContext createNoUiContext(NoUiRequest noUiRequest) {
NoUiContext noUiContext = new NoUiContext();
ILoginContext loginContext = null;
if(noUiRequest.isOpenSource())
{
loginContext = new EmptyLoginContext(everybody);
}
else if (StringUtils.isEmpty(noUiRequest.getToken())) {
try {
loginContext = (ILoginContext) Class.forName(loginContextName).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new NoUiException("loingConextName class is not found", loginContextName);
}
}
else
loginContext = new EmptyLoginContext(noUiRequest.getUserId());
loginContext.setContext(noUiContext);
noUiContext.setAuth(loginContext);
noUiContext.setSessionId(UUID.randomUUID().toString());
IModuleSession session = null;
try {
Class<?> clazz = Class.forName("org.sss.module." + dbType + ".ModuleSessionImpl");
session = (IModuleSession) ConstructorUtils.invokeConstructor(clazz, new Object[] { noUiContext, NoUiUtils.connectKeeped});
} catch (Exception e) {
log.error("Constructs NoUiContext error",e);
throw new NoUiException("Constructs NoUiContext error",e);
}
noUiContext.setGui(new NoUiPresentation(noUiContext, noUiRequest));
noUiContext.setSession(session);
noUiContext.setNoUiRequest(noUiRequest);
log.debug("Build context finished");
return noUiContext;
}
public static NoUiContext createNoUiContext(NoUiRequest noUiRequest) {
NoUiContext noUiContext = new NoUiContext();
ILoginContext loginContext = null;
if (noUiRequest.isOpenSource()) {
loginContext = new EmptyLoginContext(everybody);
}else if(!StringUtil.isEmpty(noUiRequest.getCid()) && !StringUtil.isEmpty(noUiRequest.getOid())){
loginContext = new ELoginContext(noUiRequest.getUserId());
}
else if (StringUtils.isEmpty(noUiRequest.getToken())) {
try {
loginContext = (ILoginContext) Class.forName(loginContextName).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new NoUiException("loingConextName class is not found", loginContextName);
}
} else {
loginContext = new EmptyLoginContext(noUiRequest.getUserId());
}
loginContext.setContext(noUiContext);
noUiContext.setAuth(loginContext);
noUiContext.setSessionId(UUID.randomUUID().toString());
IModuleSession session = null;
try {
Class<?> clazz = Class.forName("org.sss.module." + dbType + ".ModuleSessionImpl");
session = (IModuleSession) ConstructorUtils.invokeConstructor(clazz, new Object[]{noUiContext, NoUiUtils.connectKeeped});
} catch (Exception e) {
log.error("Constructs NoUiContext error", e);
throw new NoUiException("Constructs NoUiContext error", e);
}
noUiContext.setGui(new NoUiPresentation(noUiContext, noUiRequest));
noUiContext.setSession(session);
noUiContext.setNoUiRequest(noUiRequest);
log.debug("Build context finished");
return noUiContext;
}
}
......@@ -4,12 +4,16 @@ import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.sss.module.pojo.PreHandle;
import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.*;
import org.sss.presentation.noui.util.EhcacheUtils;
import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.presentation.noui.util.NumericUtil;
import org.sss.presentation.noui.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -34,9 +38,23 @@ public class TokenInterceptor implements HandlerInterceptor {
String userId = noUiRequest.getUserId();
// token不存在
if (StringUtil.isEmpty(token)) {
// Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, "登录token不能为空", null, noUiVersion.getVersion());
// responseMessage(response, response.getWriter(), rt);
return true;
//光大e结算改造
if (!StringUtil.isEmpty(noUiRequest.getCid()) && !StringUtil.isEmpty(noUiRequest.getOid())) {
boolean isAut = PreHandle.initUserInr(noUiRequest.getCid(),noUiRequest.getOid());
if (isAut) {
return true;
} else {
StringBuilder sb=new StringBuilder("未查找到企业客户号=[");
sb.append(noUiRequest.getCid()).append("],用户OID=[").append(noUiRequest.getOid()).append("]关联的用户信息");
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, sb.toString(), null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt);
return false;
}
} else {
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, "登录token不能为空", null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt);
return false;
}
}
// userId不存在
......
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