Search in sources :

Example 16 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project ddf by codice.

the class PaosInInterceptorTest method handleMessagePaosResponseBasicBad.

@Test(expected = Fault.class)
public void handleMessagePaosResponseBasicBad() throws IOException {
    Message message = new MessageImpl();
    message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest.xml").openStream());
    message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
    Message outMessage = new MessageImpl();
    HashMap<String, List> protocolHeaders = new HashMap<>();
    outMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
    outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
    protocolHeaders.put("Authorization", Collections.singletonList("BASIC dGVzdDp0ZXN0"));
    ExchangeImpl exchange = new ExchangeImpl();
    exchange.setOutMessage(outMessage);
    message.setExchange(exchange);
    PaosInInterceptor paosInInterceptor = new PaosInInterceptor(Phase.RECEIVE) {

        HttpResponseWrapper getHttpResponse(String responseConsumerURL, String soapResponse, Message message) throws IOException {
            HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper();
            if (responseConsumerURL.equals("https://sp.example.org/PAOSConsumer")) {
                httpResponseWrapper.statusCode = 400;
                httpResponseWrapper.content = new ByteArrayInputStream("actual content".getBytes());
            } else if (responseConsumerURL.equals("https://idp.example.org/saml2/sso")) {
                httpResponseWrapper.statusCode = 200;
                httpResponseWrapper.content = PaosInInterceptorTest.class.getClassLoader().getResource("idpresponse.xml").openStream();
            }
            return httpResponseWrapper;
        }
    };
    paosInInterceptor.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 17 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project ddf by codice.

the class PaosInInterceptorTest method handleMessagePaosResponseBasicBadAcsUrl.

@Test
public void handleMessagePaosResponseBasicBadAcsUrl() throws IOException {
    Message message = new MessageImpl();
    message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest.xml").openStream());
    message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
    Message outMessage = new MessageImpl();
    HashMap<String, List> protocolHeaders = new HashMap<>();
    outMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
    outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
    protocolHeaders.put("Authorization", Collections.singletonList("BASIC dGVzdDp0ZXN0"));
    ExchangeImpl exchange = new ExchangeImpl();
    exchange.setOutMessage(outMessage);
    message.setExchange(exchange);
    PaosInInterceptor paosInInterceptor = new PaosInInterceptor(Phase.RECEIVE) {

        HttpResponseWrapper getHttpResponse(String responseConsumerURL, String soapResponse, Message message) throws IOException {
            HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper();
            if (responseConsumerURL.equals("https://sp.example.org/PAOSConsumer")) {
                httpResponseWrapper.statusCode = 200;
                httpResponseWrapper.content = new ByteArrayInputStream("error content".getBytes());
            } else if (responseConsumerURL.equals("https://idp.example.org/saml2/sso")) {
                httpResponseWrapper.statusCode = 200;
                httpResponseWrapper.content = new ByteArrayInputStream(IOUtils.toString(PaosInInterceptorTest.class.getClassLoader().getResource("idpresponse.xml").openStream()).replace("https://sp.example.org/PAOSConsumer", "badurl").getBytes());
            }
            return httpResponseWrapper;
        }
    };
    paosInInterceptor.handleMessage(message);
    assertThat(IOUtils.toString(message.getContent(InputStream.class)), is("error content"));
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 18 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project ddf by codice.

the class PaosOutInterceptorTest method testHandleMessageAccept.

@Test
public void testHandleMessageAccept() {
    Message message = new MessageImpl();
    HashMap<String, List<String>> headers = new HashMap<>();
    headers.put(HttpHeaders.ACCEPT, new ArrayList<>());
    message.put(Message.PROTOCOL_HEADERS, headers);
    PaosOutInterceptor paosOutInterceptor = new PaosOutInterceptor(Phase.POST_LOGICAL);
    paosOutInterceptor.handleMessage(message);
    assertThat(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get(HttpHeaders.ACCEPT), contains("application/vnd.paos+xml", "*/*"));
    assertTrue(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get("PAOS").contains("ver=\"urn:liberty:paos:2003-08\""));
    assertTrue(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get("PAOS").contains("\"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp\",\"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp:2.0:WantAuthnRequestsSigned\""));
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) MessageImpl(org.apache.cxf.message.MessageImpl) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 19 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project ddf by codice.

the class PaosInInterceptorTest method handleMessagePaosResponseBasicNoIdp.

@Test(expected = Fault.class)
public void handleMessagePaosResponseBasicNoIdp() throws IOException {
    Message message = new MessageImpl();
    message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest_noidp.xml").openStream());
    message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
    Message outMessage = new MessageImpl();
    HashMap<String, List> protocolHeaders = new HashMap<>();
    outMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
    outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
    protocolHeaders.put("Authorization", Collections.singletonList("BASIC dGVzdDp0ZXN0"));
    ExchangeImpl exchange = new ExchangeImpl();
    exchange.setOutMessage(outMessage);
    message.setExchange(exchange);
    PaosInInterceptor paosInInterceptor = new PaosInInterceptor(Phase.RECEIVE);
    paosInInterceptor.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 20 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project ddf by codice.

the class PolicyWSDLGetInterceptor method handleMessage.

// Majority of this method is from the WSDLGetInterceptor, in-line comments
// specify which areas were added
@Override
public void handleMessage(Message message) throws Fault {
    String method = (String) message.get(Message.HTTP_REQUEST_METHOD);
    String query = (String) message.get(Message.QUERY_STRING);
    if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
        return;
    }
    String baseUri = (String) message.get(Message.REQUEST_URL);
    String ctx = (String) message.get(Message.PATH_INFO);
    Map<String, String> map = UrlUtils.parseQueryString(query);
    if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
        Document doc = getDocument(message, baseUri, map, ctx);
        // DDF- start ADDED code
        if (map.containsKey("wsdl")) {
            doc = addPolicyToWSDL(doc, loader.getPolicy());
            doc = configureAddress(doc);
        }
        // DDF- end of ADDED code
        Endpoint e = message.getExchange().get(Endpoint.class);
        Message mout = new MessageImpl();
        mout.setExchange(message.getExchange());
        mout = e.getBinding().createMessage(mout);
        mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
        message.getExchange().setOutMessage(mout);
        mout.put(WSDLGetInterceptor.DOCUMENT_HOLDER, doc);
        mout.put(Message.CONTENT_TYPE, "text/xml");
        // just remove the interceptor which should not be used
        cleanUpOutInterceptors(mout);
        // notice this is being added after the purge above, don't swap the order!
        mout.getInterceptorChain().add(WSDLGetOutInterceptor.INSTANCE);
        // DDF- CHANGED TRANSFORM_SKIP to transform.skip because private field 
        message.getExchange().put("transform.skip", Boolean.TRUE);
        // skip the service executor and goto the end of the chain.
        message.getInterceptorChain().doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName());
    }
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor) Document(org.w3c.dom.Document) MessageImpl(org.apache.cxf.message.MessageImpl)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)20 Message (org.apache.cxf.message.Message)16 Test (org.junit.Test)15 HashMap (java.util.HashMap)9 List (java.util.List)7 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)7 IOException (java.io.IOException)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 Document (org.w3c.dom.Document)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)3 Map (java.util.Map)2 WebServiceException (javax.xml.ws.WebServiceException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 OutgoingChainInterceptor (org.apache.cxf.interceptor.OutgoingChainInterceptor)2 Exchange (org.apache.cxf.message.Exchange)2