Search in sources :

Example 31 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project jbossws-cxf by jbossws.

the class LogHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    log.info("handleInbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("LogHandlerInbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|LogIn");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 32 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project jbossws-cxf by jbossws.

the class LogHandler method handleOutbound.

@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
    log.info("handleOutbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("LogHandlerOutbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|LogOut");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 33 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project jbossws-cxf by jbossws.

the class RoutingHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    log.info("handleInbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("RoutingHandlerInbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|RoutIn");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 34 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project jbossws-cxf by jbossws.

the class AuthorizationHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    log.info("handleInbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("AuthorizationHandlerInbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|AuthIn");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 35 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project keycloak by keycloak.

the class SAMLServletAdapterTest method testInvalidCredentialsEcpFlow.

@Test
public void testInvalidCredentialsEcpFlow() throws Exception {
    Response authnRequestResponse = AdminClientUtil.createResteasyClient().target(ecpSPPage.toString()).request().header("Accept", "text/html; application/vnd.paos+xml").header("PAOS", "ver='urn:liberty:paos:2003-08' ;'urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp'").get();
    SOAPMessage authnRequestMessage = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(authnRequestResponse.readEntity(byte[].class)));
    Iterator<javax.xml.soap.Node> it = authnRequestMessage.getSOAPHeader().<SOAPHeaderElement>getChildElements(new QName("urn:liberty:paos:2003-08", "Request"));
    it.next();
    it = authnRequestMessage.getSOAPHeader().<SOAPHeaderElement>getChildElements(new QName("urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp", "Request"));
    javax.xml.soap.Node ecpRequestHeader = it.next();
    NodeList idpList = ((SOAPHeaderElement) ecpRequestHeader).getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "IDPList");
    Assert.assertThat("No IDPList returned from Service Provider", idpList.getLength(), is(1));
    NodeList idpEntries = idpList.item(0).getChildNodes();
    Assert.assertThat("No IDPEntry returned from Service Provider", idpEntries.getLength(), is(1));
    String singleSignOnService = null;
    for (int i = 0; i < idpEntries.getLength(); i++) {
        Node item = idpEntries.item(i);
        NamedNodeMap attributes = item.getAttributes();
        Node location = attributes.getNamedItem("Loc");
        singleSignOnService = location.getNodeValue();
    }
    Assert.assertThat("Could not obtain SSO Service URL", singleSignOnService, notNullValue());
    Document authenticationRequest = authnRequestMessage.getSOAPBody().getFirstChild().getOwnerDocument();
    String username = "pedroigor";
    String password = "baspassword";
    String pair = username + ":" + password;
    String authHeader = "Basic " + Base64.encodeBytes(pair.getBytes());
    Response authenticationResponse = AdminClientUtil.createResteasyClient().target(singleSignOnService).request().header(HttpHeaders.AUTHORIZATION, authHeader).post(Entity.entity(DocumentUtil.asString(authenticationRequest), "application/soap+xml"));
    Assert.assertThat(authenticationResponse.getStatus(), is(OK.getStatusCode()));
    SOAPMessage responseMessage = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(authenticationResponse.readEntity(byte[].class)));
    Node samlResponse = responseMessage.getSOAPBody().getFirstChild();
    Assert.assertThat(samlResponse, notNullValue());
    StatusResponseType responseType = (StatusResponseType) SAMLParser.getInstance().parse(samlResponse);
    StatusCodeType statusCode = responseType.getStatus().getStatusCode();
    Assert.assertThat(statusCode.getStatusCode().getValue().toString(), is(not(JBossSAMLURIConstants.STATUS_SUCCESS.get())));
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) StatusCodeType(org.keycloak.dom.saml.v2.protocol.StatusCodeType) AbstractSamlTest(org.keycloak.testsuite.saml.AbstractSamlTest) Test(org.junit.Test)

Aggregations

SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)36 SOAPMessage (javax.xml.soap.SOAPMessage)24 SOAPHeader (javax.xml.soap.SOAPHeader)21 SOAPException (javax.xml.soap.SOAPException)17 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)14 Name (javax.xml.soap.Name)10 SOAPElement (javax.xml.soap.SOAPElement)10 SOAPBody (javax.xml.soap.SOAPBody)9 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)7 WebServiceException (javax.xml.ws.WebServiceException)7 QName (javax.xml.namespace.QName)6 SOAPFactory (javax.xml.soap.SOAPFactory)6 ProtocolException (javax.xml.ws.ProtocolException)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 Iterator (java.util.Iterator)5 JAXBException (javax.xml.bind.JAXBException)5 SOAPPart (javax.xml.soap.SOAPPart)5 Node (org.w3c.dom.Node)4 IOException (java.io.IOException)3 JAXBContext (javax.xml.bind.JAXBContext)3