org.apache.cxf.staxutils.W3CDOMStreamWriter Java Examples

The following examples show how to use org.apache.cxf.staxutils.W3CDOMStreamWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpnegoContextTokenInInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void writeProofToken(
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace,
    byte[] key
) throws Exception {
    // RequestedProofToken
    writer.writeStartElement(prefix, "RequestedProofToken", namespace);
    
    // EncryptedKey
    writer.writeStartElement(WSConstants.ENC_PREFIX, "EncryptedKey", WSConstants.ENC_NS);
    writer.writeStartElement(WSConstants.ENC_PREFIX, "EncryptionMethod", WSConstants.ENC_NS);
    writer.writeAttribute("Algorithm", namespace + "/spnego#GSS_Wrap");
    writer.writeEndElement();
    writer.writeStartElement(WSConstants.ENC_PREFIX, "CipherData", WSConstants.ENC_NS);
    writer.writeStartElement(WSConstants.ENC_PREFIX, "CipherValue", WSConstants.ENC_NS);

    writer.writeCharacters(Base64.encode(key));
    
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    
    writer.writeEndElement();
}
 
Example #2
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
Element writeSecurityTokenReference(
    W3CDOMStreamWriter writer,
    String id,
    String refValueType
) {
    Reference ref = new Reference(writer.getDocument());
    ref.setURI(id);
    if (refValueType != null) {
        ref.setValueType(refValueType);
    }
    SecurityTokenReference str = new SecurityTokenReference(writer.getDocument());
    str.setReference(ref);

    writer.getCurrentNode().appendChild(str.getElement());
    return str.getElement();
}
 
Example #3
Source File: STSInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void doCancel(
    Exchange exchange,
    SecurityToken cancelToken,
    W3CDOMStreamWriter writer,
    String prefix,
    String namespace
) throws Exception {
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeStartElement(prefix, "RequestSecurityTokenResponseCollection", namespace);
    }
    writer.writeStartElement(prefix, "RequestSecurityTokenResponse", namespace);

    TokenStore store = (TokenStore)exchange.getEndpoint().getEndpointInfo()
            .getProperty(TokenStore.class.getName());
    store.remove(cancelToken.getId());
    // Put the token on the out message so that we can sign the response
    exchange.put(SecurityConstants.TOKEN, cancelToken);
    writer.writeEmptyElement(prefix, "RequestedTokenCancelled", namespace);

    writer.writeEndElement();
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeEndElement();
    }
}
 
Example #4
Source File: SoapPayloadReaderFilter.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private void processStartElement(final XMLEvent event) {
    final QName name = event.asStartElement().getName();

    if (soapVersion.getEnvelope().equals(name)) {
        inEnvelope = true;
    } else if (inEnvelope && soapVersion.getHeader().equals(name)) {
        inHeader = true;
        // create a writer for headers
        this.headersWriter = new W3CDOMStreamWriter();
    } else if (inEnvelope && soapVersion.getBody().equals(name)) {
        inBody = true;
    }

    if (inBody && !inBodyPart) {
        inBodyPart = !soapVersion.getBody().equals(name);
        bodyPartName = name;
        bodyPartBytes = new ByteArrayOutputStream();
        try {
            bodyPartWriter = XML_OUTPUT_FACTORY.createXMLStreamWriter(new StreamResult(bodyPartBytes));
        } catch (XMLStreamException e) {
            throw new RuntimeCamelException(String.format("Error parsing body part %s: %s", bodyPartName,
                e.getMessage()), e);
        }
    }
}
 
