1 25 26 package org.objectweb.easybeans.security.permissions; 27 28 import java.net.URL ; 29 import java.security.Policy ; 30 31 import javax.security.jacc.PolicyConfiguration ; 32 import javax.security.jacc.PolicyConfigurationFactory ; 33 import javax.security.jacc.PolicyContextException ; 34 35 import org.objectweb.easybeans.api.PermissionManagerException; 36 37 41 public abstract class AbsPermissionManager { 42 43 46 private PolicyConfiguration policyConfiguration = null; 47 48 51 private URL contextIdURL = null; 52 53 56 private String contextId = null; 57 58 61 private static Policy policy = null; 62 63 68 public AbsPermissionManager(final URL contextIdURL) throws PermissionManagerException { 69 this(contextIdURL, true); 70 } 71 72 78 public AbsPermissionManager(final URL contextIdURL, final boolean remove) throws PermissionManagerException { 79 this.contextIdURL = contextIdURL; 80 this.contextId = contextIdURL.toString(); 81 82 PolicyConfigurationFactory policyConfigurationFactory = null; 83 try { 85 policyConfigurationFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory(); 86 } catch (ClassNotFoundException e) { 87 throw new PermissionManagerException("Error when trying to get the PolicyConfigurationFactory object", e); 88 } catch (PolicyContextException e) { 89 throw new PermissionManagerException("Error when trying to get the PolicyConfigurationFactory object", e); 90 } 91 try { 92 this.policyConfiguration = policyConfigurationFactory.getPolicyConfiguration(contextId, remove); 93 } catch (PolicyContextException pce) { 94 throw new PermissionManagerException("Error when trying to get the PolicyConfiguration object with contextId '" 95 + contextId + "'.'", pce); 96 } 97 98 policy = Policy.getPolicy(); 100 } 101 102 106 public void delete() throws PermissionManagerException { 107 108 try { 109 policyConfiguration.delete(); 110 } catch (PolicyContextException pce) { 111 throw new PermissionManagerException("Cannot delete policyConfiguration object", pce); 112 } 113 policyConfiguration = null; 114 115 policy.refresh(); 117 } 118 119 123 public void commit() throws PermissionManagerException { 124 try { 125 policyConfiguration.commit(); 126 policy.refresh(); 127 } catch (PolicyContextException pce) { 128 throw new PermissionManagerException("Cannot commit configuration", pce); 129 } 130 } 131 132 135 protected static Policy getPolicy() { 136 return policy; 137 } 138 139 142 protected String getContextId() { 143 return contextId; 144 } 145 146 149 protected void setContextId(final String contextId) { 150 this.contextId = contextId; 151 } 152 153 156 protected PolicyConfiguration getPolicyConfiguration() { 157 return policyConfiguration; 158 } 159 160 163 protected void setPolicyConfiguration(final PolicyConfiguration policyConfiguration) { 164 this.policyConfiguration = policyConfiguration; 165 } 166 167 170 protected URL getContextIdURL() { 171 return contextIdURL; 172 } 173 } 174 | Popular Tags |