1 13 package info.magnolia.cms.security; 14 15 import info.magnolia.cms.util.SimpleUrlPattern; 16 import info.magnolia.cms.util.UrlPattern; 17 18 import java.util.Hashtable ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 23 26 public final class SecureURI { 27 28 31 private static Map secureURIs = new Hashtable (); 32 33 private static Map unsecureURIs = new Hashtable (); 34 35 38 private SecureURI() { 39 } 41 42 public static Map listSecureURIs() { 43 Hashtable copy = new Hashtable (); 44 copy.putAll(secureURIs); 45 return copy; 46 } 47 48 public static Map listUnsecureURIs() { 49 Hashtable copy = new Hashtable (); 50 copy.putAll(unsecureURIs); 51 return copy; 52 } 53 54 57 public static void init() { 58 SecureURI.secureURIs.clear(); 59 SecureURI.unsecureURIs.clear(); 60 61 } 62 63 66 public static void reload() { 67 init(); 68 } 69 70 73 private static synchronized void addToList(String handle, Map map) { 74 UrlPattern pattern1 = new SimpleUrlPattern(handle); 75 map.put(handle, pattern1); 76 } 77 78 81 private static synchronized void deleteFromList(String handle, Map map) { 82 map.remove(handle); 83 } 84 85 88 public static void addSecure(String handle) { 89 SecureURI.addToList(handle, SecureURI.secureURIs); 90 } 91 92 95 public static void deleteSecure(String handle) { 96 SecureURI.deleteFromList(handle, SecureURI.secureURIs); 97 } 98 99 public static void addUnsecure(String handle) { 100 SecureURI.addToList(handle, SecureURI.unsecureURIs); 101 } 102 103 106 public static void deleteUnsecure(String handle) { 107 SecureURI.deleteFromList(handle, SecureURI.unsecureURIs); 108 } 109 110 115 public static boolean isProtected(String uri) { 116 return hasPattern(uri, SecureURI.secureURIs); 117 } 118 119 public static boolean isUnsecure(String uri) { 120 return hasPattern(uri, SecureURI.unsecureURIs); 121 } 122 123 129 public static boolean hasPattern(String uri, Map map) { 130 Iterator e = map.keySet().iterator(); 131 while (e.hasNext()) { 132 UrlPattern p = (UrlPattern) map.get(e.next()); 133 if (p.match(uri)) { 134 return true; 135 } 136 } 137 return false; 138 } 139 } 140 | Popular Tags |