Java Code Examples for javax.xml.soap.SOAPHeader#getElementsByTagNameNS()

The following examples show how to use javax.xml.soap.SOAPHeader#getElementsByTagNameNS() . 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: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!(Boolean)result.get("validated-token")) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example 2
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!(Boolean)result.get("validated-token")) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example 3
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!((Boolean)result.get("validated-token"))) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example 4
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!((Boolean)result.get("validated-token")).booleanValue()) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example 5
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!(Boolean) result.get("validated-token")) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example 6
Source File: SOAPSyncHelper.java    From Java-OCA-OCPP with MIT License 5 votes vote down vote up
public static String getHeaderValue(SOAPMessage message, String tagName) {
  String value = null;
  try {
    SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
    NodeList elements = header.getElementsByTagNameNS("*", tagName);
    if (elements.getLength() > 0) {
      value = elements.item(0).getChildNodes().item(0).getTextContent();
    }
  } catch (SOAPException e) {
    logger.warn("getHeaderValue() failed", e);
  }
  return value;
}
 
Example 7
Source File: WssHelper.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * Finds the Security element from the header. If not found then creates one
 * and returns the same
 *
 * @param header
 * @return
 */
public static Node getSecurityElement(SOAPHeader header) {
    NodeList targetElement = header.getElementsByTagNameNS(Constants.WSS_NS,
        Constants.SECURITY_ELEMENT_NAME);
    if (targetElement == null || targetElement.getLength() == 0) {
        JAXBElement<SecurityHeaderType> value = wsseObjFactory
            .createSecurity(wsseObjFactory.createSecurityHeaderType());
        Node headerNode = marshallJaxbElement(value).getDocumentElement();
        return header.appendChild(header.getOwnerDocument().importNode(
            headerNode, true));
    } else if (targetElement.getLength() > 1) {
        throw new RuntimeException(Constants.ERR_INSERTING_SECURITY_HEADER);
    }
    return targetElement.item(0);
}
 
Example 8
Source File: SoapHelper.java    From arctic-sea with Apache License 2.0 3 votes vote down vote up
/**
 * Get text content from element by namespace.
 *
 * @param soapHeader
 *            SOAPHeader element
 * @param namespaceURI
 *            Namespace URI
 * @param localName
 *            local name
 * @return Text content.
 */
public static String getContentFromElement(SOAPHeader soapHeader, String namespaceURI, String localName) {
    String elementContent = null;
    NodeList nodes = soapHeader.getElementsByTagNameNS(namespaceURI, localName);
    for (int i = 0; i < nodes.getLength(); i++) {
        elementContent = nodes.item(i).getTextContent();
    }
    return elementContent;
}