1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.org.iscream.cms.server.filter.plugins; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import uk.org.iscream.cms.server.filter.PluginFilter; |
6 |
|
|
import uk.org.iscream.cms.server.filter.*; |
7 |
|
|
import uk.org.iscream.cms.server.core.*; |
8 |
|
|
import uk.org.iscream.cms.server.util.*; |
9 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* This plugin is designed to check if the key in the |
13 |
|
|
* UDP packet is currently valid. |
14 |
|
|
* |
15 |
|
|
* @author $Author$ |
16 |
|
|
* @version $Id$ |
17 |
|
|
*/ |
18 |
|
|
public class KeyChecker__Plugin implements PluginFilter { |
19 |
|
|
|
20 |
|
|
//---FINAL ATTRIBUTES--- |
21 |
|
|
|
22 |
|
|
/** |
23 |
|
|
* The current CVS revision of this class |
24 |
|
|
*/ |
25 |
|
|
public final String REVISION = "$Revision: 1.1 $"; |
26 |
|
|
|
27 |
|
|
public final String DESC = "Checks the key attribute in the packet attributes. This key must be valid and current for the packet to be allowed through."; |
28 |
|
|
|
29 |
|
|
//---STATIC METHODS--- |
30 |
|
|
|
31 |
|
|
//---CONSTRUCTORS--- |
32 |
|
|
|
33 |
|
|
//---PUBLIC METHODS--- |
34 |
|
|
|
35 |
|
|
// apply the filter and return true if successful. |
36 |
|
|
public boolean runFilter(XMLPacket packet){ |
37 |
|
|
|
38 |
|
|
// only want to check data packets |
39 |
|
|
// any others will probably get filtered out further up the filter chain |
40 |
|
|
if(packet.getParam("packet.attributes.type").equals("data")) { |
41 |
|
|
String key = packet.getParam("packet.attributes.key"); |
42 |
|
|
// check to make sure the packet has a key |
43 |
|
|
if(key != null) { |
44 |
|
|
return KeyManager.getInstance().checkKey(packet.getParam("packet.attributes.machine_name"), key); |
45 |
|
|
} |
46 |
|
|
else { |
47 |
|
|
// if the packet doesn't have a key we'll see |
48 |
|
|
// whether or not we should allow it anyway... |
49 |
|
|
// default to enforcing host auth |
50 |
|
|
boolean enforceHostAuth = true; |
51 |
|
|
try { |
52 |
|
|
// try to get see what's in the config |
53 |
|
|
String enforce = ConfigurationProxy.getInstance().getProperty("Filter." + FilterMain.NAME, "Filter.EnforceHostAuth"); |
54 |
|
|
enforceHostAuth = (Integer.parseInt(enforce) == 1); |
55 |
|
|
} |
56 |
|
|
catch(PropertyNotFoundException e) { |
57 |
|
|
// if it's not set, not enforced |
58 |
|
|
_logger.write(toString(), Logger.WARNING, "EnforceHostAuth property not found: " + e); |
59 |
|
|
enforceHostAuth = false; |
60 |
|
|
} |
61 |
|
|
catch(NumberFormatException e) { |
62 |
|
|
// if it's not a number, not enforced |
63 |
|
|
_logger.write(toString(), Logger.WARNING, "EnforceHostAuth property malformed: " + e); |
64 |
|
|
enforceHostAuth = false; |
65 |
|
|
} |
66 |
|
|
// if enforceHostAuth is true we want to fail the packet |
67 |
|
|
// and vice-versa |
68 |
|
|
return !enforceHostAuth; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
// a good catchall, I guess |
73 |
|
|
//it's not a data in which case it should go through |
74 |
|
|
return true; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
/** |
78 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
79 |
|
|
* method to provide clean logging (every class should have this). |
80 |
|
|
* |
81 |
|
|
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
82 |
|
|
* to format the toString() |
83 |
|
|
* |
84 |
|
|
* @return the name of this class and its CVS revision |
85 |
|
|
*/ |
86 |
|
|
public String toString() { |
87 |
|
|
return FormatName.getName( |
88 |
|
|
_name, |
89 |
|
|
getClass().getName(), |
90 |
|
|
REVISION); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* return the String representation of what the filter does |
95 |
|
|
*/ |
96 |
|
|
public String getDescription(){ |
97 |
|
|
return DESC; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
//---PRIVATE METHODS--- |
101 |
|
|
|
102 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
103 |
|
|
|
104 |
|
|
//---ATTRIBUTES--- |
105 |
|
|
|
106 |
|
|
/** |
107 |
|
|
* This is the friendly identifier of the |
108 |
|
|
* component this class is running in. |
109 |
|
|
* eg, a Filter may be called "filter1", |
110 |
|
|
* If this class does not have an owning |
111 |
|
|
* component, a name from the configuration |
112 |
|
|
* can be placed here. This name could also |
113 |
|
|
* be changed to null for utility classes. |
114 |
|
|
*/ |
115 |
|
|
private String _name = FilterMain.NAME; |
116 |
|
|
|
117 |
|
|
/** |
118 |
|
|
* This holds a reference to the |
119 |
|
|
* system logger that is being used. |
120 |
|
|
*/ |
121 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
122 |
|
|
|
123 |
|
|
//---STATIC ATTRIBUTES--- |
124 |
|
|
|
125 |
|
|
} |