Example #5
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String writeKeyType(W3CDOMStreamWriter writer, String keyTypeToWrite) 
    throws XMLStreamException {
    if (isSecureConv) {
        if (keyTypeToWrite == null) {
            writer.writeStartElement("wst", "TokenType", namespace);
            writer.writeCharacters(STSUtils.getTokenTypeSCT(namespace));
            writer.writeEndElement();
            keyTypeToWrite = namespace + "/SymmetricKey";
        }
    } else if (keyTypeToWrite == null && sendKeyType) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(namespace + "/SymmetricKey");
        writer.writeEndElement();
        keyTypeToWrite = namespace + "/SymmetricKey";
    } else if (keyTypeToWrite != null) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(keyTypeToWrite);
        writer.writeEndElement();
    }
    return keyTypeToWrite;
}
 
Example #6
Source File: EndpointReferenceUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static Source convertToXML(EndpointReferenceType epr) {
    try {
        Marshaller jm = getJAXBContextForEPR().createMarshaller();
        jm.setProperty(Marshaller.JAXB_FRAGMENT, true);
        QName qname = new QName("http://www.w3.org/2005/08/addressing", "EndpointReference");
        JAXBElement<EndpointReferenceType> jaxEle
            = new JAXBElement<>(qname, EndpointReferenceType.class, epr);


        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        jm.marshal(jaxEle, writer);
        return new DOMSource(writer.getDocument());
    } catch (JAXBException e) {
        //ignore
    }
    return null;
}
 
Example #7
Source File: SecurityTokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testLifetimeNoExpires() throws Exception {
    String key = "key";
    Element tokenElement = DOMUtils.createDocument().createElement("token");

    // Create Lifetime
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    Instant created = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    writer.writeStartElement("wst", "Lifetime", WST_NS_05_12);
    writer.writeStartElement("wsu", "Created", WSU_NS);
    writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    writer.writeEndElement();

    writer.writeEndElement();

    SecurityToken token = new SecurityToken(key, tokenElement, writer.getDocument().getDocumentElement());
    assertEquals(key, token.getId());
    assertEquals(created, token.getCreated());
    assertNull(token.getExpires());
}
 
Example #8
Source File: OutTransformWriterTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespaceConversionAndDefaultNS() throws Exception {
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();

    Map<String, String> outMap = new HashMap<>();
    outMap.put("{http://testbeans.com}testBean", "{http://testbeans.com/v2}testBean");
    outMap.put("{http://testbeans.com}bean", "{http://testbeans.com/v3}bean");
    OutTransformWriter transformWriter = new OutTransformWriter(writer,
                                                                outMap,
                                                                Collections.<String, String>emptyMap(),
                                                                Collections.<String>emptyList(),
                                                                false,
                                                                "http://testbeans.com/v2");
    JAXBContext context = JAXBContext.newInstance(TestBean.class);
    Marshaller m = context.createMarshaller();
    m.marshal(new TestBean(), transformWriter);

    Element el = writer.getDocument().getDocumentElement();
    assertEquals("http://testbeans.com/v2", el.getNamespaceURI());
    assertTrue(StringUtils.isEmpty(el.getPrefix()));

    el = DOMUtils.getFirstElement(el);
    assertEquals("http://testbeans.com/v3", el.getNamespaceURI());
    assertFalse(StringUtils.isEmpty(el.getPrefix()));
}
 
Example #9
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
private void doCancel(
    Exchange exchange, 
    SecurityToken cancelToken, 
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace
) throws Exception {
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeStartElement(prefix, "RequestSecurityTokenResponseCollection", namespace);
    }
    writer.writeStartElement(prefix, "RequestSecurityTokenResponse", namespace);
    
    TokenStore store = (TokenStore)exchange.get(Endpoint.class).getEndpointInfo()
            .getProperty(TokenStore.class.getName());
    store.remove(cancelToken.getId());
    writer.writeEmptyElement(prefix, "RequestedTokenCancelled", namespace);
    
    writer.writeEndElement();
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeEndElement();
    }
}
 
