use of org.talend.ms.crm.sdk.RequestDateTimeData 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;
}
}
Aggregations