Commit a46253ca by fukai

支持objtyp和objinr加入过滤

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