org.apache.cxf.headers.Header Java Examples

The following examples show how to use org.apache.cxf.headers.Header. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeaderVerifier.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addPartialResponseHeader(SoapMessage message) {
    try {
        // add piggybacked wsa:From header to partial response
        List<Header> header = message.getHeaders();
        Document doc = DOMUtils.getEmptyDocument();
        SoapVersion ver = message.getVersion();
        Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(),
            ver.getHeader().getLocalPart());
        hdr.setPrefix(ver.getHeader().getPrefix());

        marshallFrom("urn:piggyback_responder", hdr, getMarshaller());
        Element elem = DOMUtils.getFirstElement(hdr);
        while (elem != null) {
            Header holder = new Header(
                    new QName(elem.getNamespaceURI(), elem.getLocalName()),
                    elem, null);
            header.add(holder);

            elem = DOMUtils.getNextElement(elem);
        }

    } catch (Exception e) {
        verificationCache.put("SOAP header addition failed: " + e);
        e.printStackTrace();
    }
}
 
Example #2
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #3
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addUsernameToken(SoapMessage message) {
    UsernameToken tok = assertUsernameTokens(message, null);

    Header h = findSecurityHeader(message, true);
    WSSecUsernameToken utBuilder = 
        addUsernameToken(message, tok);
    if (utBuilder == null) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.USERNAME_TOKEN);
        for (AssertionInfo ai : ais) {
            if (ai.isAsserted()) {
                ai.setAsserted(false);
            }
        }
        return;
    }
    Element el = (Element)h.getObject();
    utBuilder.prepare(el.getOwnerDocument());
    el.appendChild(utBuilder.getUsernameTokenElement());
}
 
Example #4
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addUsernameToken(SoapMessage message) {
    UsernameToken tok = assertUsernameTokens(message, null);

    Header h = findSecurityHeader(message, true);
    WSSecUsernameToken utBuilder = 
        addUsernameToken(message, tok);
    if (utBuilder == null) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.USERNAME_TOKEN);
        for (AssertionInfo ai : ais) {
            if (ai.isAsserted()) {
                ai.setAsserted(false);
            }
        }
        return;
    }
    Element el = (Element)h.getObject();
    utBuilder.prepare(el.getOwnerDocument());
    el.appendChild(utBuilder.getUsernameTokenElement());
}
 
Example #5
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #6
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #7
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addSamlToken(SoapMessage message) {
    WSSConfig.init();
    SamlToken tok = assertSamlTokens(message);

    Header h = findSecurityHeader(message, true);
    try {
        AssertionWrapper wrapper = addSamlToken(tok, message);
        if (wrapper == null) {
            AssertionInfoMap aim = message.get(AssertionInfoMap.class);
            Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.SAML_TOKEN);
            for (AssertionInfo ai : ais) {
                if (ai.isAsserted()) {
                    ai.setAsserted(false);
                }
            }
            return;
        }
        Element el = (Element)h.getObject();
        el.appendChild(wrapper.toDOM(el.getOwnerDocument()));
    } catch (WSSecurityException ex) {
        policyNotAsserted(tok, ex.getMessage(), message);
    }
}
 
Example #8
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #9
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addSamlToken(SoapMessage message) {
    WSSConfig.init();
    SamlToken tok = assertSamlTokens(message);

    Header h = findSecurityHeader(message, true);
    try {
        AssertionWrapper wrapper = addSamlToken(tok, message);
        if (wrapper == null) {
            AssertionInfoMap aim = message.get(AssertionInfoMap.class);
            Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.SAML_TOKEN);
            for (AssertionInfo ai : ais) {
                if (ai.isAsserted()) {
                    ai.setAsserted(false);
                }
            }
            return;
        }
        Element el = (Element)h.getObject();
        el.appendChild(wrapper.toDOM(el.getOwnerDocument()));
    } catch (WSSecurityException ex) {
        policyNotAsserted(tok, ex.getMessage(), message);
    }
}
 
