use of javax.xml.soap.SOAPException in project cxf by apache.
the class CryptoCoverageChecker method handleMessage.
/**
* Checks that the WSS4J results refer to the required signed/encrypted
* elements as defined by the XPath expressions in {@link #xPaths}.
*
* @param message
* the SOAP message containing the signature
*
* @throws SoapFault
* if there is an error evaluating an XPath or an element is not
* covered by the required cryptographic operation
*/
public void handleMessage(SoapMessage message) throws Fault {
if (this.xPaths == null || this.xPaths.isEmpty()) {
// return
}
if (message.getContent(SOAPMessage.class) == null) {
throw new SoapFault("Error obtaining SOAP document", Fault.FAULT_CODE_CLIENT);
}
Element documentElement = null;
try {
SOAPMessage saajDoc = message.getContent(SOAPMessage.class);
SOAPEnvelope envelope = saajDoc.getSOAPPart().getEnvelope();
if (!checkFaults && envelope.getBody().hasFault()) {
return;
}
documentElement = envelope;
documentElement = (Element) DOMUtils.getDomElement(documentElement);
} catch (SOAPException e) {
throw new SoapFault("Error obtaining SOAP document", Fault.FAULT_CODE_CLIENT);
}
final Collection<WSDataRef> signed = new HashSet<>();
final Collection<WSDataRef> encrypted = new HashSet<>();
List<WSHandlerResult> results = CastUtils.cast((List<?>) message.get(WSHandlerConstants.RECV_RESULTS));
// Get all encrypted and signed references
if (results != null) {
for (WSHandlerResult wshr : results) {
List<WSSecurityEngineResult> signedResults = wshr.getActionResults().get(WSConstants.SIGN);
if (signedResults != null) {
for (WSSecurityEngineResult signedResult : signedResults) {
List<WSDataRef> sl = CastUtils.cast((List<?>) signedResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS));
if (sl != null) {
if (sl.size() == 1 && sl.get(0).getName().equals(new QName(WSS4JConstants.SIG_NS, WSS4JConstants.SIG_LN))) {
// endorsing the signature so don't include
continue;
}
signed.addAll(sl);
}
}
}
List<WSSecurityEngineResult> encryptedResults = wshr.getActionResults().get(WSConstants.ENCR);
if (encryptedResults != null) {
for (WSSecurityEngineResult encryptedResult : encryptedResults) {
List<WSDataRef> el = CastUtils.cast((List<?>) encryptedResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS));
if (el != null) {
encrypted.addAll(el);
}
}
}
}
}
CryptoCoverageUtil.reconcileEncryptedSignedRefs(signed, encrypted);
// XPathFactory and XPath are not thread-safe so we must recreate them
// each request.
final XPathFactory factory = XPathFactory.newInstance();
final XPath xpath = factory.newXPath();
if (this.prefixMap != null) {
xpath.setNamespaceContext(new MapNamespaceContext(this.prefixMap));
}
for (XPathExpression xPathExpression : this.xPaths) {
Collection<WSDataRef> refsToCheck = null;
switch(xPathExpression.getType()) {
case SIGNED:
refsToCheck = signed;
break;
case ENCRYPTED:
refsToCheck = encrypted;
break;
default:
throw new IllegalStateException("Unexpected crypto type: " + xPathExpression.getType());
}
try {
CryptoCoverageUtil.checkCoverage(documentElement, refsToCheck, xpath, Arrays.asList(xPathExpression.getXPath()), xPathExpression.getType(), xPathExpression.getScope());
} catch (WSSecurityException e) {
throw new SoapFault("No " + xPathExpression.getType() + " element found matching XPath " + xPathExpression.getXPath(), Fault.FAULT_CODE_CLIENT);
}
}
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class HandlerTestImpl method createSOAPFaultException.
private SOAPFaultException createSOAPFaultException(String faultString) {
try {
SOAPFault fault = SOAPFactory.newInstance().createFault();
fault.setFaultString(faultString);
SAAJUtils.setFaultCode(fault, new QName("http://cxf.apache.org/faultcode", "Server"));
return new SOAPFaultException(fault);
} catch (SOAPException e) {
// do nothing
}
return null;
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class DocLitBareCodeFirstServiceImpl method greetMe.
public GreetMeResponse greetMe(GreetMeRequest gmr) {
if ("fault".equals(gmr.getName())) {
try {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault fault = factory.createFault("this is a fault string!", new QName("http://foo", "FooCode"));
fault.setFaultActor("mr.actor");
fault.addDetail().addChildElement("test").addTextNode("TestText");
throw new SOAPFaultException(fault);
} catch (SOAPException ex) {
throw new WebServiceException(ex);
}
} else if ("emptyfault".equals(gmr.getName())) {
throw new RuntimeException("Empty!");
}
GreetMeResponse resp = new GreetMeResponse();
resp.setName(gmr.getName());
return resp;
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class AbstractModifyRequestInterceptor method handleMessage.
public void handleMessage(SoapMessage mc) throws Fault {
SOAPMessage saaj = mc.getContent(SOAPMessage.class);
try {
Iterator<?> secHeadersIterator = SAAJUtils.getHeader(saaj).getChildElements(SEC_HEADER);
if (secHeadersIterator.hasNext()) {
SOAPHeaderElement securityHeader = (SOAPHeaderElement) secHeadersIterator.next();
modifySecurityHeader(securityHeader);
}
modifySOAPBody(SAAJUtils.getBody(saaj));
} catch (SOAPException ex) {
throw new Fault(ex);
}
}
use of javax.xml.soap.SOAPException in project Payara by payara.
the class BaseAuthConfig method getName.
private static Name getName(SOAPMessage message) {
Name rvalue = null;
SOAPPart soap = message.getSOAPPart();
if (soap != null) {
try {
SOAPEnvelope envelope = soap.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof SOAPElement) {
rvalue = ((SOAPElement) o).getElementName();
break;
}
}
}
}
} catch (SOAPException se) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
}
}
}
return rvalue;
}
Aggregations