use of javax.xml.soap.SOAPException in project tomee by apache.
the class Inflate method handleMessage.
public boolean handleMessage(SOAPMessageContext mc) {
try {
final SOAPMessage message = mc.getMessage();
final SOAPBody body = message.getSOAPBody();
final String localName = body.getFirstChild().getLocalName();
if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
final Node responseNode = body.getFirstChild();
final Node returnNode = responseNode.getFirstChild();
final Node intNode = returnNode.getFirstChild();
final int value = new Integer(intNode.getNodeValue());
intNode.setNodeValue(Integer.toString(value * 1000));
}
return true;
} catch (SOAPException e) {
return false;
}
}
use of javax.xml.soap.SOAPException in project tomee by apache.
the class Increment method handleMessage.
public boolean handleMessage(SOAPMessageContext mc) {
try {
final SOAPMessage message = mc.getMessage();
final SOAPBody body = message.getSOAPBody();
final String localName = body.getFirstChild().getLocalName();
if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
final Node responseNode = body.getFirstChild();
final Node returnNode = responseNode.getFirstChild();
final Node intNode = returnNode.getFirstChild();
final int value = new Integer(intNode.getNodeValue());
intNode.setNodeValue(Integer.toString(value + 1));
}
return true;
} catch (SOAPException e) {
return false;
}
}
use of javax.xml.soap.SOAPException in project tomee by apache.
the class SaajMetaFactoryImpl method callFactoryMethod.
private Object callFactoryMethod(String methodName, String arg) throws SOAPException {
SAAJMetaFactory factory = (SAAJMetaFactory) SaajFactoryFinder.find("javax.xml.soap.MetaFactory");
try {
Method method = factory.getClass().getDeclaredMethod(methodName, new Class[] { String.class });
boolean accessibility = method.isAccessible();
try {
method.setAccessible(true);
Object result = method.invoke(factory, new Object[] { arg });
return result;
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof SOAPException) {
throw (SOAPException) e.getTargetException();
} else {
throw new SOAPException("Error calling factory method: " + methodName, e);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new SOAPException("Error calling factory method: " + methodName, e);
} finally {
method.setAccessible(accessibility);
}
} catch (NoSuchMethodException e) {
throw new SOAPException("Factory method not found: " + methodName, e);
}
}
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;
}
Aggregations