Search in sources :

Example 41 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class BaseGreeterImpl method greetMe.

public String greetMe(String me) {
    if ("secure".equals(me)) {
        MessageContext ctx = getContext().getMessageContext();
        return "Hello " + ctx.get(BindingProvider.USERNAME_PROPERTY);
    }
    if ("principal".equals(me)) {
        return "Hello " + getContext().getUserPrincipal().getName();
    }
    LOG.info("Invoking greetMe " + prefix + me);
    invocationCount++;
    return "Hello " + me;
}
Also used : MessageContext(javax.xml.ws.handler.MessageContext)

Example 42 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class DoubleItPortTypeImpl method doubleIt.

/**
 * Disable the STSClient after the first successful invocation
 */
public int doubleIt(int numberToDouble) {
    MessageContext context = wsc.getMessageContext();
    WrappedMessageContext wmc = (WrappedMessageContext) context;
    Exchange exchange = wmc.getWrappedMessage().getExchange();
    exchange.getEndpoint().put(SecurityConstants.STS_CLIENT, new STSClient(exchange.getBus()));
    return numberToDouble * 2;
}
Also used : Exchange(org.apache.cxf.message.Exchange) STSClient(org.apache.cxf.ws.security.trust.STSClient) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 43 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class IntermediaryPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) {
    Principal pr = wsc.getUserPrincipal();
    Assert.assertNotNull("Principal must not be null", pr);
    Assert.assertNotNull("Principal.getName() must not return null", pr.getName());
    URL wsdl = IntermediaryPortTypeImpl.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    try {
        updateAddressPort(transportPort, KerberosDelegationTokenTest.PORT);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // Retrieve delegated credential + set it on the outbound message
    MessageContext messageContext = wsc.getMessageContext();
    GSSCredential delegatedCredential = (GSSCredential) messageContext.get(SecurityConstants.DELEGATED_CREDENTIAL);
    Map<String, Object> context = ((BindingProvider) transportPort).getRequestContext();
    context.put(SecurityConstants.DELEGATED_CREDENTIAL, delegatedCredential);
    STSClient stsClient = (STSClient) context.get(SecurityConstants.STS_CLIENT);
    if (stsClient != null) {
        String location = stsClient.getWsdlLocation();
        if (location.contains("8443")) {
            stsClient.setWsdlLocation(location.replace("8443", KerberosDelegationTokenTest.STSPORT));
        }
    }
    return transportPort.doubleIt(numberToDouble);
}
Also used : QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) GSSCredential(org.ietf.jgss.GSSCredential) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) MessageContext(javax.xml.ws.handler.MessageContext) Principal(java.security.Principal)

Example 44 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class DoubleItPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) {
    // 
    // Get the transformed SAML Assertion from the STS and check it
    // 
    MessageContext context = wsc.getMessageContext();
    final List<WSHandlerResult> handlerResults = CastUtils.cast((List<?>) context.get(WSHandlerConstants.RECV_RESULTS));
    WSSecurityEngineResult actionResult = handlerResults.get(0).getActionResults().get(WSConstants.UT).get(0);
    SamlAssertionWrapper assertion = (SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN);
    Assert.assertTrue(assertion != null && "DoubleItSTSIssuer".equals(assertion.getIssuerString()));
    return numberToDouble * 2;
}
Also used : SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) MessageContext(javax.xml.ws.handler.MessageContext) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Example 45 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class TwoWayJMSImplBase method greetMe.

public String greetMe(String me) {
    if (me.startsWith("PauseForTwoSecs")) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        // ignore
        }
        me = me.substring("PauseForTwoSecs".length()).trim();
    }
    MessageContext mc = wsContext.getMessageContext();
    JMSMessageHeadersType responseHeaders = (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_RESPONSE_HEADERS);
    responseHeaders.putProperty("Test_Prop", "some return value " + me);
    return "Hello " + me;
}
Also used : JMSMessageHeadersType(org.apache.cxf.transport.jms.JMSMessageHeadersType) MessageContext(javax.xml.ws.handler.MessageContext)

Aggregations

MessageContext (javax.xml.ws.handler.MessageContext)46 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 QName (javax.xml.namespace.QName)10 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)9 Exchange (org.apache.cxf.message.Exchange)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)8 List (java.util.List)7 Header (org.apache.cxf.headers.Header)7 IOException (java.io.IOException)6 Handler (javax.xml.ws.handler.Handler)6 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpSession (javax.servlet.http.HttpSession)5 JAXBException (javax.xml.bind.JAXBException)5 SOAPMessage (javax.xml.soap.SOAPMessage)5 Binding (javax.xml.ws.Binding)5