*/
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest)request;
String requestingHost = req.getRemoteHost();
String referringHost =
getReferringHost(req.getHeader("Referer"));
String bannedSite = null;
boolean isBanned = false;
if (bannedSiteTable.contains(requestingHost)) {
bannedSite = requestingHost;
isBanned = true;
Figure 5??“6 You cannot
successfully follow the link from
the page of Figure 5??“5. The
BannedAccessFilter prohibits
access from www.tbiq.com (an
unscrupulous competitor to
filtersRus.com).
5.8 Example: A Prohibited-Site Filter 231
} else if (bannedSiteTable.contains(referringHost)) {
bannedSite = referringHost;
isBanned = true;
if (bannedSiteTable.contains(requestingHost)) {
bannedSite = requestingHost;
isBanned = true;
} else if (bannedSiteTable.contains(referringHost)) {
bannedSite = referringHost;
isBanned = true;
}
if (isBanned) {
showWarning(response, bannedSite);
} else {
chain.doFilter(request,response);
}
}
/** Create a table of banned sites based on initialization
* parameters.
*/
public void init(FilterConfig config)
throws ServletException {
bannedSiteTable = new HashSet
();
String bannedSites =
config.getInitParameter("bannedSites");
if (bannedSites == null) {
return;
}
// Split using one or more white spaces
String[] sites = bannedSites.
Pages:
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282