*
* @throws Exception
*/
public void testPolicyConfiguration() throws Exception
{
PolicyConfigurationFactory pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory();
PolicyConfiguration pc = pcf.getPolicyConfiguration("context-a", false);
EJBMethodPermission someEJB = new EJBMethodPermission("someEJB", null);
pc.addToExcludedPolicy(someEJB);
pc.commit();
Policy sysPolicy = Policy.getPolicy();
assertTrue("Policy isa DelegatingPolicy", sysPolicy instanceof DelegatingPolicy);
sysPolicy.refresh();
// Act like the ejb container and check a permission
PolicyContext.setContextID("context-a");
EJBMethodPermission methodX = new EJBMethodPermission("someEJB", "methodX,,int");
assertTrue("methodX denied", sysPolicy.implies(null, methodX) == false);
pc = pcf.getPolicyConfiguration("context-a", true);
pc.addToUncheckedPolicy(someEJB);
pc.commit();
sysPolicy.refresh();
assertTrue("methodX allowed", sysPolicy.implies(null, methodX) == true);
pc.delete();
pc = pcf.getPolicyConfiguration("context-a", false);
pc.addToRole("callerX", someEJB);
pc.commit();
sysPolicy.refresh();
SimplePrincipal[] callers = {new SimplePrincipal("callerX")};
ProtectionDomain pd = new ProtectionDomain(null, null, null, callers);