1 9 10 32 33 package java.security; 34 35 import java.io.Serializable ; 36 import java.util.Enumeration ; 37 import java.util.Hashtable ; 38 39 final class BasicPermissionCollection extends PermissionCollection implements Serializable { 40 41 private Hashtable permissions; 42 private boolean all_allowed; 43 44 public BasicPermissionCollection() { 45 permissions = new Hashtable ( 11 ); 46 all_allowed = false; 47 } 48 49 public void add(Permission permission) { 50 if( !( permission instanceof BasicPermission ) ) { 51 throw new IllegalArgumentException ( "invalid permission: " + permission ); 52 } 53 BasicPermission basicpermission = (BasicPermission )permission; 54 permissions.put( basicpermission.getName(), permission ); 55 if( !all_allowed && basicpermission.getName().equals( "*" ) ) { 56 all_allowed = true; 57 } 58 } 59 60 public Enumeration elements() { 61 return permissions.elements(); 62 } 63 64 public boolean implies(Permission permission) { 65 if( !( permission instanceof BasicPermission ) ) { 66 return false; 67 } 68 BasicPermission basicpermission = (BasicPermission )permission; 69 if( all_allowed ) { 70 return true; 71 } 72 String s = basicpermission.getName(); 73 Permission permission1 = (Permission )permissions.get( s ); 74 if ( permission1 != null ) { 75 return permission1.implies( permission ); 76 } 77 int i; 78 for( int j = s.length() - 1; ( i = s.lastIndexOf( ".", j ) ) != -1; j = i - 1 ) { 79 s = s.substring( 0, i + 1 ) + "*"; 80 Permission permission2 = (Permission )permissions.get( s ); 81 if( permission2 != null ) { 82 return permission2.implies( permission ); 83 } 84 } 85 86 return false; 87 } 88 89 } 90 | Popular Tags |