use of org.apache.axiom.soap.SOAPHeaderBlock in project tdi-studio-se by Talend.
the class MSCRMClient method createCRMSecurityHeaderBlock.
private static SOAPHeaderBlock createCRMSecurityHeaderBlock(SecurityData securityData) throws XMLStreamException {
RequestDateTimeData dateTimeData = WsdlTokenManager.getRequestDateTime();
String currentDateTime = dateTimeData.getCreatedDateTime();
String expireDateTime = dateTimeData.getExpiresDateTime();
String securityHeaderTemplate = "<EncryptedData " + " xmlns=\"http://www.w3.org/2001/04/xmlenc#\"" + " Id=\"Assertion0\" " + " Type=\"http://www.w3.org/2001/04/xmlenc#Element\">" + " <EncryptionMethod " + " Algorithm=\"http://www.w3.org/2001/04/xmlenc#tripledes-cbc\"/>" + " <ds:KeyInfo " + " xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">" + " <EncryptedKey>" + " <EncryptionMethod " + " Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"/>" + " <ds:KeyInfo Id=\"keyinfo\">" + " <wsse:SecurityTokenReference " + " xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + " <wsse:KeyIdentifier " + " EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" " + " ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier\">%s</wsse:KeyIdentifier>" + " </wsse:SecurityTokenReference>" + " </ds:KeyInfo>" + " <CipherData>" + " <CipherValue>%s</CipherValue>" + " </CipherData>" + " </EncryptedKey>" + " </ds:KeyInfo>" + " <CipherData>" + " <CipherValue>%s</CipherValue>" + " </CipherData>" + "</EncryptedData>";
String securityHeader = String.format(securityHeaderTemplate, securityData.getKeyIdentifier(), securityData.getSecurityToken0(), securityData.getSecurityToken1());
try {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace securityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "o");
OMNamespace utitlityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "u");
OMElement timeStamp = factory.createOMElement("Timestamp", utitlityNS);
timeStamp.addAttribute("Id", "_0", utitlityNS);
OMElement created = factory.createOMElement("Created", utitlityNS);
OMText createdTime = factory.createOMText(currentDateTime + "Z");
created.addChild(createdTime);
OMElement expires = factory.createOMElement("Expires", utitlityNS);
OMText expiresTime = factory.createOMText(expireDateTime + "Z");
expires.addChild(expiresTime);
timeStamp.addChild(created);
timeStamp.addChild(expires);
SOAPHeaderBlock wsseHeader = OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("Security", securityNS);
wsseHeader.setMustUnderstand(true);
wsseHeader.addChild(timeStamp);
wsseHeader.addChild(AXIOMUtil.stringToOM(factory, securityHeader));
return wsseHeader;
} catch (XMLStreamException e) {
logger.error(e.getMessage());
throw e;
}
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestExtractAllHeaderBlocks method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader(envelope);
OMNamespace ns = soapFactory.createOMNamespace("urn:ns", "p");
SOAPHeaderBlock h1 = header.addHeaderBlock("header1", ns);
SOAPHeaderBlock h2 = header.addHeaderBlock("header2", ns);
Iterator<SOAPHeaderBlock> it = header.extractAllHeaderBlocks();
assertTrue(it.hasNext());
assertSame(h1, it.next());
assertTrue(it.hasNext());
assertSame(h2, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestExamineMustUnderstandHeaderBlocksWithParser method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
String roleNextURI = spec.getNextRoleURI();
Iterator<SOAPHeaderBlock> it = envelope.getHeader().examineMustUnderstandHeaderBlocks(roleNextURI);
assertThat(it.hasNext()).isTrue();
SOAPHeaderBlock headerBlock = it.next();
assertThat(headerBlock.getQName()).isEqualTo(new QName("http://example.org/RoleTest", "h7"));
assertThat(headerBlock.getRole()).isEqualTo(roleNextURI);
assertThat(it.hasNext()).isFalse();
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetHeaderBlocksWithName method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
Iterator<SOAPHeaderBlock> it = envelope.getHeader().getHeaderBlocksWithName(new QName("http://example.org/RoleTest", "h2"));
assertThat(it.hasNext()).isTrue();
SOAPHeaderBlock headerBlock = it.next();
assertThat(headerBlock.getLocalName()).isEqualTo("h2");
assertThat(headerBlock.getText().trim()).isEqualTo("I'm so next.");
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetHeaderBlocksWithNSURIWithParser method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
ArrayList<SOAPHeaderBlock> headerBlocks = envelope.getHeader().getHeaderBlocksWithNSURI("urn:ns2");
assertThat(headerBlocks).hasSize(2);
assertThat(headerBlocks.get(0).getQName()).isEqualTo(new QName("urn:ns2", "h4"));
assertThat(headerBlocks.get(1).getQName()).isEqualTo(new QName("urn:ns2", "h6"));
}
Aggregations