KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > xacml > XACMLRequestCreationUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.test.xacml;
23
24 import java.net.URI JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import org.jboss.test.JBossTestCase;
29
30 import com.sun.xacml.attr.StringAttribute;
31 import com.sun.xacml.ctx.Attribute;
32 import com.sun.xacml.ctx.RequestCtx;
33 import com.sun.xacml.ctx.Subject;
34
35 //$Id: XACMLRequestCreationUnitTestCase.java 45705 2006-06-20 17:30:10Z asaldhana $
36

37 /**
38  * Test creation of XACML Requests
39  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
40  * @since Jun 20, 2006
41  * @version $Revision: 45705 $
42  */

43 public class XACMLRequestCreationUnitTestCase extends JBossTestCase
44 {
45    private static final boolean DEBUG = true;
46    
47    public XACMLRequestCreationUnitTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51    
52    public void testCreationOfRequest() throws Exception JavaDoc
53    {
54       //refer to the src/resources/security/xacml/test1/request.xml
55

56       //Create the subject set
57
URI JavaDoc subjectAttrUri = new URI JavaDoc("urn:oasis:names:tc:xacml:1.0:subject:subject-id");
58       Attribute subjectAttr = new Attribute(subjectAttrUri,null,null,
59             new StringAttribute("Anil Saldhana"));
60       Set JavaDoc subjectAttrSet = new HashSet JavaDoc();
61       subjectAttrSet.add(subjectAttr);
62       Set JavaDoc subjectSet = new HashSet JavaDoc();
63       subjectSet.add(new Subject(subjectAttrSet));
64       
65       //Create the resource set
66
URI JavaDoc resourceUri = new URI JavaDoc("urn:oasis:names:tc:xacml:1.0:resource:resource-id");
67       Attribute resourceAttr = new Attribute(resourceUri,null,null,
68             new StringAttribute("http://jboss.com/developers/payroll/anilsaldhana"));
69       Set JavaDoc resourceSet = new HashSet JavaDoc();
70       resourceSet.add(resourceAttr);
71       
72       //Create the action set
73
URI JavaDoc actionUri = new URI JavaDoc("urn:oasis:names:tc:xacml:1.0:action:action-id");
74       Attribute actionAttr = new Attribute(actionUri,null,null,
75             new StringAttribute("read"));
76       Set JavaDoc actionSet = new HashSet JavaDoc();
77       actionSet.add(actionAttr);
78       
79       //Create the environment set
80
Set JavaDoc environSet = new HashSet JavaDoc();
81       
82       RequestCtx request = new RequestCtx(subjectSet,resourceSet,actionSet,environSet);
83       assertNotNull("XACML Request != null", request);
84       
85       //Log the request for viewing
86
if(DEBUG)
87          XACMLUtil.logRequest(log,request);
88       
89       //Test the request contents
90
Set JavaDoc subjects = request.getSubjects();
91       assertTrue("We have one subject?", subjects.size() == 1);
92       Subject subj = (Subject)(subjects.iterator().next());
93       assertNotNull("Subject != null",subj);
94       assertEquals("Attributes in subject match", subjectAttr,
95             (Attribute)(subj.getAttributes().iterator().next()));
96       
97       //Test the resource attributes
98
Set JavaDoc resources = request.getResource();
99       assertTrue("# of resources = 1", resources.size() == 1);
100       assertEquals("Attributes in resources match", resourceAttr,
101             (Attribute)(resources.iterator().next()));
102       
103       //Test the action attributes
104
Set JavaDoc actions = request.getAction();
105       assertTrue("# of actions = 1", actions.size() == 1);
106       assertEquals("Attributes in actions match", actionAttr,
107             (Attribute)(actions.iterator().next()));
108    }
109 }
110
Popular Tags