KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > processor > AccessControlList


1 package com.openinventions.webappfilter.processor;
2
3 import com.openinventions.metaframework.*;
4 import org.apache.commons.logging.*;
5
6 public class AccessControlList implements Processor {
7     private static final Log log = LogFactory.getLog(AccessControlList.class);
8     private Element acl = null;
9     
10     public void process(State state, Element context) throws Exception JavaDoc {
11         ElementFactory factory = (ElementFactory) state.get("com.openinventions.metaframework.ElementFactory");
12         String JavaDoc mode = context.getValue("@mode");
13         String JavaDoc file = context.getValue("file");
14         file = (String JavaDoc) state.get("rootDir") + "/" + file;
15
16         if (mode.equals("init")) {
17             log.error("init " + file);
18             acl = factory.read(file);
19         } else if (mode.equals("destroy")) {
20             log.error("destroy " + file);
21             factory.write(file, acl);
22         } else if (mode.equals("ban")) {
23             Element request = (Element) state.get("req");
24             log.error("ban " + request.getValue("ip"));
25             acl.setValue("/deny-list/deny/match[xpath='request/ip']/string", request.getValue("ip"));
26         } else if (mode.equals("reject")) {
27             Element request = (Element) state.get("req");
28             Element response = (Element) state.get("res");
29             
30             if (log.isDebugEnabled()) {
31                 log.debug("acl =" + request.getValue("ip") + "=" + acl.isExists("/deny-list/deny/match[xpath='request/ip'][string='" + request.getValue("ip") + "']") + "=" + factory.toString(acl));
32             }
33             
34             if (acl.isExists("/deny-list/deny/match[xpath='request/ip'][string='" + request.getValue("ip") + "']")) {
35                 response.setValue("body", "<html><body>You have been rejected from this website.</body></html>");
36                 state.set("filterDirection", "backward");
37             }
38         } else {
39             log.error("Mode not set. Is this init or destory or something else? " + mode);
40             return;
41         }
42     }
43 }
44 /* ====================================================================
45  * The webappfilter License, Version 1.1
46  *
47  * Copyright (c) 2002 Ivar Chan. All rights
48  * reserved.
49  *
50  * Redistribution and use in source and binary forms, with or without
51  * modification, are permitted provided that the following conditions
52  * are met:
53  *
54  * 1. Redistributions of source code must retain the above copyright
55  * notice, this list of conditions and the following disclaimer.
56  *
57  * 2. Redistributions in binary form must reproduce the above copyright
58  * notice, this list of conditions and the following disclaimer in
59  * the documentation and/or other materials provided with the
60  * distribution.
61  *
62  * 3. The end-user documentation included with the redistribution,
63  * if any, must include the following acknowledgment:
64  * "This product includes software developed by
65  * Ivar Chan (http://www.openinventions.com/webappfilter/)."
66  * Alternately, this acknowledgment may appear in the software itself,
67  * if and wherever such third-party acknowledgments normally appear.
68  *
69  * 4. The name "webappfilter" must not be used to endorse or promote products
70  * derived from this software without prior written permission. For
71  * written permission, please contact ivarchan@acm.org.
72  *
73  * 5. Products derived from this software may not be called "webappfilter",
74  * nor may "webappfilter" appear in their name, without
75  * prior written permission of Ivar Chan.
76  *
77  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
78  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
80  * DISCLAIMED. IN NO EVENT SHALL THE IVAR CHAN BE LIABLE FOR ANY
81  * DIRECT, INDIRECT, INCIDENTAL,
82  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
84  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
85  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
86  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
87  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88  * SUCH DAMAGE.
89  * ====================================================================
90  *
91  * This software consists of voluntary contributions made by many
92  * individuals. For more information on webappfilter, please see
93  * <http://www.openinventions/webappfilter/>.
94  */

95
Popular Tags