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;
}
}
......@@ -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