Source code: com/obinary/cms/admin/Listener.java
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-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11 *
12 * */
13
14
15
16
17 package com.obinary.cms.admin;
18
19
20 import com.obinary.cms.beans.ListenerInfo;
21
22 import javax.servlet.http.HttpServletRequest;
23 import java.util.Hashtable;
24
25
26 /**
27 * User: sameercharles
28 * Date: Oct 12, 2003
29 * Time: 10:20:59 AM
30 * @author Sameer Charles
31 * @version 1.0
32 */
33
34
35 /**
36 * <p>Listener could be used to check for the request source/types and match it with
37 * the allowed sources and types
38 * This is helpful in restricting any authoring or publishing from unwanted sources
39 * </p>
40 *
41 */
42 public class Listener {
43
44
45
46
47
48
49 /**
50 * <p>weather current request have proper access of the method requested</p>
51 *
52 * @return boolean
53 */
54 public static boolean isAllowed (HttpServletRequest req) {
55 if (Listener.isIPAllowed(req))
56 return true;
57 return false;
58 }
59
60
61
62 /**
63 * <p>weather IP is in the available listener list OR "*"</p>
64 *
65 * @return boolean
66 */
67 private static boolean isIPAllowed(HttpServletRequest req) {
68 try {
69 Hashtable access = ListenerInfo.getInfo(req.getRemoteAddr());
70 access.get(req.getMethod());
71 return true;
72 } catch (Exception e) {}
73 try {
74 /* probably there is a mapping for "*" */
75 Hashtable access = ListenerInfo.getInfo("*");
76 access.get(req.getMethod());
77 return true;
78 } catch (Exception e) {
79 return false;
80 }
81 }
82
83
84
85
86
87 }