KickJava   Java API By Example, From Geeks To Geeks.

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


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-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.security;
14
15 import java.util.Date JavaDoc;
16 import java.util.Hashtable JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20
21 import org.apache.log4j.Logger;
22
23
24 /**
25  * @author Sameer Charles
26  * @version 2.0
27  */

28 public final class Lock {
29
30     private static final String JavaDoc SESSION_LOCK = "magnolia:sessionLock"; //$NON-NLS-1$
31

32     private static Logger log = Logger.getLogger(Lock.class);
33
34     private static boolean isSystemLocked;
35
36     private static Date JavaDoc lockSetDate;
37
38     private static Map JavaDoc lockedHierarchyList = new Hashtable JavaDoc();
39
40     /**
41      * Utility class, don't instantiate.
42      */

43     private Lock() {
44         // unused
45
}
46
47     public static void setSessionLock(HttpServletRequest JavaDoc request) {
48         log.info("Session lock enabled for user ( " //$NON-NLS-1$
49
+ Authenticator.getUserId(request) + " ) on " //$NON-NLS-1$
50
+ (new Date JavaDoc()).toString());
51         request.getSession().setAttribute(SESSION_LOCK, (new Date JavaDoc()).toString());
52     }
53
54     public static boolean isSessionLocked(HttpServletRequest JavaDoc request) {
55         if (request.getSession().getAttribute(Lock.SESSION_LOCK) != null) {
56             return true;
57         }
58         return false;
59     }
60
61     public static void setHierarchyLock(String JavaDoc path) {
62         Lock.lockedHierarchyList.put(path, ""); //$NON-NLS-1$
63
}
64
65     public static void resetHierarchyLock(String JavaDoc path) {
66         Lock.lockedHierarchyList.remove(path);
67     }
68
69     public static boolean isHierarchyLocked(String JavaDoc path) {
70         return (Lock.lockedHierarchyList.get(path) != null);
71     }
72
73     public static void setSystemLock() {
74         if (Lock.isSystemLocked()) {
75             log.info("System lock exist, created on " + Lock.lockSetDate.toString()); //$NON-NLS-1$
76
}
77         else {
78             Lock.isSystemLocked = true;
79             Lock.lockSetDate = new Date JavaDoc();
80             log.info("New System lock created on " + Lock.lockSetDate.toString() + " )"); //$NON-NLS-1$ //$NON-NLS-2$
81
}
82     }
83
84     public static void resetSystemLock() {
85         if (!Lock.isSystemLocked()) {
86             log.info("No Lock found to reset"); //$NON-NLS-1$
87
}
88         else {
89             log.info("Resetting system lock created on " + Lock.lockSetDate.toString()); //$NON-NLS-1$
90
Lock.isSystemLocked = false;
91         }
92     }
93
94     public static boolean isSystemLocked() {
95         return Lock.isSystemLocked;
96     }
97 }
98
Popular Tags