KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > security > Listener


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.security;
14
15 import java.util.Map JavaDoc;
16
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18
19
20 /**
21  * Listener could be used to check for the request source/types and match it with the allowed sources and types This is
22  * helpful in restricting any authoring or publishing from unwanted sources.
23  * @author Sameer Charles
24  * @version 1.1
25  */

26 public final class Listener {
27
28     /**
29      * Utility class, don't instantiate.
30      */

31     private Listener() {
32         // unused
33
}
34
35     /**
36      * Weather current request have proper access of the method requested.
37      * @return boolean
38      */

39     public static boolean isAllowed(HttpServletRequest JavaDoc req) {
40         if (Listener.isIPAllowed(req)) {
41             return true;
42         }
43         return false;
44     }
45
46     /**
47      * weather IP is in the available listener list OR "*".
48      * @return boolean
49      */

50     private static boolean isIPAllowed(HttpServletRequest JavaDoc req) {
51         try {
52             Map JavaDoc access = info.magnolia.cms.beans.config.Listener.getInfo(req.getRemoteAddr());
53             return (access.get(req.getMethod().toLowerCase()) != null);
54         }
55         catch (Exception JavaDoc e) {
56         }
57         try {
58             /* probably there is a mapping for "*" */
59             Map JavaDoc access = info.magnolia.cms.beans.config.Listener.getInfo("*"); //$NON-NLS-1$
60
return (access.get(req.getMethod().toLowerCase()) != null);
61         }
62         catch (Exception JavaDoc e) {
63             return false;
64         }
65     }
66 }
67
Popular Tags