Ошибка разрешенного доступа XACML

В настоящее время я пытаюсь реализовать XACML для приложения и только начал играть с ним, используя библиотеку AuthZForce. У меня есть пример политики, такой как:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:policy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
    <Description>
        Policy for Conformance Test IIA001.
    </Description>
    <Target/>
    <Rule Effect="Permit" RuleId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:rule">
        <Description>
            Julius Hibbert can read or write Bart Simpson's medical record.
        </Description>
        <Target>
            <AnyOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Julius Hibbert</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
                    </Match>
                </AllOf>
            </AnyOf>
            <AnyOf>
                <AllOf>
                    <Match 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>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#anyURI" MustBePresent="false"/>
                    </Match>
                </AllOf>
            </AnyOf>
            <AnyOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
                    </Match>
                </AllOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">write</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
                    </Match>
                </AllOf>
            </AnyOf>
        </Target>
    </Rule>
</Policy>

Поэтому я попытался создать запрос XACML на основе этой политики, надеясь, что он будет разрешен PDP с помощью следующего кода:

System.setProperty("javax.xml.accessExternalSchema", "http");

        File a = new File("pdp.xml");


        final PdpEngineConfiguration pdpEngineConf = PdpEngineConfiguration.getInstance(a.toURI().toString()); 
        final BasePdpEngine pdp = new BasePdpEngine(pdpEngineConf);
        final DecisionRequestBuilder<?> requestBuilder = pdp.newRequestBuilder(-1, -1);
        String issuer="Julius Hibbert";

        final AttributeFqn subjectIdAttributeId = AttributeFqns.newInstance(XACML_1_0_ACCESS_SUBJECT.value(), Optional.ofNullable(issuer), XacmlAttributeId.XACML_1_0_SUBJECT_ID.value());
        final AttributeBag<?> subjectIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.STRING, new StringValue("Julius Hibbert"));
        requestBuilder.putNamedAttributeIfAbsent(subjectIdAttributeId, subjectIdAttributeValues);

        final AttributeFqn resourceIdAttributeId = AttributeFqns.newInstance(XACML_3_0_RESOURCE.value(), Optional.ofNullable(issuer), XacmlAttributeId.XACML_1_0_RESOURCE_ID.value());
        final AttributeBag<?> resourceIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.STRING, new StringValue("http://medico.com/record/patient/BartSimpson"));
        requestBuilder.putNamedAttributeIfAbsent(resourceIdAttributeId, resourceIdAttributeValues);

        // Add action ID attribute (action category), no issuer, string value "GET"
        final AttributeFqn actionIdAttributeId = AttributeFqns.newInstance(XACML_3_0_ACTION.value(), Optional.ofNullable(issuer), XacmlAttributeId.XACML_1_0_ACTION_ID.value());
        final AttributeBag<?> actionIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.STRING, new StringValue("write"));
        requestBuilder.putNamedAttributeIfAbsent(actionIdAttributeId, actionIdAttributeValues);

        // No more attribute, let's finalize the request creation
        final DecisionRequest request = requestBuilder.build(false);
        // Evaluate the request
        final DecisionResult result = pdp.evaluate(request);
        if(result.getDecision() == DecisionType.PERMIT) {
            // This is a Permit :-)
            System.out.println("ok");
        } else {
            // Not a Permit :-( (maybe Deny, NotApplicable or Indeterminate)
            System.out.println("not ok");
        }

Но когда я запускаю код, он дает результат NotApplicable, но я не уверен, почему. Есть ли ошибка в моем коде?


person Ihsan Haikal    schedule 14.05.2018    source источник
comment
Какие инструменты вы использовали для написания своих политик?   -  person David Brossard    schedule 14.05.2018
comment
@DavidBrossard Я взял это отсюда github.com/authzforce/core/blob/develop/pdp-testutils/src/test/ поэтому я предполагаю, что все должно быть в порядке   -  person Ihsan Haikal    schedule 14.05.2018


Ответы (2)


Тип данных атрибута resource-id в вашем коде неверен. Вы устанавливаете его на string, тогда как в политике совпадения требуется anyURI. Так что просто измените эту строку кода:

final AttributeBag<?> resourceIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.STRING, new StringValue("http://medico.com/record/patient/BartSimpson"));

to

final AttributeBag<?> resourceIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.ANYURI, new AnyUriValue("http://medico.com/record/patient/BartSimpson"));

Кроме того, по какой-либо конкретной причине вы устанавливаете эмитента атрибутов на Julius Hibbert? В противном случае установите для него значение null и не беспокойтесь об этом.

String issuer = null;
person cdan    schedule 14.05.2018
comment
Я думал, что эмитент — это имя запрашивающего лица, которым в данном случае является Джулиус Хибберт. Разве это не правильно? - person Ihsan Haikal; 15.05.2018
comment
(игнорировать предыдущий комментарий) Имя запрашивающей стороны, т. е. значение атрибута subject-id, устанавливается с помощью этого кода: final AttributeBag<?> subjectIdAttributeValues = Bags.singletonAttributeBag(StandardDatatypes.STRING, new StringValue("Julius Hibbert")); Но издатель атрибута (необязательно, см. §5.46 стандарта XACML 3.0) устанавливается вторым аргументом в AttributeFqns.newInstance(...,Optional.ofNullable(issuer),...). - person cdan; 16.05.2018

Я выполнил ваши политики с помощью Axiomatics и вот что я получил

Сводка атрибутов

Сводка атрибутов

Пример запроса XACML в формате JSON

{
    "Request": {
        "ReturnPolicyIdList": true,
        "AccessSubject": {
            "Attribute": [
                {
                    "AttributeId": "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
                    "Value": "Julius Hibbert"
                }
            ]
        },
        "Resource": {
            "Attribute": [
                {
                    "AttributeId": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
                    "Value": "http://medico.com/record/patient/BartSimpson",
                    "DataType": "http://www.w3.org/2001/XMLSchema#anyURI"
                }
            ]
        },
        "Action": {
            "Attribute": [
                {
                    "AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
                    "Value": "read"
                }
            ]
        },
        "Environment": {
            "Attribute": []
        }
    }
}

XACML-ответ в формате JSON

{
  "Response" : {
    "Decision" : "Permit",
    "Status" : {
      "StatusCode" : {
        "Value" : "urn:oasis:names:tc:xacml:1.0:status:ok",
        "StatusCode" : {
          "Value" : "urn:oasis:names:tc:xacml:1.0:status:ok"
        }
      }
    },
    "PolicyIdentifierList" : {
      "PolicyIdReference" : {
        "Id" : "urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:policy",
        "Version" : "1.0"
      }
    }
  }
}

Редактор запросов

Редактор запросов

person David Brossard    schedule 14.05.2018
comment
Я не смог протестировать политику с другими программами, особенно с Axiomatics, так как я исследовал ранее, это платная услуга. - person Ihsan Haikal; 14.05.2018
comment
Это коммерческий продукт, да. бесплатного обеда не бывает - person David Brossard; 14.05.2018