【泛微E9】实现非系统管理员也能执行清空缓存操作
需求描述
想让某个指定用户(loginid=kk)也能访问系统管理员访问的 OA地址/commcache/cacheMonitor.jsp 页面,执行清空缓存操作。
方法1
操作步骤
步骤1:
修改 WEAVER/ecology/WEB-INF/weaver_security_rules.xml,把指定用户的loginid加入全局 <allow-users>
<allow-users>
<user>sysadmin</user>
<user>kk</user>
</allow-users>
步骤2:
修改 weaver/ecology/commcache/commoncache.jsp 文件。
将
<%
User user = (User) session.getAttribute("weaver_user@bean");
if(user == null || !"sysadmin".equals(user.getLoginid())){
out.print("auth fail, please contact sysadmin...");
return;
}
%>
修改为:
<%
User user = (User) session.getAttribute("weaver_user@bean");
String loginId = user == null ? "" : user.getLoginid();
if (!"sysadmin".equals(loginId) && !"kk".equals(loginId)) {
out.print("auth fail, please contact sysadmin...");
return;
}
%>
步骤3:
执行完上述2个步骤后,重启resin服务。
方法2
【ESB中心】——【接口管理】—— 点击【新建】,执行Java代码
package com.weaver.esb.package_20260000000000;
import java.util.HashMap;
import java.util.Map;
import weaver.general.BaseBean;
import weaver.monitor.cache.CacheFactory;
public class class_20260000000000 {
private static final String PARAM_ACTION = "action";
private static final String ACTION_RELOAD_COMMON_CACHE = "reloadCommonCache";
private static final Object RESET_LOCK = new Object();
private final BaseBean bbLog = new BaseBean();
public Map execute(Map<String, Object> params) {
Map<String, String> ret = new HashMap<String, String>();
String action = getParam(params, PARAM_ACTION);
if (!ACTION_RELOAD_COMMON_CACHE.equals(action)) {
ret.put("code", "-1");
ret.put("msg", "参数错误:必须传入 action=reloadCommonCache,未执行缓存清理。");
bbLog.writeLog("公共缓存重载未执行,action===>" + action);
return ret;
}
synchronized (RESET_LOCK) {
try {
CacheFactory cacheFactory = CacheFactory.getInstance();
int sqlCacheCountBefore = cacheFactory.getCacheMap().getSize();
int tableCacheCountBefore = cacheFactory.getTableMap().size();
bbLog.writeLog(
"公共缓存重载开始,SQL缓存数量===>" + sqlCacheCountBefore
+ ",表缓存数量===>" + tableCacheCountBefore);
// 与 commoncache.jsp 中 isreload=1 时执行的操作完全相同。
cacheFactory.reset();
int sqlCacheCountAfter = cacheFactory.getCacheMap().getSize();
int tableCacheCountAfter = cacheFactory.getTableMap().size();
ret.put("code", "0");
ret.put(
"msg",
"公共缓存配置重载完成,SQL缓存:"
+ sqlCacheCountBefore + " -> " + sqlCacheCountAfter
+ ",表缓存:"
+ tableCacheCountBefore + " -> " + tableCacheCountAfter);
bbLog.writeLog("公共缓存重载完成===>" + ret.get("msg"));
} catch (Exception e) {
ret.put("code", "-1");
ret.put("msg", "公共缓存配置重载失败:" + e.getMessage());
bbLog.writeLog("公共缓存重载异常===>" + e);
}
}
return ret;
}
private String getParam(Map<String, Object> params, String key) {
if (params == null) {
return "";
}
Object value = params.get(key);
return value == null ? "" : String.valueOf(value).trim();
}
}
接口测试传入 reloadCommonCache 即可实现清空缓存的效果。
浙公网安备 33010602011771号