Search in sources :

Example 11 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project carbon-identity-framework by wso2.

the class TestJSONRequestParser method testParse.

@Test
public void testParse() {
    AttributeValue attributeValue = new StringAttribute("http://127.0.0.1");
    List<AttributeValue> attributeValues = new ArrayList<>();
    attributeValues.add(attributeValue);
    Attribute attribute = new Attribute(URI.create("urn:oasis:names:tc:xacml:1.0:resource:resource-id"), null, null, null, attributeValues, false, XACMLConstants.XACML_VERSION_3_0);
    Set<Attribute> attributeSet = new HashSet<>();
    attributeSet.add(attribute);
    Attributes category = new Attributes(URI.create(EntitlementEndpointConstants.CATEGORY_RESOURCE_URI), attributeSet);
    Set<Attributes> categories = new HashSet<>();
    categories.add(category);
    RequestCtx requestCtx = new RequestCtx(categories, null);
    String jsonRequest = "{\n" + "  \"Request\":{\n" + "    \"Action\":{\n" + "      \"Attribute\":[{\n" + "        \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:action:action-id\",\n" + "        \"Value\":\"read\"\n" + "      }]\n" + "    },\n" + "    \"Resource\":{\n" + "      \"Attribute\":[{\n" + "        \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:resource:resource-id\",\n" + "        \"Value\":\"http://127.0.0.1/service/very_secure/\"\n" + "      }]\n" + "    }\n" + "  }\n" + "}";
    String jsonRequest2 = "{\"Request\":\n" + "{\n" + "\"AccessSubject\":{\n" + "            \"Content\": \"PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8Y2F0YWxvZz48Ym9vayBpZD0iYmsxMDEiPjxhdXRob3I+R2FtYmFyZGVsbGEsIE1hdHRoZXc8L2F1dGhvcj48dGl0bGU+WE1MIERldmVsb3BlcidzIEd1aWRlPC90aXRsZT48Z2VucmU+Q29tcHV0ZXI8L2dlbnJlPjxwcmljZT40NC45NTwvcHJpY2U+PHB1Ymxpc2hfZGF0ZT4yMDAwLTEwLTAxPC9wdWJsaXNoX2RhdGU+PGRlc2NyaXB0aW9uPkFuIGluLWRlcHRoIGxvb2sgYXQgY3JlYXRpbmcgYXBwbGljYXRpb25zIHdpdGggWE1MLjwvZGVzY3JpcHRpb24+PC9ib29rPjwvY2F0YWxvZz4=\"\n" + "}\n" + "}}";
    try {
        RequestCtx requestCtx1 = JSONRequestParser.parse(jsonRequest);
    } catch (Exception e) {
        log.error("Exception in JSON Parser Test");
    }
}
Also used : AttributeValue(org.wso2.balana.attr.AttributeValue) StringAttribute(org.wso2.balana.attr.StringAttribute) Attribute(org.wso2.balana.ctx.Attribute) StringAttribute(org.wso2.balana.attr.StringAttribute) ArrayList(java.util.ArrayList) Attributes(org.wso2.balana.xacml3.Attributes) HashSet(java.util.HashSet) RequestCtx(org.wso2.balana.ctx.xacml3.RequestCtx) Test(org.testng.annotations.Test)

Example 12 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project carbon-identity-framework by wso2.

the class CarbonAttributeFinder method encodeContext.

/**
 * Converts DOM object to String. This is a helper method for creating cache key
 *
 * @param evaluationCtx EvaluationCtx
 * @return String Object
 * @throws TransformerException Exception throws if fails
 */
