0

我是 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 实现。

4

1 回答 1

0

观察您的代码后,我发现您正在尝试将字符串类型转换为 com.sun.xacml.ctx.Attribute 类的属性类型。传递属性类定义的参数:属性类 将您的代码粘贴到Pastebin中,以便我查看。

于 2014-03-05T17:25:46.690 回答