1 9 package org.jboss.portal.test.core.security; 10 11 import java.security.Permission ; 12 import java.util.Set ; 13 import java.util.regex.Matcher ; 14 import java.util.regex.Pattern ; 15 16 22 public class PortalPermission extends Permission 23 { 24 private boolean matcher; 26 27 private int hash; 29 private String actions; 30 private Set levelSet; 31 32 private Pattern [] patterns; 34 private Set impliedLevelSet; 35 36 private String [] test; 38 39 public PortalPermission(String [] test) throws IllegalArgumentException 40 { 41 super(toName(test)); 42 53 } 54 55 public PortalPermission(String name, String actions) 56 { 57 super(name); 58 if (name == null) 59 { 60 throw new IllegalArgumentException ("name must not be null"); 61 } 62 if (actions == null) 63 { 64 throw new IllegalArgumentException ("actions must not be null"); 65 } 66 94 } 95 96 public boolean equals(Object obj) 97 { 98 if (obj == this) 99 { 100 return true; 101 } 102 if (obj instanceof PortalPermission) 103 { 104 PortalPermission other = (PortalPermission)obj; 105 106 if (matcher) 107 { 108 if (other.patterns.length != patterns.length) 110 { 111 return false; 112 } 113 114 for (int i = 0;i < patterns.length;i++) 116 { 117 if (patterns[i].equals(other.patterns[i])) 118 { 119 return false; 120 } 121 } 122 123 return impliedLevelSet.equals(other.impliedLevelSet); 125 } 126 else 127 { 128 if (other.test.length != test.length) 130 { 131 return false; 132 } 133 134 for (int i = 0;i < test.length;i++) 136 { 137 if (test[i].equals(other.test[i])) 138 { 139 return false; 140 } 141 } 142 143 return levelSet.equals(other.levelSet); 145 } 146 } 147 return false; 148 } 149 150 public int hashCode() 151 { 152 183 return hash; 184 } 185 186 public String getActions() 187 { 188 219 return actions; 220 } 221 222 public boolean implies(Permission permission) 223 { 224 if (permission instanceof PortalPermission) 225 { 226 PortalPermission other = (PortalPermission)permission; 227 228 if (other.matcher) 230 { 231 return false; 232 } 233 234 if (other.test.length > patterns.length) 236 { 237 return false; 238 } 239 240 for (int i = 0;i < other.test.length;i++) 242 { 243 Pattern pattern = patterns[i]; 244 Matcher matcher = pattern.matcher(other.test[i]); 245 if (!matcher.matches()) 246 { 247 return false; 248 } 249 } 250 251 return impliedLevelSet.containsAll(other.levelSet); 253 } 254 return false; 255 } 256 257 private static String toName(String [] test) throws IllegalArgumentException 258 { 259 if (test == null) 260 { 261 throw new IllegalArgumentException ("test array cannot be null"); 262 } 263 StringBuffer buffer = new StringBuffer (); 264 for (int i = 0;i < test.length;i++) 265 { 266 if (i > 0) 267 { 268 buffer.append(":"); 269 } 270 String s = test[i]; 271 if (s == null) 272 { 273 throw new IllegalArgumentException ("test array item #" + i + " cannot be null"); 274 } 275 buffer.append(s); 276 } 277 return buffer.toString(); 278 } 279 } 280 | Popular Tags |