Example #10
Source File: AbstractSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected String writeKeyType(W3CDOMStreamWriter writer, String keyTypeToWrite)
    throws XMLStreamException {
    if (isSecureConv) {
        if (keyTypeToWrite == null) {
            writer.writeStartElement("wst", "TokenType", namespace);
            writer.writeCharacters(STSUtils.getTokenTypeSCT(namespace));
            writer.writeEndElement();
            keyTypeToWrite = namespace + "/SymmetricKey";
        }
    } else if (keyTypeToWrite == null && sendKeyType) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(namespace + "/SymmetricKey");
        writer.writeEndElement();
        keyTypeToWrite = namespace + "/SymmetricKey";
    } else if (keyTypeToWrite != null) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(keyTypeToWrite);
        writer.writeEndElement();
    }
    return keyTypeToWrite;
}
 
Example #11
Source File: AbstractSTSTest.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
protected Element createClaimsElement(List<String> realmClaims) throws Exception {
    if (realmClaims == null || realmClaims.isEmpty()) {
        return null;
    }

    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "Claims", STSUtils.WST_NS_05_12);
    writer.writeNamespace("wst", STSUtils.WST_NS_05_12);
    writer.writeNamespace("ic", "http://schemas.xmlsoap.org/ws/2005/05/identity");
    writer.writeAttribute("Dialect", "http://schemas.xmlsoap.org/ws/2005/05/identity");

    if (realmClaims != null && !realmClaims.isEmpty()) {
        for (String item : realmClaims) {
            writer.writeStartElement("ic", "ClaimType", "http://schemas.xmlsoap.org/ws/2005/05/identity");
            writer.writeAttribute("Uri", item);
            //writer.writeAttribute("Optional", "true");
            writer.writeEndElement();
        }
    }

    writer.writeEndElement();

    return writer.getDocument().getDocumentElement();
}
 
Example #12
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String writeKeyType(W3CDOMStreamWriter writer, String keyTypeToWrite) 
    throws XMLStreamException {
    if (isSecureConv) {
        if (keyTypeToWrite == null) {
            writer.writeStartElement("wst", "TokenType", namespace);
            writer.writeCharacters(STSUtils.getTokenTypeSCT(namespace));
            writer.writeEndElement();
            keyTypeToWrite = namespace + "/SymmetricKey";
        }
    } else if (keyTypeToWrite == null && sendKeyType) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(namespace + "/SymmetricKey");
        writer.writeEndElement();
        keyTypeToWrite = namespace + "/SymmetricKey";
    } else if (keyTypeToWrite != null) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(keyTypeToWrite);
        writer.writeEndElement();
    }
    return keyTypeToWrite;
}
 
Example #13
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String writeKeyType(W3CDOMStreamWriter writer, String keyTypeToWrite) 
    throws XMLStreamException {
    if (isSecureConv) {
        if (keyTypeToWrite == null) {
            writer.writeStartElement("wst", "TokenType", namespace);
            writer.writeCharacters(STSUtils.getTokenTypeSCT(namespace));
            writer.writeEndElement();
            keyTypeToWrite = namespace + "/SymmetricKey";
        }
    } else if (keyTypeToWrite == null && sendKeyType) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(namespace + "/SymmetricKey");
        writer.writeEndElement();
        keyTypeToWrite = namespace + "/SymmetricKey";
    } else if (keyTypeToWrite != null) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(keyTypeToWrite);
        writer.writeEndElement();
    }
    return keyTypeToWrite;
}
 
Example #14
Source File: STSInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
void writeLifetime(
    W3CDOMStreamWriter writer,
    Instant created,
    Instant expires,
    String prefix,
    String namespace
) throws Exception {
    writer.writeStartElement(prefix, "Lifetime", namespace);
    writer.writeNamespace("wsu", WSS4JConstants.WSU_NS);
    writer.writeStartElement("wsu", "Created", WSS4JConstants.WSU_NS);
    writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    writer.writeEndElement();

    writer.writeStartElement("wsu", "Expires", WSS4JConstants.WSU_NS);
    writer.writeCharacters(expires.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
    writer.writeEndElement();
    writer.writeEndElement();
}
 
Example #15
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
private void doCancel(
    Exchange exchange, 
    SecurityToken cancelToken, 
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace
) throws Exception {
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeStartElement(prefix, "RequestSecurityTokenResponseCollection", namespace);
    }
    writer.writeStartElement(prefix, "RequestSecurityTokenResponse", namespace);
    
    TokenStore store = (TokenStore)exchange.get(Endpoint.class).getEndpointInfo()
            .getProperty(TokenStore.class.getName());
    store.remove(cancelToken.getId());
    writer.writeEmptyElement(prefix, "RequestedTokenCancelled", namespace);
    
    writer.writeEndElement();
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeEndElement();
    }
}
 
