use of javax.xml.soap.SOAPException in project wildfly by wildfly.
the class PojoEndpoint method helloError.
public String helloError(String input) {
try {
SOAPFault fault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createFault(input, SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
fault.setFaultActor("mr.actor");
fault.addDetail().addChildElement("test");
fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "OperatorNotFound"));
throw new SOAPFaultException(fault);
} catch (SOAPException ex) {
ex.printStackTrace();
}
return "Failure!";
}
use of javax.xml.soap.SOAPException in project ddf by codice.
the class AssertionConsumerService method processSoapResponse.
@POST
@Consumes({ "text/xml", "application/soap+xml" })
public Response processSoapResponse(InputStream body, @Context HttpServletRequest request) {
try {
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(IOUtils.toString(body));
String relayState = getRelayState(soapMessage);
org.opensaml.saml.saml2.core.Response samlpResponse = getSamlpResponse(soapMessage);
boolean validateResponse = validateResponse(samlpResponse);
if (validateResponse) {
return processSamlResponse(samlpResponse, relayState);
}
} catch (XMLStreamException e) {
LOGGER.debug("Unable to parse SOAP message from response.", e);
} catch (IOException e) {
LOGGER.debug("Unable to get SAMLP response.", e);
} catch (SOAPException e) {
LOGGER.debug("Unable to get relay state from response.", e);
}
return Response.serverError().entity("Invalid AuthN response.").build();
}
use of javax.xml.soap.SOAPException in project ddf by codice.
the class IdpEndpoint method determineAuthMethod.
private AuthObj determineAuthMethod(String bodyStr, AuthnRequest authnRequest) {
XMLStreamReader xmlStreamReader = null;
try {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(bodyStr));
} catch (XMLStreamException e) {
LOGGER.debug("Unable to parse SOAP message from client.", e);
}
SoapMessage soapMessage = new SoapMessage(Soap11.getInstance());
SAAJInInterceptor.SAAJPreInInterceptor preInInterceptor = new SAAJInInterceptor.SAAJPreInInterceptor();
soapMessage.setContent(XMLStreamReader.class, xmlStreamReader);
preInInterceptor.handleMessage(soapMessage);
SAAJInInterceptor inInterceptor = new SAAJInInterceptor();
inInterceptor.handleMessage(soapMessage);
SOAPPart soapMessageContent = (SOAPPart) soapMessage.getContent(Node.class);
AuthObj authObj = new AuthObj();
try {
Iterator soapHeaderElements = soapMessageContent.getEnvelope().getHeader().examineAllHeaderElements();
while (soapHeaderElements.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) soapHeaderElements.next();
if (soapHeaderElement.getLocalName().equals("Security")) {
Iterator childElements = soapHeaderElement.getChildElements();
while (childElements.hasNext()) {
Object nextElement = childElements.next();
if (nextElement instanceof SOAPElement) {
SOAPElement element = (SOAPElement) nextElement;
if (element.getLocalName().equals("UsernameToken")) {
Iterator usernameTokenElements = element.getChildElements();
Object next;
while (usernameTokenElements.hasNext()) {
if ((next = usernameTokenElements.next()) instanceof Element) {
Element nextEl = (Element) next;
if (nextEl.getLocalName().equals("Username")) {
authObj.username = nextEl.getTextContent();
} else if (nextEl.getLocalName().equals("Password")) {
authObj.password = nextEl.getTextContent();
}
}
}
if (authObj.username != null && authObj.password != null) {
authObj.method = USER_PASS;
break;
}
} else if (element.getLocalName().equals("Assertion") && element.getNamespaceURI().equals("urn:oasis:names:tc:SAML:2.0:assertion")) {
authObj.assertion = new SecurityToken(element.getAttribute("ID"), element, null, null);
authObj.method = SAML;
break;
}
}
}
}
}
} catch (SOAPException e) {
LOGGER.debug("Unable to parse SOAP message.", e);
}
RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
boolean requestingPki = false;
boolean requestingUp = false;
if (requestedAuthnContext != null) {
List<AuthnContextClassRef> authnContextClassRefs = requestedAuthnContext.getAuthnContextClassRefs();
for (AuthnContextClassRef authnContextClassRef : authnContextClassRefs) {
String authnContextClassRefStr = authnContextClassRef.getAuthnContextClassRef();
if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SPKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_TLS_CLIENT.equals(authnContextClassRefStr)) {
requestingPki = true;
} else if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT.equals(authnContextClassRefStr)) {
requestingUp = true;
}
}
} else {
//The requested auth context isn't required so we don't know what they want... just set both to true
requestingPki = true;
requestingUp = true;
}
if (requestingUp && authObj.method != null && authObj.method.equals(USER_PASS)) {
LOGGER.trace("Found UsernameToken and correct AuthnContextClassRef");
return authObj;
} else if (requestingPki && authObj.method == null) {
LOGGER.trace("Found no token, but client requested PKI AuthnContextClassRef");
authObj.method = PKI;
return authObj;
} else if (authObj.method == null) {
LOGGER.debug("No authentication tokens found for the current request and the client did not request PKI authentication");
}
return authObj;
}
use of javax.xml.soap.SOAPException in project ddf by codice.
the class SoapRequestDecoder method decodeRelayState.
public String decodeRelayState(String samlRequest) {
String relayState = null;
try {
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(samlRequest);
SOAPEnvelope envelope = soapMessage.getEnvelope();
SOAPHeader header = envelope.getHeader();
Iterator iterator = header.examineAllHeaderElements();
while (iterator.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) iterator.next();
if ("RelayState".equals(soapHeaderElement.getLocalName())) {
relayState = soapHeaderElement.getValue();
break;
}
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("Unable to convert parse SOAP request.");
} catch (SOAPException e) {
throw new IllegalArgumentException("Unable to get SOAP envelope.");
}
return relayState;
}
use of javax.xml.soap.SOAPException in project ddf by codice.
the class GuestInterceptor method createAddressing.
private void createAddressing(SoapMessage message, SOAPMessage soapMessage) {
SOAPFactory soapFactory;
try {
soapFactory = SOAPFactory.newInstance();
} catch (SOAPException e) {
LOGGER.debug("Could not create a SOAPFactory.", e);
// can't add anything if we can't create it
return;
}
String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
AddressingProperties addressingProperties = new AddressingProperties();
try {
SOAPElement action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
AttributedURIType attributedString = new AttributedURIType();
String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION), "");
attributedString.setValue(actionValue);
addressingProperties.setAction(attributedString);
soapMessage.getSOAPHeader().addChildElement(action);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing action.", e);
}
try {
SOAPElement messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
String uuid = "urn:uuid:" + UUID.randomUUID().toString();
messageId.addTextNode(uuid);
AttributedURIType attributedString = new AttributedURIType();
attributedString.setValue(uuid);
addressingProperties.setMessageID(attributedString);
soapMessage.getSOAPHeader().addChildElement(messageId);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing messageId.", e);
}
try {
SOAPElement to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
AttributedURIType attributedString = new AttributedURIType();
attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
endpointReferenceType.setAddress(attributedString);
addressingProperties.setTo(endpointReferenceType);
soapMessage.getSOAPHeader().addChildElement(to);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing to.", e);
}
try {
SOAPElement replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
replyTo.addChildElement(address);
soapMessage.getSOAPHeader().addChildElement(replyTo);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing replyTo.", e);
}
message.put(addressingProperty, addressingProperties);
}
Aggregations