private String encodeContext(EvaluationCtx evaluationCtx) throws TransformerException {
    OutputStream stream = new ByteArrayOutputStream();
    evaluationCtx.getRequestCtx().encode(stream);
    String rowContext = stream.toString();
    String contextWithAttributeValues = rowContext + "][";
    StringBuilder builder = new StringBuilder();
    for (Attributes attributes : evaluationCtx.getRequestCtx().getAttributesSet()) {
        builder.append("<Attributes ").append(">");
        for (Attribute attribute : attributes.getAttributes()) {
            attribute.encode(builder);
        }
        builder.append("</Attributes>");
    }
    contextWithAttributeValues += builder.toString();
    return contextWithAttributeValues;
}
Also used : BagAttribute(org.wso2.balana.attr.BagAttribute) Attribute(org.wso2.balana.ctx.Attribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Attributes(org.wso2.balana.xacml3.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project core-pdp-api by authzforce.

the class BaseXacmlJaxbRequestPreprocessor method process.

@Override
public final List<IndividualXacmlJaxbRequest> process(final Request jaxbRequest, final Map<String, String> namespaceURIsByPrefix) throws IndeterminateEvaluationException {
    if (jaxbRequest == null) {
        throw NULL_REQUEST_EXCEPTION;
    }
    /*
         * No support for MultiRequests (ยง2.4 of Multiple Decision Profile).
         */
    if (jaxbRequest.getMultiRequests() != null) {
        /*
             * According to 7.19.1 Unsupported functionality, return Indeterminate with syntax-error code for unsupported element
             */
        throw UNSUPPORTED_MULTI_REQUESTS_EXCEPTION;
    }
    /*
         * No support for CombinedDecision = true if no decisionCombiner defined. (The use of the CombinedDecision attribute is specified in Multiple Decision Profile.)
         */
    if (jaxbRequest.isCombinedDecision() && !this.isCombinedDecisionSupported) {
        /*
             * According to XACML core spec, 5.42, <i>If the PDP does not implement the relevant functionality in [Multiple Decision Profile], then the PDP must return an Indeterminate with a status
             * code of urn:oasis:names:tc:xacml:1.0:status:processing-error if it receives a request with this attribute set to "true"</i>.
             */
        throw UNSUPPORTED_COMBINED_DECISION_EXCEPTION;
    }
    final RequestDefaults jaxbReqDefaults = jaxbRequest.getRequestDefaults();
    final Optional<XPathCompilerProxy> xPathCompiler;
    final Map<String, String> newNsPrefixToUriMap;
    if (jaxbReqDefaults == null) {
        xPathCompiler = Optional.empty();
        newNsPrefixToUriMap = namespaceURIsByPrefix;
    } else {
        try {
            final XPathVersion xPathVersion = XPathVersion.fromURI(jaxbReqDefaults.getXPathVersion());
            xPathCompiler = Optional.of(new BasicImmutableXPathCompilerProxy(xPathVersion, namespaceURIsByPrefix));
            /*
				namespaceURIsByPrefix already held by xPathCompiler and retrievable from it with getDeclaredNamespacePrefixToUriMap().
				 */
            newNsPrefixToUriMap = Map.of();
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid/unsupported XPathVersion in Request/RequestDefaults", e);
        }
    }
    final SingleCategoryXacmlAttributesParser<Attributes> xacmlAttrsParser = xacmlAttrsParserFactory.getInstance();
    return process(jaxbRequest.getAttributes(), xacmlAttrsParser, jaxbRequest.isReturnPolicyIdList(), jaxbRequest.isCombinedDecision(), xPathCompiler, newNsPrefixToUriMap);
}
Also used : BasicImmutableXPathCompilerProxy(org.ow2.authzforce.core.pdp.api.expression.BasicImmutableXPathCompilerProxy) BasicImmutableXPathCompilerProxy(org.ow2.authzforce.core.pdp.api.expression.BasicImmutableXPathCompilerProxy) XPathCompilerProxy(org.ow2.authzforce.core.pdp.api.expression.XPathCompilerProxy) Attributes(oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes) RequestDefaults(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestDefaults) XPathVersion(org.ow2.authzforce.xacml.identifiers.XPathVersion)

Aggregations

Attributes (org.wso2.balana.xacml3.Attributes)6 Attribute (org.wso2.balana.ctx.Attribute)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 JsonParseException (com.google.gson.JsonParseException)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Attributes (oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes)2 MergeableManifest2 (org.eclipse.xtext.util.MergeableManifest2)2 Attributes (org.eclipse.xtext.util.MergeableManifest2.Attributes)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 UnknownIdentifierException (org.wso2.balana.UnknownIdentifierException)2 AttributeValue (org.wso2.balana.attr.AttributeValue)2 StringAttribute (org.wso2.balana.attr.StringAttribute)2 RequestParseException (org.wso2.carbon.identity.entitlement.endpoint.exception.RequestParseException)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 KeyValueCollectionPermissionImpl (ddf.security.permission.impl.KeyValueCollectionPermissionImpl)1