1 7 8 package javax.crypto; 9 10 import java.security.*; 11 import java.util.Enumeration; 12 import java.util.Vector; 13 14 26 27 final class CryptoAllPermission extends CryptoPermission { 28 29 private static final long serialVersionUID = -5066513634293192112L; 30 31 static final String ALG_NAME = "CryptoAllPermission"; 33 static final CryptoAllPermission INSTANCE = 34 new CryptoAllPermission(); 35 36 private CryptoAllPermission() { 37 super(ALG_NAME); 38 } 39 40 49 public boolean implies(Permission p) { 50 return (p instanceof CryptoPermission); 51 } 52 53 61 public boolean equals(Object obj) { 62 return (obj == INSTANCE); 63 } 64 65 71 public int hashCode() { 72 return 1; 73 } 74 75 83 public PermissionCollection newPermissionCollection() { 84 return new CryptoAllPermissionCollection(); 85 } 86 } 87 88 100 final class CryptoAllPermissionCollection extends PermissionCollection 101 implements java.io.Serializable 102 { 103 104 private static final long serialVersionUID = 7450076868380144072L; 105 106 private boolean all_allowed; 108 109 112 CryptoAllPermissionCollection() { 113 all_allowed = false; 114 } 115 116 124 public void add(Permission permission) 125 { 126 if (isReadOnly()) 127 throw new SecurityException("attempt to add a Permission to " + 128 "a readonly PermissionCollection"); 129 130 if (permission != CryptoAllPermission.INSTANCE) 131 return; 132 133 all_allowed = true; 134 } 135 136 145 public boolean implies(Permission permission) 146 { 147 if (!(permission instanceof CryptoPermission)) { 148 return false; 149 } 150 return all_allowed; 151 } 152 153 159 public Enumeration elements() { 160 Vector v = new Vector(1); 161 if (all_allowed) v.add(CryptoAllPermission.INSTANCE); 162 return v.elements(); 163 } 164 } 165 166 | Popular Tags |