1 17 18 package org.apache.geronimo.security.jacc; 19 20 import java.security.CodeSource ; 21 import java.security.Permission ; 22 import java.security.PermissionCollection ; 23 import java.security.Policy ; 24 import java.security.ProtectionDomain ; 25 import javax.security.jacc.PolicyContext ; 26 import javax.security.jacc.PolicyContextException ; 27 28 29 32 public class GeronimoPolicy extends Policy { 33 private final Policy root; 34 private GeronimoPolicyConfigurationFactory factory; 35 private boolean loaded; 36 37 public GeronimoPolicy() { 38 String provider = System.getProperty("org.apache.geronimo.jacc.policy.provider"); 39 40 if (provider == null) { 41 root = Policy.getPolicy(); 42 } else { 43 try { 44 Object obj = Class.forName(provider).newInstance(); 45 if (obj instanceof Policy ) { 46 root = (Policy ) obj; 47 } else { 48 throw new RuntimeException (provider + "is not a type of java.security.Policy"); 49 } 50 } catch (InstantiationException e) { 51 throw new RuntimeException ("Unable to create an instance of " + provider, e); 52 } catch (IllegalAccessException e) { 53 throw new RuntimeException ("Unable to create an instance of " + provider, e); 54 } catch (ClassNotFoundException e) { 55 throw new RuntimeException ("Unable to create an instance of " + provider, e); 56 } 57 } 58 root.refresh(); 59 } 60 61 public PermissionCollection getPermissions(CodeSource codesource) { 62 63 if (root != null) return root.getPermissions(codesource); 64 65 return null; 66 } 67 68 public void refresh() { 69 } 70 71 public boolean implies(ProtectionDomain domain, Permission permission) { 72 73 if (!loaded) { 74 factory = GeronimoPolicyConfigurationFactory.getSingleton(); 75 loaded = true; 76 } 77 78 if (factory != null) { 79 String contextID = PolicyContext.getContextID(); 80 if (contextID != null) { 81 try { 82 GeronimoPolicyConfiguration configuration = factory.getGeronimoPolicyConfiguration(contextID); 83 84 if (configuration.inService()) { 85 if (configuration.implies(domain, permission)) return true; 86 } else { 87 return false; 88 } 89 } catch (PolicyContextException e) { 90 } 91 } 92 } 93 if (root != null) return root.implies(domain, permission); 94 95 return false; 96 } 97 } 98 | Popular Tags |