Example #16
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
Element writeSecurityTokenReference(
    W3CDOMStreamWriter writer,
    String id,
    String refValueType
) {
    Reference ref = new Reference(writer.getDocument());
    ref.setURI(id);
    if (refValueType != null) {
        ref.setValueType(refValueType);
    }
    SecurityTokenReference str = new SecurityTokenReference(writer.getDocument());
    str.setReference(ref);

    writer.getCurrentNode().appendChild(str.getElement());
    return str.getElement();
}
 
Example #17
Source File: SimpleBatchSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected String writeKeyType(W3CDOMStreamWriter writer, String keyTypeToWrite)
    throws XMLStreamException {
    if (isSecureConv) {
        if (keyTypeToWrite == null) {
            writer.writeStartElement("wst", "TokenType", namespace);
            writer.writeCharacters(STSUtils.getTokenTypeSCT(namespace));
            writer.writeEndElement();
            keyTypeToWrite = namespace + "/SymmetricKey";
        }
    } else if (keyTypeToWrite == null && sendKeyType) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(namespace + "/SymmetricKey");
        writer.writeEndElement();
        keyTypeToWrite = namespace + "/SymmetricKey";
    } else if (keyTypeToWrite != null) {
        writer.writeStartElement("wst", "KeyType", namespace);
        writer.writeCharacters(keyTypeToWrite);
        writer.writeEndElement();
    }
    return keyTypeToWrite;
}
 
Example #18
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
void writeLifetime(
    W3CDOMStreamWriter writer,
    Date created,
    Date expires,
    String prefix,
    String namespace
) throws Exception {
    XmlSchemaDateFormat fmt = new XmlSchemaDateFormat();
    writer.writeStartElement(prefix, "Lifetime", namespace);
    writer.writeNamespace("wsu", WSConstants.WSU_NS);
    writer.writeStartElement("wsu", "Created", WSConstants.WSU_NS);
    writer.writeCharacters(fmt.format(created.getTime()));
    writer.writeEndElement();
    
    writer.writeStartElement("wsu", "Expires", WSConstants.WSU_NS);
    writer.writeCharacters(fmt.format(expires.getTime()));
    writer.writeEndElement();
    writer.writeEndElement();
}
 
Example #19
Source File: STSClientAction.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
private Element createClaimsElement(List<RequestClaim> realmClaims)
    throws ParserConfigurationException, XMLStreamException {
    if (realmClaims == null || realmClaims.isEmpty()) {
        return null;
    }

    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "Claims", STSUtils.WST_NS_05_12);
    writer.writeNamespace("wst", STSUtils.WST_NS_05_12);
    writer.writeNamespace("ic", HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_05_IDENTITY);
    writer.writeAttribute("Dialect", HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_05_IDENTITY);

    if (!realmClaims.isEmpty()) {
        for (RequestClaim item : realmClaims) {
            LOG.debug("  {}", item.getClaimType().toString());
            writer.writeStartElement("ic", "ClaimType", HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_05_IDENTITY);
            writer.writeAttribute("Uri", item.getClaimType().toString());
            writer.writeAttribute("Optional", Boolean.toString(item.isOptional()));
            writer.writeEndElement();
        }
    }

    writer.writeEndElement();

    return writer.getDocument().getDocumentElement();
}
 