Example #10
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addSamlToken(SoapMessage message) {
    WSSConfig.init();
    SamlToken tok = assertSamlTokens(message);

    Header h = findSecurityHeader(message, true);
    try {
        AssertionWrapper wrapper = addSamlToken(tok, message);
        if (wrapper == null) {
            AssertionInfoMap aim = message.get(AssertionInfoMap.class);
            Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.SAML_TOKEN);
            for (AssertionInfo ai : ais) {
                if (ai.isAsserted()) {
                    ai.setAsserted(false);
                }
            }
            return;
        }
        Element el = (Element)h.getObject();
        el.appendChild(wrapper.toDOM(el.getOwnerDocument()));
    } catch (WSSecurityException ex) {
        policyNotAsserted(tok, ex.getMessage(), message);
    }
}
 
Example #11
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #12
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addUsernameToken(SoapMessage message) {
    UsernameToken tok = assertUsernameTokens(message, null);

    Header h = findSecurityHeader(message, true);
    WSSecUsernameToken utBuilder = 
        addUsernameToken(message, tok);
    if (utBuilder == null) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.USERNAME_TOKEN);
        for (AssertionInfo ai : ais) {
            if (ai.isAsserted()) {
                ai.setAsserted(false);
            }
        }
        return;
    }
    Element el = (Element)h.getObject();
    utBuilder.prepare(el.getOwnerDocument());
    el.appendChild(utBuilder.getUsernameTokenElement());
}
 
Example #13
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #14
Source File: RMSoapOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the SequenceFault in protocol-specific header.
 *
 * @param message the SOAP message.
 * @param sf the SequenceFault.
 */
public static void encodeFault(SoapMessage message, SequenceFault sf) {
    LOG.log(Level.FINE, "Encoding SequenceFault in SOAP header");
    try {
        Message inmsg = message.getExchange().getInMessage();
        RMProperties rmps = RMContextUtils.retrieveRMProperties(inmsg, false);
        AddressingProperties maps = RMContextUtils.retrieveMAPs(inmsg, false, false);
        ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(),
            maps.getNamespaceURI());
        Header header = protocol.getCodec().buildHeaderFault(sf);
        List<Header> headers = message.getHeaders();
        headers.add(header);
    } catch (JAXBException je) {
        LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
    }
}
 
Example #15
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addUsernameToken(SoapMessage message) {
    UsernameToken tok = assertUsernameTokens(message, null);

    Header h = findSecurityHeader(message, true);
    WSSecUsernameToken utBuilder = 
        addUsernameToken(message, tok);
    if (utBuilder == null) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.USERNAME_TOKEN);
        for (AssertionInfo ai : ais) {
            if (ai.isAsserted()) {
                ai.setAsserted(false);
            }
        }
        return;
    }
    Element el = (Element)h.getObject();
    utBuilder.prepare(el.getOwnerDocument());
    el.appendChild(utBuilder.getUsernameTokenElement());
}
 
Example #16
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #17
Source File: RMSoapOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the current RM properties in protocol-specific headers.
 *
 * @param message the SOAP message.
 * @param rmps the current RM properties.
 */
public static void encode(SoapMessage message, RMProperties rmps) {
    if (null == rmps) {
        return;
    }
    LOG.log(Level.FINE, "encoding RMPs in SOAP headers");
    try {

        AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
        ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI());
        List<Header> headers = message.getHeaders();
        int startSize = headers.size();
        protocol.getCodec().buildHeaders(rmps, headers);
        if (startSize != headers.size() && MessageUtils.isPartialResponse(message)) {
            // make sure the response is returned as HTTP 200 and not 202
            message.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);
        }
    } catch (JAXBException je) {
        LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
    }
}
 
