synccache.jsp
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ page import="weaver.cluster.*"%>
<%@ page import="sun.misc.BASE64Encoder"%>
<%@ page import="sun.misc.BASE64Decoder"%>
<%@ page import="java.io.*"%>
<%@ page import="weaver.general.*"%>
<%@ page import="org.apache.commons.configuration.*"%>
<%@ page import="org.apache.commons.configuration.reloading.*"%>
<%@ page import="java.util.logging.*"%>
<%@ page import="java.util.regex.*"%>
<%!
class SerialKiller extends ObjectInputStream {
private final XMLConfiguration config;
private final FileChangedReloadingStrategy reloadStrategy;
final Logger LOGGER = Logger.getLogger(SerialKiller.class.getName());
Handler fileHandler;
String logFile;
boolean logEnabled;
String[] blacklist;
String[] whitelist;
boolean profiling;
/**
* SerialKiller constructor, returns instance of ObjectInputStream
*
* @param inputStream The original InputStream, used by your service to receive serialized objects
* @param configFile The location of the config file (absolute path)
* @throws java.io.IOException File I/O exception
* @throws org.apache.commons.configuration.ConfigurationException Config exception
*/
public SerialKiller(InputStream inputStream, String configFile) throws IOException, ConfigurationException {
super(inputStream);
configFile = GCONST.getPropertyPath() + "serialkiller.conf";
config = new XMLConfiguration(configFile);
reloadStrategy = new FileChangedReloadingStrategy();
reloadStrategy.setRefreshDelay(config.getLong("refresh", 6000));
config.setReloadingStrategy(reloadStrategy);
blacklist = config.getStringArray("blacklist.regexp");
whitelist = config.getStringArray("whitelist.regexp");
profiling = config.getBoolean("mode.profiling", false);
logEnabled = false;
if(logEnabled){
logFile = config.getString("logging.logfile", "/tmp/serialkiller.log");
fileHandler = new FileHandler(logFile, true);
LOGGER.addHandler(fileHandler);
LOGGER.setLevel(Level.ALL);
}
}
@Override
protected Class<?> resolveClass(ObjectStreamClass serialInput) throws IOException, ClassNotFoundException {
//Enforce SerialKiller's blacklist
for (String blackRegExp : blacklist) {
Pattern blackPattern = Pattern.compile(blackRegExp);
Matcher blackMatcher = blackPattern.matcher(serialInput.getName());
if (blackMatcher.find()) {
if (profiling){
//Reporting mode
// LOGGER.log(Level.FINE, "Blacklist match: ''{0}''", serialInput.getName());
}else{
//Blocking mode
// LOGGER.log(Level.SEVERE, "Blocked by blacklist ''{0}''. Match found for ''{1}''", new Object[]{blackRegExp, serialInput.getName()});
throw new InvalidClassException("Class blocked by SK: '" + serialInput.getName() + "'");
}
}
}
//Enforce SerialKiller's whitelist
boolean safeClass = false;
for (String whiteRegExp : whitelist) {
Pattern whitePattern = Pattern.compile(whiteRegExp);
Matcher whiteMatcher = whitePattern.matcher(serialInput.getName());
if (whiteMatcher.find()) {
safeClass = true;
if (profiling){
//Reporting mode
// LOGGER.log(Level.FINE, "Whitelist match: ''{0}''", serialInput.getName());
}
}
}
if (!safeClass && !profiling) {
//Blocking mode
// LOGGER.log(Level.SEVERE, "Blocked by whitelist. No match found for ''{0}''", serialInput.getName());
throw new InvalidClassException("Class blocked by SK: '" + serialInput.getName() + "'");
}
return super.resolveClass(serialInput);
}
}
%>
<%
String data = request.getParameter("data");
//System.out.println(data);
if(data ==null) {
return;
}
BASE64Decoder decoder = new BASE64Decoder();
byte[] byteData = decoder.decodeBuffer(data);
ByteArrayInputStream bis = new ByteArrayInputStream(byteData);
ObjectInputStream ois = new SerialKiller(bis,"");
CacheMessage message = (CacheMessage) ois.readObject();
new BaseBean().writeLog(" An cluster-----------------message received: " + message.getAction() + "->" + message.getCacheType());
CacheManager cm = CacheManager.getInstance();
cm.handleNotification(message);
%>