1 package org.hibernate.secure; 3 4 import java.util.StringTokenizer ; 5 6 import javax.security.jacc.EJBMethodPermission ; 7 import javax.security.jacc.PolicyConfiguration ; 8 import javax.security.jacc.PolicyConfigurationFactory ; 9 import javax.security.jacc.PolicyContextException ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.hibernate.HibernateException; 14 15 20 public class JACCConfiguration { 21 22 private static final Log log = LogFactory.getLog( JACCConfiguration.class ); 23 24 private final PolicyConfiguration policyConfiguration; 25 26 public JACCConfiguration(String contextId) throws HibernateException { 27 try { 28 policyConfiguration = PolicyConfigurationFactory 29 .getPolicyConfigurationFactory() 30 .getPolicyConfiguration( contextId, false ); 31 } 32 catch (ClassNotFoundException cnfe) { 33 throw new HibernateException( "JACC provider class not found", cnfe ); 34 } 35 catch (PolicyContextException pce) { 36 throw new HibernateException( "policy context exception occurred", pce ); 37 } 38 } 39 40 public void addPermission(String role, String entityName, String action) { 41 42 if ( action.equals( "*" ) ) { 43 action = "insert,read,update,delete"; 44 } 45 46 StringTokenizer tok = new StringTokenizer ( action, "," ); 47 48 while ( tok.hasMoreTokens() ) { 49 String methodName = tok.nextToken().trim(); 50 EJBMethodPermission permission = new EJBMethodPermission ( 51 entityName, 52 methodName, 53 null, null ); 56 57 if ( log.isDebugEnabled() ) { 58 log.debug( "adding permission to role " + role + ": " + permission ); 59 } 60 try { 61 policyConfiguration.addToRole( role, permission ); 62 } 63 catch (PolicyContextException pce) { 64 throw new HibernateException( "policy context exception occurred", pce ); 65 } 66 } 67 } 68 69 } 70 | Popular Tags |