1 28 29 package com.caucho.security; 30 31 import com.caucho.loader.EnvironmentClassLoader; 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.security.*; 36 import java.util.ArrayList ; 37 import java.util.logging.Logger ; 38 39 42 public class PolicyImpl extends Policy { 43 private static Logger _log; 44 private static L10N _L; 45 46 private static final PolicyImpl _policy = new PolicyImpl(); 47 48 private ClassLoader _systemClassLoader; 49 private Policy _parent; 50 51 private PolicyImpl() 52 { 53 _parent = Policy.getPolicy(); 54 _systemClassLoader = ClassLoader.getSystemClassLoader(); 55 } 56 57 public static PolicyImpl getPolicy() 58 { 59 return _policy; 60 } 61 62 public static void init() 63 { 64 Policy.setPolicy(_policy); 65 } 66 67 public PermissionCollection getPermissions(CodeSource codesource) 68 { 69 PermissionCollection perms = new Permissions(); 70 perms.add(new AllPermission()); 71 72 return perms; 73 } 74 75 public PermissionCollection getPermissions(ProtectionDomain domain) 76 { 77 PermissionCollection perms = new Permissions(); 78 perms.add(new AllPermission()); 79 80 return perms; 81 } 82 83 public boolean implies(ProtectionDomain domain, Permission permission) 84 { 85 89 90 ClassLoader loader = domain.getClassLoader(); 91 92 if (loader == _systemClassLoader) 93 return true; 94 95 if (true) 97 return true; 98 if (true && _parent != null) 99 return _parent.implies(domain, permission); 100 else if (true) 101 return true; 102 103 for (; loader != null; loader = loader.getParent()) { 104 if (loader instanceof EnvironmentClassLoader) { 105 EnvironmentClassLoader envLoader; 106 envLoader = (EnvironmentClassLoader) loader; 107 108 ArrayList <Permission> perms = envLoader.getPermissions(); 109 110 if (perms == null) 111 return _parent.implies(domain, permission); 112 113 for (int i = perms.size() - 1; i >= 0; i--) { 114 Permission perm = perms.get(i); 115 116 if (permission.implies(perm)) 117 return true; 118 } 119 120 return _parent.implies(domain, permission); 121 } 122 } 123 124 if (loader == null) 125 return true; 126 127 return true; 128 } 129 130 public void refresh() 131 { 132 } 133 134 private Logger log() 135 { 136 if (_log == null) 137 _log = Log.open(PolicyImpl.class); 138 139 return _log; 140 } 141 142 private L10N L() 143 { 144 if (_L == null) 145 _L = new L10N(PolicyImpl.class); 146 147 return _L; 148 } 149 150 public String toString() 151 { 152 return "PolicyImpl[]"; 153 } 154 } 155 | Popular Tags |