Search in sources :

Example 71 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestWfs10JTStoGML200Converter method extractLineStringMemberCoordinates.

private String extractLineStringMemberCoordinates(JAXBElement element1) throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    assertThat(Wfs10Constants.LINESTRING_MEMBER.getLocalPart().equals(element1.getName().getLocalPart()), is(Boolean.TRUE));
    LineStringMemberType lsMemberType1 = (LineStringMemberType) element1.getValue();
    JAXBElement geometry1 = lsMemberType1.getGeometry();
    LineStringType lineStringType = (LineStringType) geometry1.getValue();
    return lineStringType.getCoordinates().getValue().replaceAll("\n", "").trim();
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) MultiLineStringType(ogc.schema.opengis.gml.v_2_1_2.MultiLineStringType) LineStringType(ogc.schema.opengis.gml.v_2_1_2.LineStringType) LineStringMemberType(ogc.schema.opengis.gml.v_2_1_2.LineStringMemberType)

Example 72 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestWfs10JTStoGML200Converter method testPointTypeToJAXB.

@Test
public void testPointTypeToJAXB() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    String pointGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(POINT));
    PointType pointType = (PointType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(pointGML, Wfs10Constants.POINT);
    JAXBElement<PointType> pointTypeJAXBElement = (JAXBElement<PointType>) Wfs10JTStoGML200Converter.convertGeometryTypeToJAXB(pointType);
    JAXB.marshal(pointTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, POINT_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}
Also used : Diff(org.custommonkey.xmlunit.Diff) PointType(ogc.schema.opengis.gml.v_2_1_2.PointType) MultiPointType(ogc.schema.opengis.gml.v_2_1_2.MultiPointType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 73 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class WssBasicAuthenticationHandler method getBaseAuthenticationToken.

protected BaseAuthenticationToken getBaseAuthenticationToken(String realm, String username, String password) {
    if (null == parser) {
        throw new IllegalStateException("XMLParser must be configured.");
    }
    UsernameTokenType usernameTokenType = new UsernameTokenType();
    AttributedString user = new AttributedString();
    user.setValue(username);
    usernameTokenType.setUsername(user);
    String usernameToken = null;
    // Add a password
    PasswordString pass = new PasswordString();
    pass.setValue(password);
    pass.setType(WSConstants.PASSWORD_TEXT);
    JAXBElement<PasswordString> passwordType = new JAXBElement<>(QNameConstants.PASSWORD, PasswordString.class, pass);
    usernameTokenType.getAny().add(passwordType);
    // Marshall the received JAXB object into a DOM Element
    List<String> ctxPath = new ArrayList<>(2);
    ctxPath.add(ObjectFactory.class.getPackage().getName());
    ctxPath.add(org.apache.cxf.ws.security.sts.provider.model.wstrust14.ObjectFactory.class.getPackage().getName());
    ParserConfigurator configurator = parser.configureParser(ctxPath, WssBasicAuthenticationHandler.class.getClassLoader());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JAXBElement<UsernameTokenType> tokenType = new JAXBElement<>(QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType);
    try {
        parser.marshal(configurator, tokenType, os);
        usernameToken = os.toString("UTF-8");
    } catch (ParserException | UnsupportedEncodingException ex) {
        LOGGER.info("Unable to parse username token.", ex);
    }
    BaseAuthenticationToken baseAuthenticationToken = new BaseAuthenticationToken(null, "", usernameToken);
    baseAuthenticationToken.setUseWssSts(true);
    return baseAuthenticationToken;
}
Also used : ParserException(org.codice.ddf.parser.ParserException) UsernameTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AttributedString(org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString) PasswordString(org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString) JAXBElement(javax.xml.bind.JAXBElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PasswordString(org.apache.cxf.ws.security.sts.provider.model.secext.PasswordString) ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) AttributedString(org.apache.cxf.ws.security.sts.provider.model.secext.AttributedString) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken)

Example 74 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class BSTAuthenticationToken method getBinarySecurityToken.

/**
     * Creates a binary security token based on the provided credential.
     */
private synchronized String getBinarySecurityToken(String credential) {
    Writer writer = new StringWriter();
    Marshaller marshaller = null;
    BinarySecurityTokenType binarySecurityTokenType = createBinarySecurityTokenType(credential);
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement = new JAXBElement<BinarySecurityTokenType>(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "BinarySecurityToken"), BinarySecurityTokenType.class, binarySecurityTokenType);
    if (BINARY_TOKEN_CONTEXT != null) {
        try {
            marshaller = BINARY_TOKEN_CONTEXT.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        } catch (JAXBException e) {
            LOGGER.debug("Exception while creating UsernameToken marshaller.", e);
        }
        if (marshaller != null) {
            try {
                marshaller.marshal(binarySecurityTokenElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Exception while writing username token.", e);
            }
        }
    }
    String binarySecurityToken = writer.toString();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Binary Security Token: {}", binarySecurityToken);
    }
    return binarySecurityToken;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) BinarySecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 75 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestGetRecordsResponseConverter method getRecords.

private void getRecords(final int maxRecords, final int startPosition, final int totalResults, final int expectedNext, final int expectedReturn) throws JAXBException, UnsupportedEncodingException {
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType query = new GetRecordsType();
    query.setMaxRecords(BigInteger.valueOf(maxRecords));
    query.setStartPosition(BigInteger.valueOf(startPosition));
    CswRecordCollection collection = createCswRecordCollection(query, totalResults);
    collection.setStartPosition(startPosition);
    String xml = xstream.toXML(collection);
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    assertThat(response.getSearchResults().getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(response.getSearchResults().getNumberOfRecordsReturned().intValue(), is(expectedReturn));
    assertThat(response.getSearchResults().getAbstractRecord().size(), is(expectedReturn));
    assertThat(response.getSearchResults().getNextRecord().intValue(), is(expectedNext));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XStream(com.thoughtworks.xstream.XStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)650 QName (javax.xml.namespace.QName)194 Element (org.w3c.dom.Element)124 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)95 ArrayList (java.util.ArrayList)93 MessageImpl (org.apache.cxf.message.MessageImpl)92 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 Test (org.junit.Test)87 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 JAXBException (javax.xml.bind.JAXBException)81 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 JAXBContext (javax.xml.bind.JAXBContext)75 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 Unmarshaller (javax.xml.bind.Unmarshaller)65 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58