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.ArrayList ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 31 import com.sun.xacml.EvaluationCtx; 32 import com.sun.xacml.attr.AttributeDesignator; 33 import com.sun.xacml.attr.BagAttribute; 34 import com.sun.xacml.attr.StringAttribute; 35 import com.sun.xacml.cond.EvaluationResult; 36 import com.sun.xacml.ctx.Status; 37 import com.sun.xacml.finder.AttributeFinderModule; 38 39 41 49 50 public class TestRoleAttributeFinderModule extends AttributeFinderModule 51 { 52 55 public static final String ROLE_IDENTIFIER = 56 "urn:oasis:names:tc:xacml:1.0:example:attribute:role"; 57 58 private static URI SUBJECT_IDENTIFIER = null; 60 61 private static URI SUBJECT_SOMEATTRIBUTE_IDENTIFIER = null; 62 63 static 65 { 66 try 67 { 68 SUBJECT_IDENTIFIER = 69 new URI ("urn:oasis:names:tc:xacml:1.0:subject:subject-id"); 70 SUBJECT_SOMEATTRIBUTE_IDENTIFIER = 71 new URI ("urn:oasis:names:tc:xacml:2.0:jboss-test:some-attribute"); 72 } 73 catch (URISyntaxException ex) 74 { 75 } 76 }; 77 78 81 public TestRoleAttributeFinderModule() 82 { 83 84 } 85 86 91 public boolean isDesignatorSupported() 92 { 93 return true; 94 } 95 96 104 public Set getSupportedDesignatorTypes() 105 { 106 Set set = new HashSet (); 107 set.add(new Integer (AttributeDesignator.SUBJECT_TARGET)); 108 return set; 109 } 110 111 116 public Set getSupportedIds() 117 { 118 Set set = new HashSet (); 119 set.add(ROLE_IDENTIFIER); 120 return set; 121 } 122 123 126 public EvaluationResult findAttribute(URI attributeType, URI attributeId, 127 URI issuer, URI subjectLogger, 128 EvaluationCtx context, 129 int designatorType) 130 { 131 if (! attributeId.toString().equals(ROLE_IDENTIFIER)) 133 return new EvaluationResult(BagAttribute. 134 createEmptyBag(attributeType)); 135 136 if (! attributeType.toString().equals(StringAttribute.identifier)) 138 return new EvaluationResult(BagAttribute. 139 createEmptyBag(attributeType)); 140 141 EvaluationResult result = 143 context.getSubjectAttribute(attributeType, SUBJECT_IDENTIFIER, 144 issuer, subjectLogger); 145 if (result.indeterminate()) 146 return result; 147 148 BagAttribute bag = (BagAttribute)(result.getAttributeValue()); 150 if (bag.isEmpty()) 151 { 152 ArrayList code = new ArrayList (); 153 code.add(Status.STATUS_MISSING_ATTRIBUTE); 154 Status status = new Status(code, "missing subject-id"); 155 return new EvaluationResult(status); 156 } 157 158 BagAttribute returnBag = null; 161 Iterator it = bag.iterator(); 162 while (it.hasNext()) 163 { 164 StringAttribute attr = (StringAttribute)(it.next()); 165 if (attr.getValue().equals("Anil Saldhana")) 166 { 167 Set set = new HashSet (); 168 set.add(new StringAttribute("Developer")); 169 returnBag = new BagAttribute(attributeType, set); 170 break; 171 } 172 } 173 174 return new EvaluationResult(returnBag); 175 } 176 } 177 | Popular Tags |