1 22 package org.jboss.test.web.security.jacc; 23 24 import java.security.Policy ; 25 import java.security.ProtectionDomain ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import javax.security.jacc.PolicyConfiguration ; 29 import javax.security.jacc.PolicyContext ; 30 import javax.security.jacc.WebResourcePermission ; 31 32 import junit.framework.TestCase; 33 import org.jboss.metadata.WebMetaData; 34 import org.jboss.metadata.WebSecurityMetaData; 35 import org.jboss.security.SimplePrincipal; 36 import org.jboss.security.jacc.DelegatingPolicy; 37 import org.jboss.security.jacc.JBossPolicyConfigurationFactory; 38 import org.jboss.web.WebPermissionMapping; 39 40 45 public class DataWebConstraintsUnitTestCase extends TestCase 46 { 47 public void testUncheckedExact() throws Exception 48 { 49 Policy p = Policy.getPolicy(); 50 SimplePrincipal[] caller = null; 51 ProtectionDomain pd = new ProtectionDomain (null, null, null, caller); 52 53 WebResourcePermission wrp = new WebResourcePermission ("/", "GET"); 54 assertTrue("/ GET", p.implies(pd, wrp)); 55 wrp = new WebResourcePermission ("/", "POST"); 56 assertTrue("/ POST", p.implies(pd, wrp)); 57 wrp = new WebResourcePermission ("/any", "POST"); 58 assertTrue("/any POST", p.implies(pd, wrp)); 59 wrp = new WebResourcePermission ("/", "DELETE"); 60 assertTrue("/any DELETE", p.implies(pd, wrp)); 61 62 } 63 64 protected void setUp() throws Exception 65 { 66 PolicyConfiguration pc; 67 WebMetaData metaData = new WebMetaData(); 68 ArrayList securityContraints = new ArrayList (); 69 addSC(securityContraints); 70 metaData.setSecurityConstraints(securityContraints); 71 72 DelegatingPolicy policy = new DelegatingPolicy(); 73 Policy.setPolicy(policy); 74 JBossPolicyConfigurationFactory pcf = new JBossPolicyConfigurationFactory(); 75 pc = pcf.getPolicyConfiguration("UncheckedWebConstraintsUnitTestCase", true); 76 WebPermissionMapping.createPermissions(metaData, pc); 77 pc.commit(); 78 System.out.println(policy.listContextPolicies()); 79 PolicyContext.setContextID("UncheckedWebConstraintsUnitTestCase"); 80 } 81 82 93 private void addSC(List securityContraints) 94 { 95 WebSecurityMetaData wsmd = new WebSecurityMetaData(); 96 securityContraints.add(wsmd); 97 WebSecurityMetaData.WebResourceCollection wrc = wsmd.addWebResource("SSL Only"); 99 wrc.addPattern("/*"); 100 wsmd.setUnchecked(true); 101 wsmd.setTransportGuarantee("CONFIDENTIAL"); 102 } 103 104 } 105 | Popular Tags |