1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.security;
35
36 import java.util.Date;
37
38 import javax.servlet.http.HttpServletRequest;
39 import javax.servlet.http.HttpSession;
40
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import info.magnolia.context.MgnlContext;
44
45
46
47
48
49
50
51
52 public final class Lock {
53
54
55
56
57 private static Logger log = LoggerFactory.getLogger(Lock.class);
58
59
60
61
62 private static final String SESSION_LOCK = "mgnlSessionLock";
63
64
65
66
67 private static boolean isSystemLocked;
68
69
70
71
72 private static Date lockSetDate;
73
74
75
76
77 private Lock() {
78
79 }
80
81
82
83
84
85 public static void setSessionLock(HttpServletRequest request) {
86 log.info("Session lock enabled for user ( "
87 + MgnlContext.getUser().getName()
88 + " ) on "
89 + (new Date()).toString());
90
91 HttpSession httpsession = request.getSession(true);
92 httpsession.setAttribute(SESSION_LOCK, (new Date()).toString());
93 }
94
95
96
97
98
99
100 public static boolean isSessionLocked(HttpServletRequest request) {
101
102 if (request.getSession(true).getAttribute(Lock.SESSION_LOCK) != null) {
103 return true;
104 }
105 return false;
106 }
107
108
109
110
111
112 public static void resetSessionLock(HttpServletRequest request) {
113 if (!Lock.isSessionLocked(request)) {
114 if (log.isDebugEnabled()) {
115 log.debug("No Lock found to reset");
116 }
117 }
118 else {
119 if (log.isDebugEnabled()) {
120 log.debug("Resetting session lock");
121 }
122 Lock.isSystemLocked = false;
123 }
124
125 HttpSession httpsession = request.getSession(true);
126 httpsession.removeAttribute(Lock.SESSION_LOCK);
127 }
128
129
130
131
132 public static void setSystemLock() {
133 if (Lock.isSystemLocked()) {
134 if (log.isDebugEnabled()) {
135 log.debug("System lock exist, created on " + Lock.lockSetDate.toString());
136 }
137 }
138 else {
139 Lock.isSystemLocked = true;
140 Lock.lockSetDate = new Date();
141 if (log.isDebugEnabled()) {
142 log.debug("New System lock created on " + Lock.lockSetDate.toString() + " )");
143 }
144 }
145 }
146
147
148
149
150 public static void resetSystemLock() {
151 if (!Lock.isSystemLocked()) {
152 log.debug("No Lock found to reset");
153 }
154 else {
155 if (log.isDebugEnabled()) {
156 log.debug("Resetting system lock created on " + Lock.lockSetDate.toString());
157 }
158 Lock.isSystemLocked = false;
159 }
160 }
161
162
163
164
165
166 public static boolean isSystemLocked() {
167 return Lock.isSystemLocked;
168 }
169 }