List of usage examples for javax.xml.soap SOAPMessage getSOAPPart
public abstract SOAPPart getSOAPPart();
From source file:be.e_contract.mycarenet.sts.WSSecuritySOAPHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws WSSecurityException { LOG.debug("adding WS-Security header"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecHeader wsSecHeader = new WSSecHeader(); wsSecHeader.insertSecurityHeader(soapPart); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.setTimeToLive(60);//from w w w . j a v a 2 s .c om wsSecTimeStamp.build(soapPart, wsSecHeader); WSSecurityCrypto crypto = new WSSecurityCrypto(this.privateKey, this.certificate); WSSConfig wssConfig = new WSSConfig(); wssConfig.setWsiBSPCompliant(false); WSSecSignature sign = new WSSecSignature(wssConfig); sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); sign.prepare(soapPart, crypto, wsSecHeader); String bstId = sign.getBSTTokenId(); sign.appendBSTElementToHeader(wsSecHeader); Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>(); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart.getDocumentElement()); signParts.add(new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(), "Content")); signParts.add(new WSEncryptionPart(bstId)); signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId())); List<Reference> referenceList = sign.addReferencesToSign(signParts, wsSecHeader); sign.computeSignature(referenceList, false, null); }
From source file:be.e_contract.mycarenet.async.SecuritySOAPHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException, WSSecurityException { LOG.debug("adding WS-Security header"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecHeader wsSecHeader = new WSSecHeader(); wsSecHeader.insertSecurityHeader(soapPart); WSSecUsernameToken usernameToken = new WSSecUsernameToken(); usernameToken.setUserInfo(this.packageLicenseKey.getUsername(), this.packageLicenseKey.getPassword()); usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT); usernameToken.prepare(soapPart);//from w w w. j a v a 2 s.c om usernameToken.prependToHeader(wsSecHeader); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.build(soapPart, wsSecHeader); WSSecurityCrypto crypto = new WSSecurityCrypto(this.sessionKey); WSSConfig wssConfig = new WSSConfig(); wssConfig.setWsiBSPCompliant(false); WSSecSignature sign = new WSSecSignature(wssConfig); sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); sign.prepare(soapPart, crypto, wsSecHeader); sign.appendBSTElementToHeader(wsSecHeader); Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>(); signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId())); signParts.add(new WSEncryptionPart(usernameToken.getId())); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart.getDocumentElement()); signParts.add(new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(), "Content")); sign.addReferencesToSign(signParts, wsSecHeader); List<Reference> referenceList = sign.addReferencesToSign(signParts, wsSecHeader); sign.computeSignature(referenceList, false, null); }
From source file:be.agiv.security.handler.WSTrustHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { if (null == this.secondaryParametersNodeList) { return;// w w w . ja v a2s . c o m } SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPBody soapBody = soapMessage.getSOAPBody(); NodeList nodeList = soapBody.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestSecurityToken"); if (0 == nodeList.getLength()) { return; } SOAPElement requestSecurityTokenElement = (SOAPElement) nodeList.item(0); String prefix = requestSecurityTokenElement.getPrefix(); SOAPElement secondaryParametersElement = requestSecurityTokenElement.addChildElement("SecondaryParameters", prefix); for (int idx = 0; idx < this.secondaryParametersNodeList.getLength(); idx++) { Node node = this.secondaryParametersNodeList.item(idx); Node importedNode = soapPart.importNode(node, true); secondaryParametersElement.appendChild(importedNode); } }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPHeader soapHeader = soapMessage.getSOAPHeader(); if (null == soapHeader) { SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapHeader = soapEnvelope.addHeader(); }//from www . j av a 2 s. c o m WSSecHeader wsSecHeader = new WSSecHeader(); Element securityElement; try { securityElement = wsSecHeader.insertSecurityHeader(soapPart); } catch (WSSecurityException e) { throw new SOAPException("WS-Security error: " + e.getMessage(), e); } soapHeader.removeChild(securityElement); soapHeader.appendChild(securityElement); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.build(soapPart, wsSecHeader); }
From source file:org.drools.camel.component.cxf.CxfSoapTestWithLookup.java
public void testCxfSoapSessionLookup() throws Exception { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1"); body.addBodyElement(payloadName);// w ww.j a v a 2 s. c o m String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\" disconnected=\"true\">\n"; cmd += " <org.drools.springframework.Person2>\n"; cmd += " <name>salaboy</name>\n"; cmd += " <age>27</age>\n"; cmd += " </org.drools.springframework.Person2>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; body.addTextNode(cmd); Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage); OutputStream out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream(); soapMessage = (SOAPMessage) object; soapMessage.writeTo(out); String response = out.toString(); assertTrue(response.contains("fact-handle identifier=\"salaboy\"")); SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage(); SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1"); body2.addBodyElement(payloadName2); String cmd2 = ""; cmd2 += "<batch-execution lookup=\"ksession2\">\n"; cmd2 += " <insert out-identifier=\"salaboy\" disconnected=\"true\">\n"; cmd2 += " <org.drools.springframework.Person3>\n"; cmd2 += " <name>salaboy</name>\n"; cmd2 += " <age>27</age>\n"; cmd2 += " </org.drools.springframework.Person3>\n"; cmd2 += " </insert>\n"; cmd2 += " <fire-all-rules/>\n"; cmd2 += "</batch-execution>\n"; body2.addTextNode(cmd2); Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2); OutputStream out2 = new ByteArrayOutputStream(); out2 = new ByteArrayOutputStream(); soapMessage2 = (SOAPMessage) object2; soapMessage2.writeTo(out2); String response2 = out2.toString(); assertTrue(response2.contains("fact-handle identifier=\"salaboy\"")); }
From source file:org.kie.camel.component.cxf.CxfSoapTestWithLookup.java
public void testCxfSoapSessionLookup() throws Exception { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1"); body.addBodyElement(payloadName);/* w w w.j a v a2 s .c o m*/ String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"salaboy\" disconnected=\"true\">\n"; cmd += " <org.kie.springframework.Person2>\n"; cmd += " <name>salaboy</name>\n"; cmd += " <age>27</age>\n"; cmd += " </org.kie.springframework.Person2>\n"; cmd += " </insert>\n"; cmd += " <fire-all-rules/>\n"; cmd += "</batch-execution>\n"; body.addTextNode(cmd); Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage); OutputStream out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream(); soapMessage = (SOAPMessage) object; soapMessage.writeTo(out); String response = out.toString(); assertTrue(response.contains("fact-handle identifier=\"salaboy\"")); SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage(); SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1"); body2.addBodyElement(payloadName2); String cmd2 = ""; cmd2 += "<batch-execution lookup=\"ksession2\">\n"; cmd2 += " <insert out-identifier=\"salaboy\" disconnected=\"true\">\n"; cmd2 += " <org.kie.springframework.Person3>\n"; cmd2 += " <name>salaboy</name>\n"; cmd2 += " <age>27</age>\n"; cmd2 += " </org.kie.springframework.Person3>\n"; cmd2 += " </insert>\n"; cmd2 += " <fire-all-rules/>\n"; cmd2 += "</batch-execution>\n"; body2.addTextNode(cmd2); Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2); OutputStream out2 = new ByteArrayOutputStream(); out2 = new ByteArrayOutputStream(); soapMessage2 = (SOAPMessage) object2; soapMessage2.writeTo(out2); String response2 = out2.toString(); assertTrue(response2.contains("fact-handle identifier=\"salaboy\"")); }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java
private void handleInboundMessage(SOAPMessageContext context) throws SOAPException { SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); if (null == soapHeader) { return;//from www.j ava 2s . c o m } Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements(); while (headerIterator.hasNext()) { SOAPHeaderElement soapHeaderElement = headerIterator.next(); if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) { continue; } if (false == "Security".equals(soapHeaderElement.getLocalName())) { continue; } Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements(); while (securityElementIterator.hasNext()) { SOAPElement securityElement = securityElementIterator.next(); if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) { continue; } if (false == "Assertion".equals(securityElement.getLocalName())) { continue; } LOG.debug("putting SAML token on JAX-WS context"); context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement); context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION); } } }
From source file:be.fedict.trust.client.WSSecurityClientHandler.java
public boolean handleMessage(SOAPMessageContext soapMessageContext) { Boolean outboundProperty = (Boolean) soapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); SOAPMessage soapMessage = soapMessageContext.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); if (false == outboundProperty.booleanValue()) { /*// www.j ava2 s . co m * Validate incoming WS-Security header if present */ return handleInboundDocument(soapPart, soapMessageContext); } return true; }
From source file:be.e_contract.mycarenet.ehealth.common.WSSecuritySOAPHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws WSSecurityException, SAXException, IOException { LOG.debug("adding WS-Security header"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecHeader wsSecHeader = new WSSecHeader(); wsSecHeader.insertSecurityHeader(soapPart); WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp(); wsSecTimeStamp.setTimeToLive(60);//from www. j av a 2 s . c o m wsSecTimeStamp.build(soapPart, wsSecHeader); Document assertionDocument = this.documentBuilder .parse(new InputSource(new StringReader(this.samlAssertion))); Element assertionElement = assertionDocument.getDocumentElement(); String assertionId = assertionElement.getAttribute("AssertionID"); Element importedAssertionElement = (Element) soapPart.importNode(assertionElement, true); Element securityHeaderElement = wsSecHeader.getSecurityHeader(); securityHeaderElement.appendChild(importedAssertionElement); WSSecSignature wsSecSignature = new WSSecSignature(); wsSecSignature.setSignatureAlgorithm(WSConstants.RSA); wsSecSignature.setKeyIdentifierType(WSConstants.CUSTOM_KEY_IDENTIFIER); wsSecSignature.setCustomTokenValueType(WSConstants.WSS_SAML_KI_VALUE_TYPE); wsSecSignature.setCustomTokenId(assertionId); Crypto crypto = new WSSecurityCrypto(this.privateKey, null); wsSecSignature.prepare(soapPart, crypto, wsSecHeader); Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>(); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapPart.getDocumentElement()); signParts.add(new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(), "Content")); signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId())); List<Reference> referenceList = wsSecSignature.addReferencesToSign(signParts, wsSecHeader); wsSecSignature.computeSignature(referenceList, false, null); }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java
private void generateSOAPErrorMessage(SOAPMessage msg, String reason) { try {//from w ww .j a v a 2 s .c o m SOAPBody soapBody = msg.getSOAPPart().getEnvelope().getBody(); SOAPFault soapFault = soapBody.addFault(); soapFault.setFaultString(reason); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { } }