ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/plugins/KeyChecker__Plugin.java
Revision: 1.2
Committed: Sat May 18 18:16:02 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.1: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.2 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 tdb 1.1 //---PACKAGE DECLARATION---
21     package uk.org.iscream.cms.server.filter.plugins;
22    
23     //---IMPORTS---
24     import uk.org.iscream.cms.server.filter.PluginFilter;
25     import uk.org.iscream.cms.server.filter.*;
26     import uk.org.iscream.cms.server.core.*;
27     import uk.org.iscream.cms.server.util.*;
28     import uk.org.iscream.cms.server.componentmanager.*;
29    
30     /**
31     * This plugin is designed to check if the key in the
32     * UDP packet is currently valid.
33     *
34 tdb 1.2 * @author $Author: tdb $
35     * @version $Id: KeyChecker__Plugin.java,v 1.1 2002/03/21 17:44:51 tdb Exp $
36 tdb 1.1 */
37     public class KeyChecker__Plugin implements PluginFilter {
38    
39     //---FINAL ATTRIBUTES---
40    
41     /**
42     * The current CVS revision of this class
43     */
44     public final String REVISION = "$Revision: 1.1 $";
45    
46     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.";
47    
48     //---STATIC METHODS---
49    
50     //---CONSTRUCTORS---
51    
52     //---PUBLIC METHODS---
53    
54     // apply the filter and return true if successful.
55     public boolean runFilter(XMLPacket packet){
56    
57     // only want to check data packets
58     // any others will probably get filtered out further up the filter chain
59     if(packet.getParam("packet.attributes.type").equals("data")) {
60     String key = packet.getParam("packet.attributes.key");
61     // check to make sure the packet has a key
62     if(key != null) {
63     return KeyManager.getInstance().checkKey(packet.getParam("packet.attributes.machine_name"), key);
64     }
65     else {
66     // if the packet doesn't have a key we'll see
67     // whether or not we should allow it anyway...
68     // default to enforcing host auth
69     boolean enforceHostAuth = true;
70     try {
71     // try to get see what's in the config
72     String enforce = ConfigurationProxy.getInstance().getProperty("Filter." + FilterMain.NAME, "Filter.EnforceHostAuth");
73     enforceHostAuth = (Integer.parseInt(enforce) == 1);
74     }
75     catch(PropertyNotFoundException e) {
76     // if it's not set, not enforced
77     _logger.write(toString(), Logger.WARNING, "EnforceHostAuth property not found: " + e);
78     enforceHostAuth = false;
79     }
80     catch(NumberFormatException e) {
81     // if it's not a number, not enforced
82     _logger.write(toString(), Logger.WARNING, "EnforceHostAuth property malformed: " + e);
83     enforceHostAuth = false;
84     }
85     // if enforceHostAuth is true we want to fail the packet
86     // and vice-versa
87     return !enforceHostAuth;
88     }
89     }
90    
91     // a good catchall, I guess
92     //it's not a data in which case it should go through
93     return true;
94     }
95    
96     /**
97     * Overrides the {@link java.lang.Object#toString() Object.toString()}
98     * method to provide clean logging (every class should have this).
99     *
100     * This uses the uk.org.iscream.cms.server.util.NameFormat class
101     * to format the toString()
102     *
103     * @return the name of this class and its CVS revision
104     */
105     public String toString() {
106     return FormatName.getName(
107     _name,
108     getClass().getName(),
109     REVISION);
110     }
111    
112     /**
113     * return the String representation of what the filter does
114     */
115     public String getDescription(){
116     return DESC;
117     }
118    
119     //---PRIVATE METHODS---
120    
121     //---ACCESSOR/MUTATOR METHODS---
122    
123     //---ATTRIBUTES---
124    
125     /**
126     * This is the friendly identifier of the
127     * component this class is running in.
128     * eg, a Filter may be called "filter1",
129     * If this class does not have an owning
130     * component, a name from the configuration
131     * can be placed here. This name could also
132     * be changed to null for utility classes.
133     */
134     private String _name = FilterMain.NAME;
135    
136     /**
137     * This holds a reference to the
138     * system logger that is being used.
139     */
140     private Logger _logger = ReferenceManager.getInstance().getLogger();
141    
142     //---STATIC ATTRIBUTES---
143    
144     }