Commit a46253ca by fukai

支持objtyp和objinr加入过滤

parent ab4d1bed
......@@ -20,10 +20,7 @@ import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.jwt.JWT;
import org.sss.presentation.noui.jwt.JwtLogin;
import org.sss.presentation.noui.jwt.RedisLoginInfo;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.NumericUtil;
import org.sss.presentation.noui.util.RedisUtil;
import org.sss.presentation.noui.util.StringUtil;
import org.sss.presentation.noui.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
......@@ -95,6 +92,8 @@ public class LoginController {
RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes, noUiRequest.getTerminalType());
redisLoginInfo.setUserInr((String)inridf.getValue()); //设置当前用户主键
NoUiUtils.logout(userId,"*"); //清理可能存在的历史缓存
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
//解决初次登陆,超期限登陆
......@@ -156,7 +155,7 @@ public class LoginController {
try {
NoUiRequest noUiRequest = new NoUiRequest(request, "", null);
RedisUtil.delete(StringUtil.userUniqueId(noUiRequest));
NoUiUtils.logout(noUiRequest.getUserId(),"*"); //清理可能存在的历史缓存
return ResultUtil.result(ErrorCodes.SUCCESS,"退出成功",null);
}catch (Exception e)
{
......
......@@ -11,6 +11,8 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Service;
import org.sss.module.hibernate.HibernateUtils;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.RedisUtil;
@Service
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
......@@ -37,6 +39,13 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
transaction.commit();
session.close();
log.info("clear expire user " + userId + " session success");
//清理缓存set
try {
RedisUtil.delete(NoUiPresentationUtil.getCacheSetKey(userId));
}catch (Exception e)
{
log.error(e.getMessage());
}
}
}
......
......@@ -239,29 +239,30 @@ public class NoUiPresentationUtil {
if (val instanceof IModuleList<?>) {
List<Map<String, Object>> list = new ArrayList<>();
IModuleList<?> moduleList = (IModuleList<?>) val;
List<String> cacheRecord = new ArrayList<>();
String paramsKey[] = getParamKeys(moduleList);
for (int index = 0; index < moduleList.size(); index++) {
Map<String, Object> map = new HashMap<>();
IModule module = moduleList.get(index);
Collection<IDatafield> datafields = module.getDatafields();
String[] paramsKey = (String[])moduleList.getAttribute("KEY_PARAMS");
if(paramsKey!=null)
paramsKey = new String[]{"inr","$objtyp"};
for (IDatafield<Object> datafield : datafields) {
map.put(changeForELCS(datafield.getName()), handle(datafield.getValue(), datafield));
}
String[] keyParams = new String[paramsKey.length];
StringBuilder sb = new StringBuilder();
for(int i=0;i<paramsKey.length;i++)
{
if("$objtyp".equals(paramsKey[i]))
keyParams[i] = module.getClass().getSimpleName().toLowerCase(); //module type
sb.append(module.getClass().getSimpleName().toLowerCase()); //module type
else
keyParams[i] = map.get(paramsKey[i]).toString();
sb.append(map.get(paramsKey[i]).toString());
}
String safeCode = NoUiUtils.genSafeCode(keyParams);
map.put("safeCode",safeCode);
cacheRecord.add(sb.toString());
list.add(map);
}
//记录缓存列表进入数据
cacheDataKeys(cacheRecord.toArray(new String[0]));
return list;
} else if (val instanceof IModule) {
val = context.getSession().getBaseObject(context.getRoot(), path);
......@@ -393,4 +394,46 @@ public class NoUiPresentationUtil {
return String.valueOf(ch);
}
public static String getCacheSetKey()
{
String setKey = Constants.SESSION+"."+NoUiUtils.getUserId()+".CACHE_SET";
return setKey;
}
public static String getCacheSetKey(String userId)
{
String setKey = Constants.SESSION+"."+userId+".CACHE_SET";
return setKey;
}
public static void cacheDataKeys(String[] keys)
{
String setKey = getCacheSetKey();
try{
RedisUtil.addMembers(setKey,keys);
}catch (Exception e){
log.error(e.getMessage());
}
}
public static String[] getParamKeys(IModuleList moduleList)
{
String[] paramsKey = (String[])moduleList.getAttribute("KEY_PARAMS");
//TODO 考虑后续读取配置文件
if(paramsKey!=null)
paramsKey = new String[]{"inr","$objtyp"};
return paramsKey;
}
//检查key是否在set中存在
public static boolean isKeyAllowed(String key)
{
try {
return RedisUtil.isMembers(getCacheSetKey(),key);
} catch (Exception e) {
log.error(e.getMessage());
return false;
}
}
}
......@@ -134,6 +134,11 @@ public class NoUiUtils {
tl.remove();
}
public static String getUserId()
{
return tl.get().getUserId();
}
public static String getToken()
{
return tl.get().getToken();
......
......@@ -145,4 +145,24 @@ public class RedisUtil {
}
return new HashSet();
}
public static boolean isMembers(String setKey,String key) throws Exception
{
try {
return masterNode.opsForSet().isMember(setKey,key);
} catch (Exception e) {
log.error(e.getMessage());
checkRedisNodeAvailable();
}
return false;
}
public static void addMembers(String setKey,Object... args) throws Exception
{
try {
masterNode.opsForSet().add(setKey, args);
}catch (Exception e) {
log.error(e.getMessage());
checkRedisNodeAvailable();
}
}
}
\ No newline at end of file
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