Search in sources :

Example 1 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project xtext-core by eclipse.

the class ManifestMerger2Test method testMergeRequiredBundles.

@Test
public void testMergeRequiredBundles() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
    Attributes attrs = manifest.getMainAttributes();
    String before = attrs.get(MergeableManifest2.REQUIRE_BUNDLE).replaceAll("\\s", "");
    manifest.addRequiredBundles(Collections.singleton("foo.bar.baz"));
    String after = attrs.get(MergeableManifest2.REQUIRE_BUNDLE);
    assertEquals(before + ",foo.bar.baz", after.replaceAll("\\s", ""));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) Attributes(org.eclipse.xtext.util.MergeableManifest2.Attributes) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) Test(org.junit.Test)

Example 2 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project xtext-core by eclipse.

the class ManifestMerger2Test method testNoChanges.

@Test
public void testNoChanges() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
    Attributes attrs = manifest.getMainAttributes();
    String before = attrs.get(MergeableManifest2.EXPORT_PACKAGE).replaceAll("\\s", "");
    manifest.addExportedPackages(Collections.singleton("foo.bar.baz"));
    String after = attrs.get(MergeableManifest2.EXPORT_PACKAGE);
    assertEquals(before + ",foo.bar.baz", after.replaceAll("\\s", ""));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) Attributes(org.eclipse.xtext.util.MergeableManifest2.Attributes) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) Test(org.junit.Test)

Example 3 with Attributes

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project ddf by codice.

the class XacmlPdpTest method testEnvironmentVariables.

@Test
public void testEnvironmentVariables() {
    RequestType request = testRealm.createXACMLRequest(USER_NAME, generateSubjectInfo(TEST_COUNTRY), new KeyValueCollectionPermissionImpl(QUERY_ACTION));
    List<AttributesType> attributes = request.getAttributes();
    AttributesType environmentAttributes = null;
    for (AttributesType attribute : attributes) {
        if (attribute.getCategory().equals(ENVIRONMENT_CATEGORY)) {
            environmentAttributes = attribute;
        }
    }
    assertNotNull(environmentAttributes);
    assertThat(environmentAttributes.getAttribute().get(0).getAttributeId(), is("item0"));
    assertThat(environmentAttributes.getAttribute().get(0).getAttributeValue().size(), is(1));
    assertThat(environmentAttributes.getAttribute().get(1).getAttributeId(), is("item1"));
    assertThat(environmentAttributes.getAttribute().get(1).getAttributeValue().size(), is(2));
    assertThat(environmentAttributes.getAttribute().get(2).getAttributeId(), is("item2"));
    assertThat(environmentAttributes.getAttribute().get(2).getAttributeValue().size(), is(3));
}
Also used : AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) KeyValueCollectionPermissionImpl(ddf.security.permission.impl.KeyValueCollectionPermissionImpl) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Example 4 with Attributes

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

the class EntitlementUtil method getAttributes.

