Search in sources :

Example 1 with ReceivedTokenCallbackHandler

use of org.apache.cxf.ws.security.trust.delegation.ReceivedTokenCallbackHandler in project cxf by apache.

the class IntermediaryCachingPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) {
    if (transportPort == null) {
        // Re-use the same proxy
        URL wsdl = IntermediaryCachingPortTypeImpl.class.getResource("DoubleIt.wsdl");
        Service service = Service.create(wsdl, SERVICE_QNAME);
        QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
        transportPort = service.getPort(portQName, DoubleItPortType.class);
        try {
            updateAddressPort(transportPort, IntermediaryTransformationCachingTest.PORT2);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if ("standalone".equals(System.getProperty("sts.deployment"))) {
            Map<String, Object> context = ((BindingProvider) transportPort).getRequestContext();
            STSClient stsClient = (STSClient) context.get(SecurityConstants.STS_CLIENT);
            if (stsClient == null) {
                stsClient = (STSClient) context.get("ws-" + SecurityConstants.STS_CLIENT);
            }
            if (stsClient != null) {
                String location = stsClient.getWsdlLocation();
                if (location.contains("8080")) {
                    stsClient.setWsdlLocation(location.replace("8080", IntermediaryTransformationCachingTest.STSPORT2));
                } else if (location.contains("8443")) {
                    stsClient.setWsdlLocation(location.replace("8443", IntermediaryTransformationCachingTest.STSPORT));
                }
            }
        }
    }
    Principal pr = wsc.getUserPrincipal();
    Assert.assertNotNull("Principal must not be null", pr);
    Assert.assertNotNull("Principal.getName() must not return null", pr.getName());
    // Disable the STSClient after the second invocation
    if (i > 1) {
        BindingProvider p = (BindingProvider) transportPort;
        STSClient stsClient = new STSClient(null);
        stsClient.setOnBehalfOf(new ReceivedTokenCallbackHandler());
        p.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    }
    i++;
    return transportPort.doubleIt(numberToDouble);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) QName(javax.xml.namespace.QName) ReceivedTokenCallbackHandler(org.apache.cxf.ws.security.trust.delegation.ReceivedTokenCallbackHandler) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Principal(java.security.Principal)

Aggregations

URL (java.net.URL)1 Principal (java.security.Principal)1 WebService (javax.jws.WebService)1 QName (javax.xml.namespace.QName)1 BindingProvider (javax.xml.ws.BindingProvider)1 Service (javax.xml.ws.Service)1 STSClient (org.apache.cxf.ws.security.trust.STSClient)1 ReceivedTokenCallbackHandler (org.apache.cxf.ws.security.trust.delegation.ReceivedTokenCallbackHandler)1 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)1