01: /* StripSessionIDs
02: *
03: * Created on Oct 6, 2004
04: *
05: * Copyright (C) 2004 Internet Archive.
06: *
07: * This file is part of the Heritrix web crawler (crawler.archive.org).
08: *
09: * Heritrix is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU Lesser Public License as published by
11: * the Free Software Foundation; either version 2.1 of the License, or
12: * any later version.
13: *
14: * Heritrix is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * GNU Lesser Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser Public License
20: * along with Heritrix; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: */
23: package org.archive.crawler.url.canonicalize;
24:
25: import java.util.regex.Pattern;
26:
27: /**
28: * Strip known session ids.
29: * @author stack
30: * @version $Date: 2006-09-25 20:27:35 +0000 (Mon, 25 Sep 2006) $, $Revision: 4655 $
31: */
32: public class StripSessionIDs extends BaseRule {
33:
34: private static final long serialVersionUID = -3737115200690525641L;
35:
36: private static final String DESCRIPTION = "Strip known session IDs. "
37: + "Use this rule to remove all of a set of known session IDs."
38: + " For example, this rule will strip JSESSIONID and its value from"
39: + " 'http://archive.org/index.html?"
40: + "JSESSIONID=DDDSSE233232333355FFSXXXXDSDSDS'. The resulting"
41: + " canonicalization returns 'http://archive.org/index.html'."
42: + " This rule strips JSESSIONID, ASPSESSIONID, PHPSESSID, and 'sid'"
43: + " session ids.";
44:
45: /**
46: * Example: jsessionid=999A9EF028317A82AC83F0FDFE59385A.
47: * Example: PHPSESSID=9682993c8daa2c5497996114facdc805.
48: */
49: private static final Pattern BASE_PATTERN = Pattern.compile("^(.+)"
50: + "(?:(?:(?:jsessionid)|(?:phpsessid))="
51: + "[0-9a-zA-Z]{32})(?:&(.*))?$", Pattern.CASE_INSENSITIVE);
52:
53: /**
54: * Example: sid=9682993c8daa2c5497996114facdc805.
55: * 'sid=' can be tricky but all sid= followed by 32 byte string
56: * so far seen have been session ids. Sid is a 32 byte string
57: * like the BASE_PATTERN only 'sid' is the tail of 'phpsessid'
58: * so have to have it run after the phpsessid elimination.
59: */
60: private static final Pattern SID_PATTERN = Pattern.compile("^(.+)"
61: + "(?:sid=[0-9a-zA-Z]{32})(?:&(.*))?$",
62: Pattern.CASE_INSENSITIVE);
63:
64: /**
65: * Example:ASPSESSIONIDAQBSDSRT=EOHBLBDDPFCLHKPGGKLILNAM.
66: */
67: private static final Pattern ASPSESSION_PATTERN = Pattern
68: .compile(
69: "^(.+)"
70: + "(?:ASPSESSIONID[a-zA-Z]{8}=[a-zA-Z]{24})(?:&(.*))?$",
71: Pattern.CASE_INSENSITIVE);
72:
73: public StripSessionIDs(String name) {
74: super (name, DESCRIPTION);
75: }
76:
77: public String canonicalize(String url, Object context) {
78: url = doStripRegexMatch(url, BASE_PATTERN.matcher(url));
79: url = doStripRegexMatch(url, SID_PATTERN.matcher(url));
80: url = doStripRegexMatch(url, ASPSESSION_PATTERN.matcher(url));
81: return url;
82: }
83: }
|