AbsPermissionManager.java

00001 
00027 package org.objectweb.jonas_lib.security;
00028 
00029 import java.security.Policy;
00030 
00031 import javax.security.jacc.PolicyConfiguration;
00032 import javax.security.jacc.PolicyConfigurationFactory;
00033 import javax.security.jacc.PolicyContextException;
00034 
00035 import org.objectweb.jonas.security.jacc.JPolicyUserRoleMapping;
00036 
00042 public abstract class AbsPermissionManager {
00043 
00047     private PolicyConfiguration policyConfiguration = null;
00048 
00052     private String contextId = null;
00053 
00057     private static Policy policy = null;
00058 
00064     public AbsPermissionManager(String contextId) throws PermissionManagerException {
00065         this.contextId = contextId;
00066 
00067         PolicyConfigurationFactory policyConfigurationFactory = null;
00068         // Init JACC
00069         try {
00070             policyConfigurationFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
00071         } catch (Exception e) {
00072             throw new PermissionManagerException("Error when trying to get the PolicyConfigurationFactory object : '"
00073                     + e.getMessage() + "'.");
00074         }
00075         try {
00076             this.policyConfiguration = policyConfigurationFactory.getPolicyConfiguration(contextId, true);
00077         } catch (PolicyContextException pce) {
00078             throw new PermissionManagerException(
00079                     "Error when trying to get the PolicyConfiguration object with contextId '" + contextId + "' : "
00080                             + pce.getMessage());
00081         }
00082 
00083         // Policy to use
00084         policy = Policy.getPolicy();
00085     }
00086 
00091     public void delete() throws PermissionManagerException {
00092         resetDeploymentDesc();
00093 
00094         try {
00095             policyConfiguration.delete();
00096         } catch (PolicyContextException pce) {
00097             throw new PermissionManagerException("Can't delete policyConfiguration object", pce);
00098         }
00099         policyConfiguration = null;
00100 
00101         // Also delete user-to-role mapping
00102         JPolicyUserRoleMapping.removeUserToRoleMapping(contextId);
00103 
00104         // Policy need to be refresh
00105         policy.refresh();
00106     }
00107 
00112     public void commit() throws PermissionManagerException {
00113         try {
00114             policyConfiguration.commit();
00115             policy.refresh();
00116         } catch (PolicyContextException pce) {
00117             throw new PermissionManagerException("Can't commit configuration", pce);
00118         }
00119     }
00120 
00124     protected abstract void resetDeploymentDesc();
00125 
00129     protected static Policy getPolicy() {
00130         return policy;
00131     }
00132 
00136     protected static void setPolicy(Policy policy) {
00137         AbsPermissionManager.policy = policy;
00138     }
00139 
00143     protected String getContextId() {
00144         return contextId;
00145     }
00146 
00150     protected void setContextId(String contextId) {
00151         this.contextId = contextId;
00152     }
00153 
00157     protected PolicyConfiguration getPolicyConfiguration() {
00158         return policyConfiguration;
00159     }
00160 
00164     protected void setPolicyConfiguration(PolicyConfiguration policyConfiguration) {
00165         this.policyConfiguration = policyConfiguration;
00166     }
00167 
00168 }

Generated on Tue Feb 15 15:05:56 2005 for JOnAS by  doxygen 1.3.9.1