List of usage examples for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY
String MESSAGE_OUTBOUND_PROPERTY
To view the source code for javax.xml.ws.handler MessageContext MESSAGE_OUTBOUND_PROPERTY.
Click Source Link
From source file:be.e_contract.mycarenet.async.SecuritySOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; }//from ww w. j a v a 2 s. co m try { handleOutboundMessage(context); } catch (Exception e) { LOG.error("outbound exception: " + e.getMessage(), e); throw new ProtocolException(e); } return true; }
From source file:be.e_contract.mycarenet.xkms2.ProofOfPossessionSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { if (null == this.sessionKey) { return true; }/*w ww . j a v a 2s . c om*/ if (null == this.prototypeKeyBindingId) { return true; } Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; } LOG.debug("adding proof of possession signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "RegisterRequest"); Element registerRequestElement = (Element) registerRequestNodeList.item(0); Document xkmsDocument; try { xkmsDocument = copyDocument(registerRequestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList proofOfPossessionNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(proofOfPossessionElement); } catch (Exception e) { LOG.error("error adding proof signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true); proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); proofOfPossessionElement.appendChild(signatureNode); return true; }
From source file:be.e_contract.mycarenet.xkms.ProofOfPossessionSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { if (null == this.sessionKey) { return true; }//from ww w . jav a 2s .c om if (null == this.prototypeKeyBindingId) { return true; } Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; } LOG.debug("adding proof of possession signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "Register"); Element registerRequestElement = (Element) registerRequestNodeList.item(0); Document xkmsDocument; try { xkmsDocument = copyDocument(registerRequestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList proofOfPossessionNodeList = xkmsDocument.getElementsByTagNameNS(XKMS_NAMESPACE, "ProofOfPossession"); Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(proofOfPossessionElement); } catch (Exception e) { LOG.error("error adding proof signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true); proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "ProofOfPossession"); proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); proofOfPossessionElement.appendChild(signatureNode); return true; }
From source file:be.e_contract.mycarenet.xkms2.KeyBindingAuthenticationSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; }/*from www. j a va2s . co m*/ LOG.debug("adding key binding authentication signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String requestElementName; if (null != this.prototypeKeyBindingId) { requestElementName = "RegisterRequest"; this.referenceUri = "#" + this.prototypeKeyBindingId; } else if (null != this.revokeKeyBindingId) { requestElementName = "RevokeRequest"; this.referenceUri = "#" + this.revokeKeyBindingId; } else { LOG.error("missing key binding id"); return false; } NodeList requestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, requestElementName); Element requestElement = (Element) requestNodeList.item(0); if (null == requestElement) { LOG.error("request element not present"); return false; } Document xkmsDocument; try { xkmsDocument = copyDocument(requestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList keyBindingAuthenticationNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); Element keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(keyBindingAuthenticationElement); } catch (Exception e) { LOG.error("error adding authn signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(keyBindingAuthenticationElement.getFirstChild(), true); keyBindingAuthenticationNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); keyBindingAuthenticationElement.appendChild(signatureNode); return true; }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); //for response message only, true for outbound messages, false for inbound if (!isRequest) { try {/*from ww w . j ava2 s . c om*/ WebServiceServerConfiguration configuration = getWebServiceServerConfiguration( ((com.sun.xml.ws.api.server.WSEndpoint) context.get("com.sun.xml.ws.api.server.WSEndpoint")) .getImplementationClass().getName()); SOAPMessage soapMsg = context.getMessage(); SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope(); SOAPHeader soapHeader = soapEnv.getHeader(); if (!configuration.isActive()) { generateSOAPErrorMessage(soapMsg, "Sorry webservice is disabled at application level!"); } if (configuration.isAuthenticatioNeeded()) { if (configuration.isUsingWSSecurity()) { if (soapHeader == null) { generateSOAPErrorMessage(soapMsg, "No header in message, unabled to validate security credentials"); } String username = null; String password = null; String nonce = null; String created = null; Iterator<SOAPElement> childElements = soapHeader.getChildElements(QNAME_WSSE_SECURITY); if (childElements.hasNext()) { SOAPElement securityElement = childElements.next(); Iterator<SOAPElement> usernameTokens = securityElement .getChildElements(QNAME_WSSE_USERNAME_TOKEN); if (usernameTokens.hasNext()) { SOAPElement usernameToken = usernameTokens.next(); username = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_USERNAME) .next()).getValue(); password = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_PASSWORD) .next()).getValue(); nonce = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_NONCE).next()) .getValue(); created = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_CREATED).next()) .getValue(); } } if (username == null || password == null || nonce == null || created == null) { generateSOAPErrorMessage(soapMsg, "Missing information, unabled to validate security credentials"); } SecurityHeader securityHeader = new SecurityHeader(configuration, username, password, nonce, created); if (!securityHeader.isValid()) { generateSOAPErrorMessage(soapMsg, "Invalid credentials"); } else { context.put(BennuWebService.SECURITY_HEADER, securityHeader); context.setScope(BennuWebService.SECURITY_HEADER, Scope.APPLICATION); } } else { com.sun.xml.ws.transport.Headers httpHeader = (Headers) context .get(MessageContext.HTTP_REQUEST_HEADERS); String username = null; String password = null; List<String> list = httpHeader.get("authorization"); if (list != null) { for (String value : list) { if (value.startsWith("Basic")) { String[] split = value.split(" "); try { String decoded = new String(Base64.decodeBase64(split[1]), "UTF-8"); String[] split2 = decoded.split(":"); if (split2.length == 2) { username = split2[0]; password = split2[1]; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } } if (username == null || password == null) { generateSOAPErrorMessage(soapMsg, "Missing information, unabled to validate security credentials"); } if (!configuration.validate(username, password)) { generateSOAPErrorMessage(soapMsg, "Invalid credentials"); } } } } catch (SOAPException e) { System.err.println(e); } } //continue other handler chain return true; }
From source file:be.e_contract.dssp.client.WSSecuritySOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (true == outboundProperty.booleanValue()) { try {//from w w w . j a v a 2 s. co m handleOutboundMessage(context); } catch (Exception e) { LOG.error("outbound exception: " + e.getMessage(), e); throw new ProtocolException(e); } } return true; }
From source file:eu.payzen.webservices.sdk.handler.soap.HeaderHandler.java
/** * Takes the outgoing SOAP message and modifies it adding the header * information/* w w w . j a v a 2 s. c om*/ * * @param smc SOAP message context * @return boolean indicating outbound property */ public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (Boolean.TRUE.equals(outboundProperty)) { SOAPMessage message = smc.getMessage(); try { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); //Creates header into SOAP envelope SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } // Add shopId addHeaderField(header, "shopId", this.shopId); // Add User name if (wsUser != null) { addHeaderField(header, "wsUser", this.wsUser); } // Add return url if (returnUrl != null) { addHeaderField(header, "returnUrl", this.returnUrl); } // Add ecsPaymentId if (ecsPaymentId != null) { addHeaderField(header, "ecsPaymentId", this.ecsPaymentId); } // Add remoteId if (remoteId != null) { addHeaderField(header, "remoteId", this.remoteId); } //DynamicHeaders if (dynamicHeaders != null) { for (String key : dynamicHeaders.keySet()) { String value = dynamicHeaders.get(key); if (value != null) { addHeaderField(header, key, value); } } } // Timestamp TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date()); addHeaderField(header, "timestamp", nowAsISO); // Mode addHeaderField(header, "mode", this.mode); // Add requestId String requestId = UUID.randomUUID().toString(); addHeaderField(header, "requestId", requestId); // Authentication token String tokenString = requestId + nowAsISO; addHeaderField(header, "authToken", sign(tokenString, shopKey)); } catch (SOAPException e) { logger.error("Error sending header", e); } } return outboundProperty; }
From source file:be.agiv.security.handler.WSSecurityHandler.java
public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (true == outboundProperty.booleanValue()) { try {// w w w . j av a2s . co m handleOutboundMessage(context); } catch (Exception e) { LOG.error("outbound exception: " + e.getMessage(), e); throw new ProtocolException(e); } } else { try { handleInboundMessage(context); } catch (Exception e) { throw new ProtocolException(e); } } return true; }
From source file:be.fedict.hsm.ws.impl.WSSecuritySOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { LOG.debug("handleMessage"); Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty.booleanValue()) { try {/*from w w w .java 2 s . co m*/ handleInboundMessage(context); } catch (Exception e) { throw new ProtocolException(e); } } return true; }
From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java
@Override public boolean handleMessage(final SOAPMessageContext context) { // Nur fuer den Eingang final Boolean isOutBound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (isOutBound) { return true; }/*from w ww .j a v a2 s.c o m*/ // Servlet-Context speichern final ServletContext servletContext = (ServletContext) context.get(MessageContext.SERVLET_CONTEXT); SOAPBody soapBody = getSoapBody(context); try { // Pruefe SOAP-Body if (soapBody == null) { try { // Erstelle neue SOAP-Message mit SOAP-Body final SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); soapBody = soapMessage.getSOAPBody(); context.setMessage(soapMessage); } catch (final SOAPException e) { LOG.error("Exception beim Erstellen einer SOAP-Message.", e); } // Request ungueltig - z.B. ungueltiges XML throw new InvalidExtraRequestException(resourceBundle.getString(Messages.ERROR_REQUEST_NO_EXTRA)); } // Hole Transport-Element final Node transportNode = getTransportElement(soapBody); if (transportNode == null) { // kein 'Transport'-Element, Request ungueltig throw new InvalidExtraRequestException(resourceBundle.getString(Messages.ERROR_REQUEST_NO_EXTRA)); } // Validiere Request-XML gegen eXTra-Schema validateExtraRequest(transportNode, servletContext); } catch (final InvalidExtraRequestException e) { return handleException(soapBody, e.getMessage(), ExtraErrorReasonType.INVALID_REQUEST); } catch (final Exception e) { LOG.error("Unbekannter Fehler beim Request-Validierung.", e); return handleException(soapBody, resourceBundle.getString(Messages.ERROR_REQUEST_VALIDATION_UNKNOWN), ExtraErrorReasonType.UNSPECIFIED); } return true; }