KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > xacml > modules > TestResourceFinderModule


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.modules;
23
24 import java.net.URI JavaDoc;
25 import java.net.URISyntaxException JavaDoc;
26 import java.util.HashSet JavaDoc;
27
28 import com.sun.xacml.EvaluationCtx;
29 import com.sun.xacml.attr.AnyURIAttribute;
30 import com.sun.xacml.attr.AttributeValue;
31 import com.sun.xacml.finder.ResourceFinderModule;
32 import com.sun.xacml.finder.ResourceFinderResult;
33
34 //$Id: TestResourceFinderModule.java 45389 2006-05-30 21:29:37Z asaldhana $
35

36 /**
37  * Resource Finder Module for testing purposes
38  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
39  * @since May 26, 2006
40  * @version $Revision: 45389 $
41  */

42 public class TestResourceFinderModule extends ResourceFinderModule
43 {
44
45     /**
46      * Default constructor.
47      */

48     public TestResourceFinderModule()
49     {
50     }
51
52     /**
53      * @see ResourceFinderModule#isChildSupported()
54      *
55      * @return true
56      */

57     public boolean isChildSupported()
58     {
59         return true;
60     }
61
62     /**
63      * @see ResourceFinderModule#isDescendantSupported()
64      *
65      * @return true
66      */

67     public boolean isDescendantSupported()
68     {
69         return true;
70     }
71
72     /**
73      * @see ResourceFinderModule#findChildResources(com.sun.xacml.attr.AttributeValue,
74      * com.sun.xacml.EvaluationCtx)
75      */

76     public ResourceFinderResult findChildResources(AttributeValue root,
77                                                    EvaluationCtx context)
78     {
79        //Validate the root
80
if (preValidateRequest(root) == false)
81            return new ResourceFinderResult();
82
83         // add the root to the set of resolved resources
84
HashSet JavaDoc set = new HashSet JavaDoc();
85         set.add(root);
86
87         // add the other resources, which are defined by the conformance tests
88
try
89         {
90             set.add(new AnyURIAttribute(new URI JavaDoc("urn:root:child1")));
91             set.add(new AnyURIAttribute(new URI JavaDoc("urn:root:child2")));
92         }
93         catch (URISyntaxException JavaDoc ex)
94         {
95         }
96
97         return new ResourceFinderResult(set);
98     }
99
100     /**
101      * @see ResourceFinderModule#findDescendantResources(com.sun.xacml.attr.AttributeValue,
102      * com.sun.xacml.EvaluationCtx)
103      */

104     public ResourceFinderResult findDescendantResources(AttributeValue root,
105                                                         EvaluationCtx
106                                                         context)
107     {
108         // Validate the root
109
if (preValidateRequest(root) == false)
110             return new ResourceFinderResult();
111
112         // add the root to the set of resolved resources
113
HashSet JavaDoc set = new HashSet JavaDoc();
114         set.add(root);
115
116         // add the other resources, which are defined by the conformance tests
117
try
118         {
119             set.add(new AnyURIAttribute(new URI JavaDoc("urn:root:child1")));
120             set.add(new AnyURIAttribute(new
121                                         URI JavaDoc("urn:root:child1:descendant1")));
122             set.add(new AnyURIAttribute(new
123                                         URI JavaDoc("urn:root:child1:descendant2")));
124             set.add(new AnyURIAttribute(new URI JavaDoc("urn:root:child2")));
125             set.add(new AnyURIAttribute(new
126                                         URI JavaDoc("urn:root:child2:descendant1")));
127             set.add(new AnyURIAttribute(new
128                                         URI JavaDoc("urn:root:child2:descendant2")));
129         }
130         catch (URISyntaxException JavaDoc ex)
131         {
132         }
133         return new ResourceFinderResult(set);
134     }
135
136     /**
137      * Verify the root
138      */

139     private boolean preValidateRequest(AttributeValue root)
140     {
141        String JavaDoc rootType = root.getType().toString();
142        
143        //Check that the resource-id for the root is a URI
144
if(AnyURIAttribute.identifier.equals(rootType) == false)
145           return false;
146
147        AnyURIAttribute uriRoot = (AnyURIAttribute)root;
148        
149        //Is root == urn:root?
150
if("urn:root".equals(uriRoot.toString()) == false)
151           return false;
152        
153         return true;
154     }
155
156 }
157
Popular Tags