001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.web.security.jacc;
023:
024: import java.security.Policy;
025: import java.security.ProtectionDomain;
026: import java.util.ArrayList;
027: import java.util.List;
028: import javax.security.jacc.PolicyConfiguration;
029: import javax.security.jacc.PolicyContext;
030: import javax.security.jacc.WebResourcePermission;
031:
032: import junit.framework.TestCase;
033: import org.jboss.metadata.WebMetaData;
034: import org.jboss.metadata.WebSecurityMetaData;
035: import org.jboss.security.SimplePrincipal;
036: import org.jboss.security.jacc.DelegatingPolicy;
037: import org.jboss.security.jacc.JBossPolicyConfigurationFactory;
038: import org.jboss.web.WebPermissionMapping;
039:
040: /**
041:
042: * @author Scott.Stark@jboss.org
043: * @version $Revision: 57206 $
044: */
045: public class DataWebConstraintsUnitTestCase extends TestCase {
046: public void testUncheckedExact() throws Exception {
047: Policy p = Policy.getPolicy();
048: SimplePrincipal[] caller = null;
049: ProtectionDomain pd = new ProtectionDomain(null, null, null,
050: caller);
051:
052: WebResourcePermission wrp = new WebResourcePermission("/",
053: "GET");
054: assertTrue("/ GET", p.implies(pd, wrp));
055: wrp = new WebResourcePermission("/", "POST");
056: assertTrue("/ POST", p.implies(pd, wrp));
057: wrp = new WebResourcePermission("/any", "POST");
058: assertTrue("/any POST", p.implies(pd, wrp));
059: wrp = new WebResourcePermission("/", "DELETE");
060: assertTrue("/any DELETE", p.implies(pd, wrp));
061:
062: }
063:
064: protected void setUp() throws Exception {
065: PolicyConfiguration pc;
066: WebMetaData metaData = new WebMetaData();
067: ArrayList securityContraints = new ArrayList();
068: addSC(securityContraints);
069: metaData.setSecurityConstraints(securityContraints);
070:
071: DelegatingPolicy policy = new DelegatingPolicy();
072: Policy.setPolicy(policy);
073: JBossPolicyConfigurationFactory pcf = new JBossPolicyConfigurationFactory();
074: pc = pcf.getPolicyConfiguration(
075: "UncheckedWebConstraintsUnitTestCase", true);
076: WebPermissionMapping.createPermissions(metaData, pc);
077: pc.commit();
078: System.out.println(policy.listContextPolicies());
079: PolicyContext
080: .setContextID("UncheckedWebConstraintsUnitTestCase");
081: }
082:
083: /*
084: <security-constraint>
085: <web-resource-collection>
086: <web-resource-name>SSL Only</web-resource-name>
087: <url-pattern>/*</url-pattern>
088: </web-resource-collection>
089: <user-data-constraint>
090: <transport-guarantee>CONFIDENTIAL</transport-guarantee>
091: </user-data-constraint>
092: </security-constraint>
093: */
094: private void addSC(List securityContraints) {
095: WebSecurityMetaData wsmd = new WebSecurityMetaData();
096: securityContraints.add(wsmd);
097: // web-resource-collection/web-resource-name = exact, get method, roleA
098: WebSecurityMetaData.WebResourceCollection wrc = wsmd
099: .addWebResource("SSL Only");
100: wrc.addPattern("/*");
101: wsmd.setUnchecked(true);
102: wsmd.setTransportGuarantee("CONFIDENTIAL");
103: }
104:
105: }
|