1 13 package info.magnolia.cms.security; 14 15 import java.util.Date ; 16 import java.util.Hashtable ; 17 import java.util.Map ; 18 19 import javax.servlet.http.HttpServletRequest ; 20 21 import org.apache.log4j.Logger; 22 23 24 28 public final class Lock { 29 30 private static final String SESSION_LOCK = "magnolia:sessionLock"; 32 private static Logger log = Logger.getLogger(Lock.class); 33 34 private static boolean isSystemLocked; 35 36 private static Date lockSetDate; 37 38 private static Map lockedHierarchyList = new Hashtable (); 39 40 43 private Lock() { 44 } 46 47 public static void setSessionLock(HttpServletRequest request) { 48 log.info("Session lock enabled for user ( " + Authenticator.getUserId(request) + " ) on " + (new Date ()).toString()); 51 request.getSession().setAttribute(SESSION_LOCK, (new Date ()).toString()); 52 } 53 54 public static boolean isSessionLocked(HttpServletRequest 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 path) { 62 Lock.lockedHierarchyList.put(path, ""); } 64 65 public static void resetHierarchyLock(String path) { 66 Lock.lockedHierarchyList.remove(path); 67 } 68 69 public static boolean isHierarchyLocked(String 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()); } 77 else { 78 Lock.isSystemLocked = true; 79 Lock.lockSetDate = new Date (); 80 log.info("New System lock created on " + Lock.lockSetDate.toString() + " )"); } 82 } 83 84 public static void resetSystemLock() { 85 if (!Lock.isSystemLocked()) { 86 log.info("No Lock found to reset"); } 88 else { 89 log.info("Resetting system lock created on " + Lock.lockSetDate.toString()); Lock.isSystemLocked = false; 91 } 92 } 93 94 public static boolean isSystemLocked() { 95 return Lock.isSystemLocked; 96 } 97 } 98 | Popular Tags |