public static Attributes getAttributes(AttributeDTO attributeDataDTO) {
    try {
        AttributeValue value = Balana.getInstance().getAttributeFactory().createValue(new URI(attributeDataDTO.getAttributeDataType()), attributeDataDTO.getAttributeValue());
        Attribute attribute = new Attribute(new URI(attributeDataDTO.getAttributeId()), null, null, value, XACMLConstants.XACML_VERSION_3_0);
        Set<Attribute> set = new HashSet<Attribute>();
        set.add(attribute);
        String category = attributeDataDTO.getCategory();
        // We are only creating XACML 3.0 requests Therefore covert order XACML categories to new uris
        if (PDPConstants.SUBJECT_ELEMENT.equals(category)) {
            category = PDPConstants.SUBJECT_CATEGORY_URI;
        } else if (PDPConstants.RESOURCE_ELEMENT.equals(category)) {
            category = PDPConstants.RESOURCE_CATEGORY_URI;
        } else if (PDPConstants.ACTION_ELEMENT.equals(category)) {
            category = PDPConstants.ACTION_CATEGORY_URI;
        } else if (PDPConstants.ENVIRONMENT_ELEMENT.equals(category)) {
            category = PDPConstants.ENVIRONMENT_CATEGORY_URI;
        }
        return new Attributes(new URI(category), set);
    } catch (Exception e) {
        log.debug(e);
    // ignore and return null;
    }
    return null;
}
Also used : AttributeValue(org.wso2.balana.attr.AttributeValue) StringAttribute(org.wso2.balana.attr.StringAttribute) DateAttribute(org.wso2.balana.attr.DateAttribute) DoubleAttribute(org.wso2.balana.attr.DoubleAttribute) IntegerAttribute(org.wso2.balana.attr.IntegerAttribute) TimeAttribute(org.wso2.balana.attr.TimeAttribute) HexBinaryAttribute(org.wso2.balana.attr.HexBinaryAttribute) DateTimeAttribute(org.wso2.balana.attr.DateTimeAttribute) Attribute(org.wso2.balana.ctx.Attribute) BooleanAttribute(org.wso2.balana.attr.BooleanAttribute) Attributes(org.wso2.balana.xacml3.Attributes) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ParseException(java.text.ParseException) SAXException(org.xml.sax.SAXException) ParsingException(org.wso2.balana.ParsingException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Example 5 with Attributes

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

the class JSONRequestParser method jsonAttributeSeperator.

/**
 * This is to seperate JSON to attributes
 * @param jsonAttribute - the map of category string and the JSON Element
 * @param jsonCategory - the  main object category
 * @param categories - the set of categories
 * @throws RequestParseException
 * @throws UnknownIdentifierException
 */
private static void jsonAttributeSeperator(Map.Entry<String, JsonElement> jsonAttribute, JsonObject jsonCategory, Set<Attributes> categories) throws RequestParseException, UnknownIdentifierException {
    Node content = null;
    URI category = null;
    Set<Attribute> attributes = null;
    String id = null;
    if (EntitlementEndpointConstants.CATEGORY_DEFAULT.equals(jsonAttribute.getKey())) {
        if (jsonCategory.has(EntitlementEndpointConstants.CATEGORY_ID)) {
            category = stringCateogryToURI(jsonCategory.get(EntitlementEndpointConstants.CATEGORY_ID).getAsString());
        }
    } else {
        if (category == null) {
            category = stringCateogryToURI(jsonAttribute.getKey());
        }
        if (jsonCategory.has(EntitlementEndpointConstants.ID)) {
            id = jsonCategory.get(EntitlementEndpointConstants.ID).getAsString();
        }
        if (jsonCategory.has(EntitlementEndpointConstants.CONTENT)) {
            DocumentBuilderFactory dbf;
            Document doc = null;
            String xmlContent = stringContentToXMLContent(jsonCategory.get(EntitlementEndpointConstants.CONTENT).getAsString());
            dbf = IdentityUtil.getSecuredDocumentBuilderFactory();
            dbf.setNamespaceAware(true);
            try (ByteArrayInputStream inputStream = new ByteArrayInputStream(xmlContent.getBytes())) {
                doc = dbf.newDocumentBuilder().parse(inputStream);
            } catch (Exception e) {
                throw new JsonParseException("DOM of request element can not be created from String.", e);
            }
            if (doc != null) {
                content = doc.getDocumentElement();
            }
        }
        // Add all category attributes
        if (jsonCategory.has(EntitlementEndpointConstants.ATTRIBUTE)) {
            if (jsonCategory.get(EntitlementEndpointConstants.ATTRIBUTE).isJsonArray()) {
                attributes = new HashSet<>();
                for (JsonElement jsonElement : jsonCategory.get(EntitlementEndpointConstants.ATTRIBUTE).getAsJsonArray()) {
                    attributes.add(jsonObjectToAttribute(jsonElement.getAsJsonObject()));
                }
            }
        }
    }
    // Build the Attributes object using above values
    Attributes attributesObj = new Attributes(category, content, attributes, id);
    categories.add(attributesObj);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Attribute(org.wso2.balana.ctx.Attribute) Node(org.w3c.dom.Node) Attributes(org.wso2.balana.xacml3.Attributes) Document(org.w3c.dom.Document) JsonParseException(com.google.gson.JsonParseException) URI(java.net.URI) JsonParseException(com.google.gson.JsonParseException) RequestParseException(org.wso2.carbon.identity.entitlement.endpoint.exception.RequestParseException) UnknownIdentifierException(org.wso2.balana.UnknownIdentifierException) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonElement(com.google.gson.JsonElement)

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