1 26 27 package org.objectweb.jonas_lib.security; 28 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.jonas.security.jacc.JPolicyUserRoleMapping; 36 37 42 public abstract class AbsPermissionManager { 43 44 47 private PolicyConfiguration policyConfiguration = null; 48 49 52 private String contextId = null; 53 54 57 private static Policy policy = null; 58 59 64 public AbsPermissionManager(String contextId) throws PermissionManagerException { 65 this.contextId = contextId; 66 67 PolicyConfigurationFactory policyConfigurationFactory = null; 68 try { 70 policyConfigurationFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory(); 71 } catch (Exception e) { 72 throw new PermissionManagerException("Error when trying to get the PolicyConfigurationFactory object : '" 73 + e.getMessage() + "'."); 74 } 75 try { 76 this.policyConfiguration = policyConfigurationFactory.getPolicyConfiguration(contextId, true); 77 } catch (PolicyContextException pce) { 78 throw new PermissionManagerException( 79 "Error when trying to get the PolicyConfiguration object with contextId '" + contextId + "' : " 80 + pce.getMessage()); 81 } 82 83 policy = Policy.getPolicy(); 85 } 86 87 91 public void delete() throws PermissionManagerException { 92 resetDeploymentDesc(); 93 94 try { 95 policyConfiguration.delete(); 96 } catch (PolicyContextException pce) { 97 throw new PermissionManagerException("Can't delete policyConfiguration object", pce); 98 } 99 policyConfiguration = null; 100 101 JPolicyUserRoleMapping.removeUserToRoleMapping(contextId); 103 104 policy.refresh(); 106 } 107 108 112 public void commit() throws PermissionManagerException { 113 try { 114 policyConfiguration.commit(); 115 policy.refresh(); 116 } catch (PolicyContextException pce) { 117 throw new PermissionManagerException("Can't commit configuration", pce); 118 } 119 } 120 121 124 protected abstract void resetDeploymentDesc(); 125 126 129 protected static Policy getPolicy() { 130 return policy; 131 } 132 133 136 protected static void setPolicy(Policy policy) { 137 AbsPermissionManager.policy = policy; 138 } 139 140 143 protected String getContextId() { 144 return contextId; 145 } 146 147 150 protected void setContextId(String contextId) { 151 this.contextId = contextId; 152 } 153 154 157 protected PolicyConfiguration getPolicyConfiguration() { 158 return policyConfiguration; 159 } 160 161 164 protected void setPolicyConfiguration(PolicyConfiguration policyConfiguration) { 165 this.policyConfiguration = policyConfiguration; 166 } 167 168 } | Popular Tags |