Search in sources :

Example 16 with ObjectFactory

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

the class TestCswFilterDelegate method testFeatureIdAndComparisonOpsOr.

@Test(expected = UnsupportedOperationException.class)
public void testFeatureIdAndComparisonOpsOr() throws JAXBException, SAXException, IOException {
    ObjectFactory filterObjectFactory = new ObjectFactory();
    FeatureIdType fidType = new FeatureIdType();
    fidType.setFid("cswRecord.1234");
    List<JAXBElement<? extends AbstractIdType>> fidFilters = new ArrayList<>();
    fidFilters.add(filterObjectFactory.createFeatureId(fidType));
    FilterType idFilter = new FilterType();
    idFilter.setId(fidFilters);
    FilterType propertyIsLikeFilter = cswFilterDelegateLatLon.propertyIsLike(propertyName, likeLiteral, isCaseSensitive);
    List<FilterType> filterList = new ArrayList<>();
    filterList.add(idFilter);
    filterList.add(propertyIsLikeFilter);
    cswFilterDelegateLatLon.or(filterList);
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ObjectFactory(net.opengis.filter.v_1_1_0.ObjectFactory) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) AbstractIdType(net.opengis.filter.v_1_1_0.AbstractIdType) FeatureIdType(net.opengis.filter.v_1_1_0.FeatureIdType) Test(org.junit.Test)

Example 17 with ObjectFactory

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

the class XacmlClientTest method testWrapperpoliciesdirectorypolicyadded.

@Test
public void testWrapperpoliciesdirectorypolicyadded() throws Exception {
    LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_policy_added");
    File policyDir = folder.newFolder("tempDir");
    XacmlClient.defaultPollingIntervalInSeconds = 1;
    // Perform Test
    XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), new XmlParser());
    File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, policyDir);
    Thread.sleep(2000);
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);
    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);
    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);
    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
    // Verify - The policy was loaded to allow a permit decision
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);
    FileUtils.deleteDirectory(policyDir);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Example 18 with ObjectFactory

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

the class XacmlClient method marshal.

/**
     * Marshalls the XACML request to a string.
     *
     * @param xacmlRequestType The XACML request to marshal.
     * @return A string representation of the XACML request.
     */
private String marshal(RequestType xacmlRequestType) throws PdpException {
    if (null == parser) {
        throw new IllegalStateException("XMLParser must be configured.");
    }
    String xacmlRequest = null;
    try {
        List<String> ctxPath = new ArrayList<>(1);
        ctxPath.add(ResponseType.class.getPackage().getName());
        ParserConfigurator configurator = parser.configureParser(ctxPath, XacmlClient.class.getClassLoader());
        configurator.addProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ObjectFactory objectFactory = new ObjectFactory();
        parser.marshal(configurator, objectFactory.createRequest(xacmlRequestType), os);
        xacmlRequest = os.toString("UTF-8");
    } catch (ParserException | UnsupportedEncodingException e) {
        String message = "Unable to marshal XACML request.";
        LOGGER.info(message, e);
        throw new PdpException(message, e);
    }
    LOGGER.debug("\nXACML 3.0 Request:\n{}", xacmlRequest);
    return xacmlRequest;
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) ParserException(org.codice.ddf.parser.ParserException) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 19 with ObjectFactory

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

the class CswQueryResponseTransformer method writeAcknowledgement.

private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:" + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
        Marshaller marshaller = jaxBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        AcknowledgementType ack = new AcknowledgementType();
        EchoedRequestType echoedRequest = new EchoedRequestType();
        JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
        echoedRequest.setAny(jaxBRequest);
        ack.setEchoedRequest(echoedRequest);
        try {
            ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        } catch (DatatypeConfigurationException e) {
            LOGGER.debug("Failed to set timestamp on Acknowledgement, Exception {}", e);
        }
        JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
        marshaller.marshal(jaxBAck, byteArrayOutputStream);
        return byteArrayOutputStream;
    } catch (JAXBException e) {
        throw new CatalogTransformerException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBContext(javax.xml.bind.JAXBContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 20 with ObjectFactory

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

the class WfsSource method logMessage.

private void logMessage(GetFeatureType getFeature) {
    if (LOGGER.isDebugEnabled()) {
        try {
            StringWriter writer = new StringWriter();
            JAXBContext contextObj = JAXBContext.newInstance(GetFeatureType.class);
            Marshaller marshallerObj = contextObj.createMarshaller();
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshallerObj.marshal(new ObjectFactory().createGetFeature(getFeature), writer);
            LOGGER.debug("WfsSource {}: {}", getId(), writer.toString());
        } catch (JAXBException e) {
            LOGGER.debug("An error occurred debugging the GetFeature request", e);
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ObjectFactory(ogc.schema.opengis.wfs.v_1_0_0.ObjectFactory) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)13 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 JAXBElement (javax.xml.bind.JAXBElement)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)7 Marshaller (javax.xml.bind.Marshaller)7 StringWriter (java.io.StringWriter)6 JAXBContext (javax.xml.bind.JAXBContext)6 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)6 Test (org.junit.Test)6 XStream (com.thoughtworks.xstream.XStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Writer (java.io.Writer)5 ArrayList (java.util.ArrayList)5 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)5 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)5 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)5 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)5 Matchers.anyString (org.mockito.Matchers.anyString)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4