Example #18
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #19
Source File: AbstractTokenInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if ("Security".equals(n.getLocalPart())
            && (n.getNamespaceURI().equals(WSS4JConstants.WSSE_NS)
                || n.getNamespaceURI().equals(WSS4JConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.getEmptyDocument();
    Element el = doc.createElementNS(WSS4JConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns:wsse", WSS4JConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSS4JConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #20
Source File: UsernameTokenInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void addToken(SoapMessage message) {
    UsernameToken tok = assertTokens(message);

    Header h = findSecurityHeader(message, true);
    Element el = (Element)h.getObject();
    Document doc = el.getOwnerDocument();

    WSSecUsernameToken utBuilder =
        addUsernameToken(message, doc, tok);
    if (utBuilder == null) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        Collection<AssertionInfo> ais =
            PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.USERNAME_TOKEN);
        for (AssertionInfo ai : ais) {
            if (ai.isAsserted()) {
                ai.setAsserted(false);
            }
        }
        return;
    }
    utBuilder.prepare();
    el.appendChild(utBuilder.getUsernameTokenElement());
}
 
Example #21
Source File: NetSuiteClientService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * Set preferences for given port.
 *
 * @param port port which to set preferences for
 * @param nsPreferences general preferences
 * @param nsSearchPreferences search preferences
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setPreferences(PortT port,
        NsPreferences nsPreferences, NsSearchPreferences nsSearchPreferences) throws NetSuiteException {

    Object searchPreferences = createNativeSearchPreferences(nsSearchPreferences);
    Object preferences = createNativePreferences(nsPreferences);
    try {
        Header searchPreferencesHeader = new Header(
                new QName(getPlatformMessageNamespaceUri(), "searchPreferences"),
                searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));

        Header preferencesHeader = new Header(
                new QName(getPlatformMessageNamespaceUri(), "preferences"),
                preferences, new JAXBDataBinding(preferences.getClass()));

        setHeader(port, preferencesHeader);
        setHeader(port, searchPreferencesHeader);

    } catch (JAXBException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
    }
}
 
Example #22
Source File: NetSuiteClientService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * Remove log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void updateLoginHeaders(PortT port) throws NetSuiteException {
    if (!isUseRequestLevelCredentials()) {
        removeHeader(port, new QName(getPlatformMessageNamespaceUri(), "applicationInfo"));
    } else {
        Object passport = createNativePassport(credentials);
        try {
            if (passport != null) {
                Header passportHeader = new Header(
                        new QName(getPlatformMessageNamespaceUri(), "passport"),
                        passport, new JAXBDataBinding(passport.getClass()));
                setHeader(port, passportHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
        }
    }
}
 
Example #23
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFaultHeadersCopy() throws Throwable {
    ExceptionService serviceObject = new ExceptionService();
    Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    prepareInMessage(ex, true);
    Message msg = new MessageImpl();
    SoapMessage outMessage = new SoapMessage(msg);
    ex.setOutMessage(outMessage);

    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);

    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Expected fault");
    } catch (Fault fault) {
        Message outMsg = ex.getOutMessage();
        assertNotNull(outMsg);
        @SuppressWarnings("unchecked")
        List<Header> headers = (List<Header>)outMsg.get(Header.HEADER_LIST);
        assertEquals(1, headers.size());
        assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
    }
}
 
Example #24
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void updateHeader(Exchange exchange, MessageContext ctx) {
    if (ctx.containsKey(Header.HEADER_LIST)
            && ctx.get(Header.HEADER_LIST) instanceof List<?>) {
        List<?> list = (List<?>) ctx.get(Header.HEADER_LIST);
        if (list != null && !list.isEmpty()) {
            SoapMessage sm = (SoapMessage) createResponseMessage(exchange);
            if (sm != null) {
                Iterator<?> iter = list.iterator();
                while (iter.hasNext()) {
                    Header header = (Header) iter.next();
                    if (header.getDirection() != Header.Direction.DIRECTION_IN
                        && !header.getName().getNamespaceURI().
                            equals("http://docs.oasis-open.org/wss/2004/01/"
                                    + "oasis-200401-wss-wssecurity-secext-1.0.xsd")
                               && !header.getName().getNamespaceURI().
                                   equals("http://docs.oasis-open.org/"
                                          + "wss/oasis-wss-wssecurity-secext-1.1.xsd")) {
                        //don't copy over security header, out interceptor chain will take care of it.
                        sm.getHeaders().add(header);
                    }
                }
            }
        }
    }
}
 
Example #25
Source File: SoapChannel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void newToken(String token) {
	if (useSoapHeaderSessions) {
		for (PublicInterface p : getServiceInterfaces().values()) {
			List<Header> headers = new ArrayList<Header>();
			try {
				Token tokenObject = new Token(token);
				Header sessionHeader = new Header(new QName("uri:org.bimserver.shared", "token"), tokenObject, new JAXBDataBinding(Token.class));
				headers.add(sessionHeader);
			} catch (JAXBException e) {
				LOGGER.error("", e);
			}
			((BindingProvider) p).getRequestContext().put(Header.HEADER_LIST, headers);
		}
	}
}
 
Example #26
Source File: HeaderVerifier.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void verify(SoapMessage message, boolean outgoingPartialResponse) {
    try {
        List<String> wsaHeaders = new ArrayList<>();
        List<Header> headers = message.getHeaders();
        if (headers != null) {
            recordWSAHeaders(headers,
                             wsaHeaders,
                             Names.WSA_NAMESPACE_NAME);
            recordWSAHeaders(headers,
                             wsaHeaders,
                             Names200408.WSA_NAMESPACE_NAME);
            recordWSAHeaders(headers,
                             wsaHeaders,
                             MAPTestBase.CUSTOMER_NAME.getNamespaceURI());
        }
        boolean partialResponse = isIncomingPartialResponse(message)
                                  || outgoingPartialResponse;
        verificationCache.put(MAPTestBase.verifyHeaders(wsaHeaders,
                                                    partialResponse,
                                                    isRequestLeg(message),
                                                    false));
    } catch (SOAPException se) {
        verificationCache.put("SOAP header verification failed: " + se);
    }
}
 
Example #27
Source File: IntFaultClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void assertSoapHeader(BindingProvider serviceProxy) {
    List<?> headers = (List<?>) serviceProxy.getResponseContext().get(Header.HEADER_LIST);
    QName testQName = new QName("http://test", "test");
    if (headers != null) {
        for (Object o : headers) {
            if (o instanceof SoapHeader) {
                SoapHeader soapHeader = (SoapHeader) o;
                QName qName = soapHeader.getName();
                if (testQName.getNamespaceURI().equals(qName.getNamespaceURI())
                        && testQName.getLocalPart().equals(qName.getLocalPart())) {
                    Node returnedContent = (Node) soapHeader.getObject();
                    assertEquals("test", returnedContent.getTextContent());
                    return;
                }
            }
        }
    }
    fail("Header not found");
}
 
Example #28
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private void addSamlToken(SoapMessage message) {
    WSSConfig.init();
    SamlToken tok = assertSamlTokens(message);

    Header h = findSecurityHeader(message, true);
    try {
        AssertionWrapper wrapper = addSamlToken(tok, message);
        if (wrapper == null) {
            AssertionInfoMap aim = message.get(AssertionInfoMap.class);
            Collection<AssertionInfo> ais = aim.getAssertionInfo(SP12Constants.SAML_TOKEN);
            for (AssertionInfo ai : ais) {
                if (ai.isAsserted()) {
                    ai.setAsserted(false);
                }
            }
            return;
        }
        Element el = (Element)h.getObject();
        el.appendChild(wrapper.toDOM(el.getOwnerDocument()));
    } catch (WSSecurityException ex) {
        policyNotAsserted(tok, ex.getMessage(), message);
    }
}
 
Example #29
Source File: EncoderDecoder.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Builds an element containing a WS-RM Fault. This adds the appropriate WS-RM namespace declaration to
 * the element, and then adds the Fault as a child element.
 *
 * @param sf
 * @return Header fault
 */
public Header buildHeaderFault(SequenceFault sf) throws JAXBException {
    Object o = buildHeaderFaultObject(sf);

    return new Header(new QName(getConstants().getWSRMNamespace(),
                                RMConstants.SEQUENCE_FAULT_NAME),
                      o, getDataBinding());
}
 
Example #30
Source File: RMSoapOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void verifyHeaders(SoapMessage message, String... names) {
    List<Header> headers = new ArrayList<>(message.getHeaders());

    // check all expected headers are present

    for (String name : names) {
        boolean found = false;
        Iterator<Header> iter = headers.iterator();
        while (iter.hasNext()) {
            Header header = iter.next();
            Object obj = header.getObject();
            String namespace = header.getName().getNamespaceURI();
            String localName = header.getName().getLocalPart();
            if (obj instanceof Element) {
                Element elem = (Element) obj;
                namespace = elem.getNamespaceURI();
                localName = elem.getLocalName();
            }
            if (RM10Constants.NAMESPACE_URI.equals(namespace)
                && localName.equals(name)) {
                found = true;
                iter.remove();
                break;
            } else if (Names.WSA_NAMESPACE_NAME.equals(namespace)
                && localName.equals(name)) {
                found = true;
                iter.remove();
                break;
            }
        }
        assertTrue("Could not find header element " + name, found);
    }

    // no other headers should be present
    assertTrue(headers.isEmpty());
}