use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project camel by apache.
the class CXFMessageDataFormatFeature method setupEndpoint.
protected void setupEndpoint(Endpoint ep) {
resetPartTypes(ep.getBinding());
Class<?> fmt = Source.class;
if (ep.getBinding() instanceof SoapBinding) {
ep.getInInterceptors().add(new SAAJInInterceptor());
SAAJOutInterceptor out = new SAAJOutInterceptor();
ep.getOutInterceptors().add(out);
ep.getOutInterceptors().add(new CxfMessageSoapHeaderOutInterceptor());
ep.getOutInterceptors().add(new MessageModeOutInterceptor(out, ep.getBinding().getBindingInfo().getName()));
fmt = SOAPMessage.class;
} else {
ep.getOutInterceptors().add(new MessageModeOutInterceptor(Source.class, ep.getBinding().getBindingInfo().getName()));
}
ep.getInInterceptors().add(new MessageModeInInterceptor(fmt, ep.getBinding().getBindingInfo().getName()));
ep.put(AbstractInDatabindingInterceptor.NO_VALIDATE_PARTS, Boolean.TRUE);
// need to remove the wrapper class and holder interceptor
removeInterceptors(ep.getInInterceptors(), REMOVING_IN_INTERCEPTORS);
removeInterceptors(ep.getOutInterceptors(), REMOVING_OUT_INTERCEPTORS);
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor 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 org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project tomee by apache.
the class ConfigureCxfSecurity method setupWSS4JChain.
public static final void setupWSS4JChain(InterceptorProvider endpoint, Map<String, Object> inProps, Map<String, Object> outProps) {
if (null != inProps && !inProps.isEmpty()) {
endpoint.getInInterceptors().add(new SAAJInInterceptor());
endpoint.getInInterceptors().add(new WSS4JInInterceptor(inProps));
// if WS Security is used with a JAX-WS handler (See EjbInterceptor), we have to deal with mustUnderstand flag
// in WS Security headers. So, let's add an interceptor
endpoint.getInInterceptors().add(new WSSPassThroughInterceptor());
}
if (null != outProps && !outProps.isEmpty()) {
endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
endpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
}
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project tomee by apache.
the class EjbEndpoint method init.
protected void init() {
// configure handlers
try {
initHandlers();
} catch (Exception e) {
throw new WebServiceException("Error configuring handlers", e);
}
// Set service to invoke the target ejb
service.setInvoker(new EjbMethodInvoker(this.bus, beanContext));
// Remove interceptors that perform handler processing since
// handler processing must happen within the EJB container.
Endpoint endpoint = getEndpoint();
removeHandlerInterceptors(bus.getInInterceptors());
removeHandlerInterceptors(endpoint.getInInterceptors());
removeHandlerInterceptors(endpoint.getBinding().getInInterceptors());
removeHandlerInterceptors(endpoint.getService().getInInterceptors());
// Install SAAJ interceptor
if (endpoint.getBinding() instanceof SoapBinding && !this.implInfo.isWebServiceProvider()) {
endpoint.getService().getInInterceptors().add(new SAAJInInterceptor());
}
// Install WSS4J interceptor
ConfigureCxfSecurity.configure(endpoint, port);
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.
the class SpringBeansTest method testClients.
@Test
public void testClients() throws Exception {
AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
ClientHolderBean greeters = (ClientHolderBean) ctx.getBean("greeters");
assertEquals(4, greeters.greeterCount());
Object bean = ctx.getBean("client1.proxyFactory");
assertNotNull(bean);
Greeter greeter = (Greeter) ctx.getBean("client1");
Greeter greeter2 = (Greeter) ctx.getBean("client1");
assertNotNull(greeter);
assertNotNull(greeter2);
assertSame(greeter, greeter2);
Client client = ClientProxy.getClient(greeter);
assertNotNull("expected ConduitSelector", client.getConduitSelector());
assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
boolean saaj = false;
boolean logging = false;
for (Interceptor<? extends Message> i : inInterceptors) {
if (i instanceof SAAJInInterceptor) {
saaj = true;
} else if (i instanceof LoggingInInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
saaj = false;
logging = false;
for (Interceptor<?> i : client.getOutInterceptors()) {
if (i instanceof SAAJOutInterceptor) {
saaj = true;
} else if (i instanceof LoggingOutInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
assertTrue(client.getEndpoint().getService().getDataBinding() instanceof SourceDataBinding);
JaxWsProxyFactoryBean factory = (JaxWsProxyFactoryBean) ctx.getBean("wsdlLocation.proxyFactory");
assertNotNull(factory);
String wsdlLocation = factory.getWsdlLocation();
assertEquals("We should get the right wsdl location", wsdlLocation, "wsdl/hello_world.wsdl");
factory = (JaxWsProxyFactoryBean) ctx.getBean("inlineSoapBinding.proxyFactory");
assertNotNull(factory);
BindingConfiguration bc = factory.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
assertTrue(sbc.getVersion() instanceof Soap12);
assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
Greeter g1 = greeters.getGreet1();
Greeter g2 = greeters.getGreet2();
assertNotSame(g1, g2);
ctx.close();
}
Aggregations