2014-02-24 54 views
0

我是新來XACML並收到以下錯誤XACML類轉換異常

java.lang.String cannot be cast to com.sun.xacml.ctx.Attribute 
    at com.sun.xacml.BasicEvaluationCtx.setupSubjects(BasicEvaluationCtx.java:252) 

我定義我的屬性是這樣的:

 Set subjects=new HashSet(); 

     subjects.add("Julius Hibbert"); 
     Subject subject = new Subject(subjects); 

     Set subjectList=new HashSet(); 
     subjectList.add(subject); 

      value = new AnyURIAttribute(new URI("http://medico.com/record/patient/BartSimpson")); 
      Attribute resource = new Attribute(new URI("urn:oasis:names:tc:xacml:1.0:resource:resource-id"), null, null, value); 
      Set resourceAttrs=new HashSet(); 
      resourceAttrs.add(resource); 

      Set actionAttrs=new HashSet(); 

      DateTimeAttribute date=new DateTimeAttribute(); 
      AttributeValue attvalue=new StringAttribute("read"); 

      Attribute action = new Attribute(new URI("urn:oasis:names:tc:xacml:1.0:action:action-id"), "", date, attvalue); 
      actionAttrs.add(action); 

      Set env=new HashSet(); 

RequestCtx request = new RequestCtx(subjects, resourceAttrs, 
        actionAttrs, environmentAttrs); 

我的XACML文件是:

<?xml version="1.0" encoding="UTF-8"?> 
<Policy 
     xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:policy:schema:os 
     http://docs.oasis-open.org/xacml/2.0/access_control-xacml-2.0-context-schema-os.xsd" 
     PolicyId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:policy" 
     RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides"> 
    <Description> 
     Policy for Conformance Test IIA001. 
    </Description> 
    <Target/> 
    <Rule 
      RuleId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:rule" 
      Effect="Permit"> 
     <Description> 
      Julius Hibbert can read or write Bart Simpson's medical record. 
     </Description> 
     <Target> 
      <Subjects> 
       <Subject> 
        <SubjectMatch 
          MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> 
         <AttributeValue 
           DataType="http://www.w3.org/2001/XMLSchema#string">Julius Hibbert</AttributeValue> 
         <SubjectAttributeDesignator 
           AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" 
           DataType="http://www.w3.org/2001/XMLSchema#string"/> 
        </SubjectMatch> 
       </Subject> 
      </Subjects> 
      <Resources> 
       <Resource> 
        <ResourceMatch 
          MatchId="urn:oasis:names:tc:xacml:1.0:function:anyURI-equal"> 
         <AttributeValue 
           DataType="http://www.w3.org/2001/XMLSchema#anyURI">http://medico.com/record/patient/BartSimpson</AttributeValue> 
         <ResourceAttributeDesignator 
           AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 
           DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 
        </ResourceMatch> 
       </Resource> 
      </Resources> 
      <Actions> 
       <Action> 
        <ActionMatch 
          MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> 
         <AttributeValue 
           DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue> 
         <ActionAttributeDesignator 
           AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" 
           DataType="http://www.w3.org/2001/XMLSchema#string"/> 
        </ActionMatch> 
       </Action> 
       <Action> 
        <ActionMatch 
          MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> 
         <AttributeValue 
           DataType="http://www.w3.org/2001/XMLSchema#string">write</AttributeValue> 
         <ActionAttributeDesignator 
           AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" 
           DataType="http://www.w3.org/2001/XMLSchema#string"/> 
        </ActionMatch> 
       </Action> 
      </Actions> 
     </Target> 
    </Rule> 
</Policy> 

我在哪裏出錯?我正在使用Sun XACML實現。

回答

0

在觀察你的代碼後,我發現你試圖將一個String類型轉換爲類com.sun.xacml.ctx.Attribute的屬性類型。按照屬性類的定義傳遞參數:Attribute Class 將您的代碼粘貼到Pastebin中,以便我可以看一看。