1 22 package org.jboss.test.security.test.xacml.modules; 23 24 import java.net.URI ; 25 import java.net.URISyntaxException ; 26 import java.util.HashSet ; 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 36 42 public class TestResourceFinderModule extends ResourceFinderModule 43 { 44 45 48 public TestResourceFinderModule() 49 { 50 } 51 52 57 public boolean isChildSupported() 58 { 59 return true; 60 } 61 62 67 public boolean isDescendantSupported() 68 { 69 return true; 70 } 71 72 76 public ResourceFinderResult findChildResources(AttributeValue root, 77 EvaluationCtx context) 78 { 79 if (preValidateRequest(root) == false) 81 return new ResourceFinderResult(); 82 83 HashSet set = new HashSet (); 85 set.add(root); 86 87 try 89 { 90 set.add(new AnyURIAttribute(new URI ("urn:root:child1"))); 91 set.add(new AnyURIAttribute(new URI ("urn:root:child2"))); 92 } 93 catch (URISyntaxException ex) 94 { 95 } 96 97 return new ResourceFinderResult(set); 98 } 99 100 104 public ResourceFinderResult findDescendantResources(AttributeValue root, 105 EvaluationCtx 106 context) 107 { 108 if (preValidateRequest(root) == false) 110 return new ResourceFinderResult(); 111 112 HashSet set = new HashSet (); 114 set.add(root); 115 116 try 118 { 119 set.add(new AnyURIAttribute(new URI ("urn:root:child1"))); 120 set.add(new AnyURIAttribute(new 121 URI ("urn:root:child1:descendant1"))); 122 set.add(new AnyURIAttribute(new 123 URI ("urn:root:child1:descendant2"))); 124 set.add(new AnyURIAttribute(new URI ("urn:root:child2"))); 125 set.add(new AnyURIAttribute(new 126 URI ("urn:root:child2:descendant1"))); 127 set.add(new AnyURIAttribute(new 128 URI ("urn:root:child2:descendant2"))); 129 } 130 catch (URISyntaxException ex) 131 { 132 } 133 return new ResourceFinderResult(set); 134 } 135 136 139 private boolean preValidateRequest(AttributeValue root) 140 { 141 String rootType = root.getType().toString(); 142 143 if(AnyURIAttribute.identifier.equals(rootType) == false) 145 return false; 146 147 AnyURIAttribute uriRoot = (AnyURIAttribute)root; 148 149 if("urn:root".equals(uriRoot.toString()) == false) 151 return false; 152 153 return true; 154 } 155 156 } 157 | Popular Tags |