Example #20
Source File: STSInvoker.java    From steady with Apache License 2.0 6 votes vote down vote up
private void doCancel(
    Exchange exchange, 
    SecurityToken cancelToken, 
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace
) throws Exception {
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeStartElement(prefix, "RequestSecurityTokenResponseCollection", namespace);
    }
    writer.writeStartElement(prefix, "RequestSecurityTokenResponse", namespace);
    
    TokenStore store = (TokenStore)exchange.get(Endpoint.class).getEndpointInfo()
            .getProperty(TokenStore.class.getName());
    store.remove(cancelToken.getId());
    writer.writeEmptyElement(prefix, "RequestedTokenCancelled", namespace);
    
    writer.writeEndElement();
    if (STSUtils.WST_NS_05_12.equals(namespace)) {
        writer.writeEndElement();
    }
}
 
Example #21
Source File: LogicalHandlerInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void handleAbort(Message message, W3CDOMStreamWriter writer) {
    message.getInterceptorChain().abort();

    if (!message.getExchange().isOneWay()) {
        //server side inbound
        Endpoint e = message.getExchange().getEndpoint();
        Message responseMsg = new MessageImpl();
        responseMsg.setExchange(message.getExchange());
        responseMsg = e.getBinding().createMessage(responseMsg);

        message.getExchange().setOutMessage(responseMsg);
        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
        if (reader == null && writer != null) {
            reader = StaxUtils.createXMLStreamReader(writer.getDocument());
        }

        InterceptorChain chain = OutgoingChainInterceptor
            .getOutInterceptorChain(message.getExchange());
        responseMsg.setInterceptorChain(chain);
        responseMsg.put("LogicalHandlerInterceptor.INREADER", reader);

        chain.doIntercept(responseMsg);
    }
}
 
Example #22
Source File: SpnegoContextTokenInInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void writeProofToken(
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace,
    byte[] key
) throws Exception {
    // RequestedProofToken
    writer.writeStartElement(prefix, "RequestedProofToken", namespace);
    
    // EncryptedKey
    writer.writeStartElement(WSConstants.ENC_PREFIX, "EncryptedKey", WSConstants.ENC_NS);
    writer.writeStartElement(WSConstants.ENC_PREFIX, "EncryptionMethod", WSConstants.ENC_NS);
    writer.writeAttribute("Algorithm", namespace + "/spnego#GSS_Wrap");
    writer.writeEndElement();
    writer.writeStartElement(WSConstants.ENC_PREFIX, "CipherData", WSConstants.ENC_NS);
    writer.writeStartElement(WSConstants.ENC_PREFIX, "CipherValue", WSConstants.ENC_NS);

    writer.writeCharacters(Base64.encode(key));
    
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    
    writer.writeEndElement();
}
 
Example #23
Source File: AbstractBindingBuilder.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Element cloneElement(Element el) {
    Document doc = secHeader.getSecurityHeaderElement().getOwnerDocument();
    if (!doc.equals(el.getOwnerDocument())) {

        XMLStreamReader reader = StaxUtils.createXMLStreamReader(el);
        DocumentFragment fragment = doc.createDocumentFragment();
        W3CDOMStreamWriter writer = new W3CDOMStreamWriter(fragment);
        try {
            StaxUtils.copy(reader, writer);
            return (Element)fragment.getFirstChild();
        } catch (XMLStreamException ex) {
            LOG.log(Level.FINE, "Error cloning security element", ex);
        }
    }
    return el;
}
 
Example #24
Source File: STSInvoker.java    From steady with Apache License 2.0 5 votes vote down vote up
abstract void doIssue(
    Element requestEl,
    Exchange exchange,
    Element binaryExchange,
    W3CDOMStreamWriter writer,
    String prefix, 
    String namespace
) throws Exception;
 
