Commit 02b792f5 by gechengyang

优化登录存储用户信息

parent fa73fd67
package com.ceb.gjjs.mda.global;
/**
* 登录使用的静态参数
*/
public class LoginConstants {
//核心编号
public static final String cid = "cid";
//企业操作员编号
public static final String oid= "oid";
//网银编号
public static final String ncid= "ncid";
public static final String token="__token";
//用户ID
public static final String usrinr= "usrinr";
public static final String ptyinr= "ptyinr";
public static final String errorText= "errorText";
public static final String CN= "CN";
public static final String needSign= "needSign";
public static final String __terminalType= "__terminalType";
}
......@@ -8,8 +8,13 @@ import com.brilliance.mda.runtime.mda.driver.MdaDriver;
import com.brilliance.mda.runtime.mda.driver.MdaEnv;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.request.BaseVO;
import com.brilliance.mda.support.cache.ICache;
import com.brilliance.mda.support.cache.impl.RedisCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.*;
......@@ -791,10 +796,13 @@ public class Platform {
return null;
}
public static Object getLoginData(Object param) {
if ("usrinr".equals(param)) {
return "00000970";
}
public static Object getLoginData(String param) {
if(LoginConstants.usrinr.equals(param))
return MdaEnv.getAuthInfo().getUsrInr();
else if(LoginConstants.errorText.equals(param))
return MdaEnv.getAuthInfo().getErrorText();
else if(LoginConstants.ncid.equals(param))
return MdaEnv.getAuthInfo().getPtyInr();
return null;
}
......
......@@ -3,14 +3,11 @@ package com.ceb.gjjs.mda.web;
import com.brilliance.mda.runtime.mda.IAuthInfo;
import com.brilliance.mda.runtime.mda.IContext;
import com.brilliance.mda.runtime.mda.driver.MdaEnv;
import com.brilliance.mda.runtime.mda.util.Systems;
import com.brilliance.mda.runtime.request.BaseVO;
import com.brilliance.mda.support.cache.ICache;
import com.brilliance.mda.support.mybatis.DynamicDataSourceContextHolder;
import com.brilliance.mda.support.td.TDAuthInfo;
import com.ceb.gjjs.mda.dao.EtgMapper;
import com.ceb.gjjs.mda.dao.EtyMapper;
import com.ceb.gjjs.mda.dao.UsrMapper;
import com.brilliance.mda.support.td.BDAuthInfo;
import com.ceb.gjjs.mda.global.LoginConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -19,21 +16,22 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.brilliance.mda.runtime.mda.Constants.tdContextLASTUSERACTIONTIME;
import java.util.Map;
public class AuthInterceptor implements HandlerInterceptor {
@Autowired
/* @Autowired
private UsrMapper usrMapper;
@Autowired
private PtyMapper ptyMapper;
@Autowired
private EtyMapper etyMapper;
@Autowired
private EtgMapper etgMapper;
private EtgMapper etgMapper;*/
@Qualifier(ICache.CTX_CACHE)
@Autowired
......@@ -43,22 +41,16 @@ public class AuthInterceptor implements HandlerInterceptor {
@Autowired
private ICache<String, IAuthInfo> authInfoICache;
//简单生成Token Key
private String getTokenKey(HttpServletRequest request) {
String logName = request.getHeader("token");
if (logName == null || "undefined".equals(logName))
logName = "test";
//现在仅仅以userId这个来实现
return logName;
}
private IAuthInfo getOrCreateAuthInfo(String tokenKey, String userId) {
private IAuthInfo getOrCreateAuthInfo(String tokenKey,Map<String,Object> headMap) {
IAuthInfo authInfo = authInfoICache.get(tokenKey);
if (authInfo == null) {
synchronized (authInfoICache) {
authInfo = authInfoICache.get(tokenKey);
if (authInfo == null) {
TDAuthInfo tdAuthInfo = new TDAuthInfo(userId);
String cid=headMap.get(LoginConstants.cid).toString();
String ncid=headMap.get(LoginConstants.ncid).toString();
BDAuthInfo tdAuthInfo = new BDAuthInfo(cid,ncid,"");
authInfo = tdAuthInfo;
authInfoICache.store(tokenKey, authInfo);
//构造authInfo,本该在登录里面做
......@@ -96,22 +88,45 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
/*
//客户核心编号
String cid = request.getHeader(LoginConstants.cid);
//这里需要通过cid查询usr表,项目组实现相关逻辑 TODO
//逻辑补充在这里.....
Map<String,Object> argsMap = new HashMap<>();
argsMap.put("sql","select * from usr where cid='"+cid+"'");
List<Usr> usrList = usrMapper.dyncRead(argsMap);
if(usrList.size()==0)
{
return false;
//throw new RuntimeException("通过 "+cid+" 查找用户信息表,返回为空");
}
String userId=usrList.get(0).getInr();
//网银编号
String ncid= request.getHeader(LoginConstants.ncid);
//这里需要通过ncid查询pty表,项目组实现相关逻辑 TODO
//.........
String logName = request.getHeader("userId");
if (logName == null || "undefined".equals(logName))
logName = "test";
String token = getTokenKey(request);
if (cid == null || "undefined".equals(cid))
cid = "test";
String token =request.getHeader(LoginConstants.token);
Map<String,Object> headMap=new HashMap<>();
headMap.put(LoginConstants.cid,cid);
headMap.put(LoginConstants.ncid,ncid);
headMap.put(LoginConstants.token,token);
//目前采用自动登录模式认证
getOrCreateAuthInfo(token, logName);
getOrCreateAuthInfo(token, headMap);
//设置一些系统参数
String actionTime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
Systems.setContext(tdContextLASTUSERACTIONTIME, actionTime);
Systems.setContext(tdContextLASTUSERACTIONTIME, actionTime);*/
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
......
......@@ -5,7 +5,11 @@ import com.brilliance.mda.runtime.mda.IContext;
import com.brilliance.mda.runtime.mda.driver.MdaEnv;
import com.brilliance.mda.runtime.mda.util.Systems;
import com.brilliance.mda.support.cache.ICache;
import com.brilliance.mda.support.td.TDAuthInfo;
import com.brilliance.mda.support.td.BDAuthInfo;
import com.ceb.gjjs.mda.bo.Usr;
import com.ceb.gjjs.mda.dao.PtyMapper;
import com.ceb.gjjs.mda.dao.UsrMapper;
import com.ceb.gjjs.mda.global.LoginConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -13,7 +17,7 @@ import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.ext.Provider;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import static com.brilliance.mda.runtime.mda.Constants.tdContextLASTUSERACTIONTIME;
......@@ -33,37 +37,71 @@ public class AuthorizationRequestFilter implements ContainerRequestFilter {
@Autowired
private ICache<String, IAuthInfo> authInfoICache;
@Autowired
private UsrMapper usrMapper;
@Autowired
private PtyMapper ptyMapper;
/****
*
* @param request
* 这里可以获取网银传递的uid、cid、ocid等各种信息
*/
@Override
public void filter(ContainerRequestContext request) {
//String logName = request.getHeaderString("userId");
//客户核心编号
String cid = request.getHeaderString(LoginConstants.cid);
//逻辑修改补充在这里.....
Map<String,Object> argsMap = new HashMap<>();
argsMap.put("sql","select * from usr where cid='"+cid+"'");
List<Usr> usrList = usrMapper.dyncRead(argsMap);
if(usrList.size()==0)
{
return ;
}
String userId=usrList.get(0).getInr();
//网银编号
String ncid = request.getHeaderString(LoginConstants.ncid);
//errorText
String errorText=request.getHeaderString(LoginConstants.errorText);
Map<String,Object> headMap=new HashMap<>();
headMap.put(LoginConstants.usrinr,userId);
headMap.put(LoginConstants.ncid,ncid);
headMap.put(LoginConstants.errorText,errorText);
String logName = request.getHeaderString("userId");
if (logName == null || "undefined".equals(logName))
logName = "test";
String token = getTokenKey(request);
//目前采用自动登录模式认证
getOrCreateAuthInfo(token, logName);
getOrCreateAuthInfo(token, headMap);
//设置一些系统参数
String actionTime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
Systems.setContext(tdContextLASTUSERACTIONTIME, actionTime);
}
private String getTokenKey(ContainerRequestContext request) {
String logName = request.getHeaderString("token");
if (logName == null || "undefined".equals(logName))
logName = "test";
//现在仅仅以userId这个来实现
return logName;
/*String token = request.getHeaderString(LoginConstants.token);
if (token == null || "undefined".equals(token))
token = "test";
return token;*/
return UUID.randomUUID().toString();
}
private IAuthInfo getOrCreateAuthInfo(String tokenKey, String userId) {
private IAuthInfo getOrCreateAuthInfo(String tokenKey, Map<String,Object> headMap) {
IAuthInfo authInfo = authInfoICache.get(tokenKey);
if (authInfo == null) {
synchronized (authInfoICache) {
authInfo = authInfoICache.get(tokenKey);
if (authInfo == null) {
TDAuthInfo tdAuthInfo = new TDAuthInfo(userId);
String usrinr=headMap.get(LoginConstants.usrinr).toString();
String ptyinr=headMap.get(LoginConstants.ncid).toString();
String errorText=headMap.get(LoginConstants.errorText)==null?"":headMap.get(LoginConstants.errorText).toString();
BDAuthInfo tdAuthInfo = new BDAuthInfo(usrinr,ptyinr,errorText);
authInfo = tdAuthInfo;
authInfoICache.store(tokenKey, authInfo);
//构造authInfo,本该在登录里面做
......
......@@ -7,7 +7,7 @@
<property name="charset" value="UTF-8"></property>
<property name="immediateFlush" value="true"></property>
<property name="pattern"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-6level) --- [%15.15(%thread)] %cyan(%-40.40(%logger{40})) : %msg%n"></property>
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-6level) --- [%15.15(%thread)] %cyan(%-60.60(%logger{100})) : %msg%n"></property>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
......
package com.brilliance.test;
import java.util.HashSet;
public class Test {
@org.junit.jupiter.api.Test
public void test(){
HashSet set=new HashSet();
set.add("com");
set.add("com1");
set.add("com");
System.out.println(set.size());
System.out.println(set);
}
}
......@@ -107,4 +107,6 @@ public class Constants {
public static final String ATTR_CODE_VALUES = "ATTR_CODE_VALUES";
public static final EventType onChange = EventType.ON_CHANGE;;
public static final EventType onClick = EventType.ON_CLICK;
}
......@@ -2,7 +2,13 @@ package com.brilliance.mda.runtime.mda;
public interface IAuthInfo {
//获取当前用户登录ID
String getUserId();
String getUsrInr();
//获取当前用户的机构ID
String getPtyInr();
//获取errorText
String getErrorText();
IStream getSysStream();
......
......@@ -116,7 +116,7 @@ public class MdaEnv {
public static String getLoginUser() {
//结合具体环境,从tl_infos中获取
return tl_infos.get().getUserId();
return tl_infos.get().getUsrInr();
}
public static String getEncoding() {
......@@ -133,7 +133,7 @@ public class MdaEnv {
}
public static <T> T getSessionContextValue(String key) {
String uid = MdaEnv.getAuthInfo().getUserId();
String uid = MdaEnv.getAuthInfo().getUsrInr();
if (!sessionContext.containsKey(uid)) {
return null;
}
......@@ -146,7 +146,7 @@ public class MdaEnv {
public static void setSessionContext(String key, Object... obj) {
if (key == null) return;
String uid = MdaEnv.getAuthInfo().getUserId();
String uid = MdaEnv.getAuthInfo().getUsrInr();
if (!sessionContext.containsKey(uid)) {
sessionContext.put(uid, new ConcurrentHashMap<String, List<Object>>());
}
......
......@@ -9,9 +9,9 @@ public class BaseVO {
protected List<Map<String, Object>> changes;
protected int pageNum;
protected int pageNum;//第几页,从1开始,比如1,2,3,4,5......
protected int pageSize;
protected int pageSize;//分页每页大小
public Map<String, Object> getParams() {
return params;
......
......@@ -6,27 +6,42 @@ import com.brilliance.mda.runtime.mda.impl.StreamImpl;
import java.util.List;
public class TDAuthInfo implements IAuthInfo {
private String userId;
public class BDAuthInfo implements IAuthInfo {
private String usrInr;
private String ptyInr;
private String errorText;
private IStream sysStream;
private IStream ddsStream;
private IStream keepAuthInfo;
public TDAuthInfo(){}
public BDAuthInfo(){}
public TDAuthInfo(String userId) {
this.userId = userId;
public BDAuthInfo(String usrInr, String ptyInr,String errorText) {
this.usrInr = usrInr;
this.ptyInr=ptyInr;
this.errorText=errorText;
sysStream = new StreamImpl();
ddsStream = new StreamImpl();
keepAuthInfo = new StreamImpl();
}
@Override
public String getUserId() {
return userId;
public String getUsrInr() {
return usrInr;
}
@Override
public String getPtyInr() {
return ptyInr;
}
@Override
public String getErrorText() {
return null;
}
@Override
public IStream getSysStream() {
return sysStream;
}
......
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