Example #25
Source File: AbstractSTSClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void writeElementsForRSTPublicKey(W3CDOMStreamWriter writer,
        X509Certificate cert) throws Exception {
    writer.writeStartElement("wst", "UseKey", namespace);
    writer.writeStartElement("ds", "KeyInfo", "http://www.w3.org/2000/09/xmldsig#");
    writer.writeNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");

    boolean useCert = useCertificateForConfirmationKeyInfo;
    String useCertStr = (String)getProperty(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO);
    if (useCertStr != null) {
        useCert = Boolean.parseBoolean(useCertStr);
    }
    if (useCert) {
        X509Data certElem = new X509Data(writer.getDocument());
        certElem.addCertificate(cert);
        writer.getCurrentNode().appendChild(certElem.getElement());
    } else {
        writer.writeStartElement("ds", "KeyValue", "http://www.w3.org/2000/09/xmldsig#");
        PublicKey key = cert.getPublicKey();
        String pubKeyAlgo = key.getAlgorithm();
        if ("DSA".equalsIgnoreCase(pubKeyAlgo)) {
            DSAKeyValue dsaKeyValue = new DSAKeyValue(writer.getDocument(), key);
            writer.getCurrentNode().appendChild(dsaKeyValue.getElement());
        } else if ("RSA".equalsIgnoreCase(pubKeyAlgo)) {
            RSAKeyValue rsaKeyValue = new RSAKeyValue(writer.getDocument(), key);
            writer.getCurrentNode().appendChild(rsaKeyValue.getElement());
        }
        writer.writeEndElement();
    }

    writer.writeEndElement();
    writer.writeEndElement();
}
 
Example #26
Source File: STSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
abstract void doRenew(
        Element requestEl,
        Exchange exchange,
        SecurityToken renewToken,
        Element binaryExchange,
        W3CDOMStreamWriter writer,
        String prefix,
        String namespace
) throws Exception;
 
Example #27
Source File: MappingBeanDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Element transformElement(Element element) {

        W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter();
        OutTransformWriter transformWriter = new OutTransformWriter(domWriter, transformMap);
        try {
            StaxUtils.copy(element, transformWriter);
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        }
        return domWriter.getDocument().getDocumentElement();
    }
 
Example #28
Source File: STSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
Element writeSecurityTokenReference(
    W3CDOMStreamWriter writer,
    String id,
    String instance,
    String refValueType
) {
    Reference ref = new Reference(writer.getDocument());
    ref.setURI(id);
    if (refValueType != null) {
        ref.setValueType(refValueType);
    }
    SecurityTokenReference str = new SecurityTokenReference(writer.getDocument());
    str.addWSSENamespace();
    str.setReference(ref);

    if (instance != null) {
        try {
            Element firstChildElement = str.getFirstElement();
            if (firstChildElement != null) {
                int version = NegotiationUtils.getWSCVersion(refValueType);
                String ns = ConversationConstants.getWSCNs(version);
                firstChildElement.setAttributeNS(ns, "wsc:" + ConversationConstants.INSTANCE_LN,
                                                 instance);
            }
        } catch (WSSecurityException e) {
            //just return without wsc:Instance
        }
    }

    writer.getCurrentNode().appendChild(str.getElement());
    return str.getElement();
}
 
Example #29
Source File: LogicalMessageImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void setPayload(Object arg0, JAXBContext arg1) {
    try {
        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
        arg1.createMarshaller().marshal(arg0, writer);
        Source source = new DOMSource(writer.getDocument().getDocumentElement());

        setPayload(source);
    } catch (JAXBException e) {
        throw new WebServiceException(e);
    }
}
 
Example #30
Source File: AbstractSTSClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addBinaryExchange(
    String binaryExchange,
    W3CDOMStreamWriter writer
) throws XMLStreamException {
    writer.writeStartElement("wst", "BinaryExchange", namespace);
    writer.writeAttribute("EncodingType", WSS4JConstants.BASE64_ENCODING);
    writer.writeAttribute("ValueType", namespace + "/spnego");
    writer.writeCharacters(binaryExchange);
    writer.writeEndElement();
}