Search in sources :

Example 41 with STSClient

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

the class WSSCTest method testSecureConversation.

@Test
public void testSecureConversation() throws Exception {
    final wssec.wssc.IPingService port = svc.getPort(new QName("http://WSSec/wssc", test.prefix), wssec.wssc.IPingService.class);
    if (PORT2.equals(test.port) || STAX_PORT2.equals(test.port)) {
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://localhost:" + test.port + "/" + test.prefix);
    } else {
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + test.port + "/" + test.prefix);
    }
    if (test.prefix.charAt(0) == '_') {
        // MS would like the _ versions to send a cancel
        ((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_TOKEN_DO_CANCEL, Boolean.TRUE);
    }
    if (test.streaming) {
        ((BindingProvider) port).getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
        ((BindingProvider) port).getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    }
    if (test.clearAction) {
        AbstractPhaseInterceptor<Message> clearActionInterceptor = new AbstractPhaseInterceptor<Message>(Phase.POST_LOGICAL) {

            public void handleMessage(Message message) throws Fault {
                STSClient client = STSUtils.getClient(message, "sct");
                client.getOutInterceptors().add(this);
                message.put(SecurityConstants.STS_CLIENT, client);
                String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
                if (s == null) {
                    s = SoapActionInInterceptor.getSoapAction(message);
                }
                if (s != null && s.contains("RST/SCT")) {
                    message.put(SoapBindingConstants.SOAP_ACTION, "");
                }
            }
        };
        clearActionInterceptor.addBefore(SoapPreProtocolOutInterceptor.class.getName());
        ((Client) port).getOutInterceptors().add(clearActionInterceptor);
    }
    wssec.wssc.PingRequest params = new wssec.wssc.PingRequest();
    org.xmlsoap.ping.Ping ping = new org.xmlsoap.ping.Ping();
    ping.setOrigin("CXF");
    ping.setScenario("Scenario5");
    ping.setText("ping");
    params.setPing(ping);
    try {
        wssec.wssc.PingResponse output = port.ping(params);
        assertEquals(OUT, output.getPingResponse().getText());
    } catch (Exception ex) {
        throw new Exception("Error doing " + test.prefix, ex);
    }
    ((java.io.Closeable) port).close();
}
Also used : SoapPreProtocolOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) STSClient(org.apache.cxf.ws.security.trust.STSClient) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Test(org.junit.Test)

Example 42 with STSClient

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

the class WSSCUnitTest method testIssueUnitTest.

@Test
public void testIssueUnitTest() throws Exception {
    if (test.isStreaming()) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSCUnitTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    STSClient stsClient = new STSClient(bus);
    stsClient.setSecureConv(true);
    stsClient.setLocation("https://localhost:" + PORT + "/" + "DoubleItTransport");
    // Add Addressing policy
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();
    all.addPolicyComponent(new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, false));
    ea.addPolicyComponent(all);
    stsClient.setPolicy(p);
    stsClient.requestSecurityToken("http://localhost:" + PORT + "/" + "DoubleItTransport");
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) ExactlyOne(org.apache.neethi.ExactlyOne) URL(java.net.URL) Test(org.junit.Test)

Example 43 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.

the class WSTrustTestUtils method setupWsseAndSTSClientNoCallbackHandler.

/**
     * A PASSWORD is provided in place of the ClientCallbackHandler in the
     * STSClient.  A USERNAME and PASSWORD is required by CXF in the msg.
     *
     * @param proxy
     * @param bus
     * @param stsWsdlLocation
     * @param stsService
     * @param stsPort
     * @see org.apache.cxf.ws.security.SecurityConstants#PASSWORD
     */
public static void setupWsseAndSTSClientNoCallbackHandler(ServiceIface proxy, Bus bus, String stsWsdlLocation, QName stsService, QName stsPort) {
    Map<String, Object> ctx = ((BindingProvider) proxy).getRequestContext();
    setServiceContextAttributes(ctx);
    STSClient stsClient = new STSClient(bus);
    if (stsWsdlLocation != null) {
        stsClient.setWsdlLocation(stsWsdlLocation);
        stsClient.setServiceQName(stsService);
        stsClient.setEndpointQName(stsPort);
    }
    Map<String, Object> props = stsClient.getProperties();
    props.put(SecurityConstants.USERNAME, "alice");
    props.put(SecurityConstants.PASSWORD, "clarinet");
    props.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
    props.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
    props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
    ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) BindingProvider(javax.xml.ws.BindingProvider)

Example 44 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.

the class WSTrustTestUtils method setupWsseAndSTSClientOnBehalfOf.

/**
     * Request a security token that allows it to act on the behalf of somebody else.
     *
     * @param proxy
     * @param bus
     */
public static void setupWsseAndSTSClientOnBehalfOf(BindingProvider proxy, Bus bus) {
    Map<String, Object> ctx = proxy.getRequestContext();
    ctx.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
    ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myactaskey");
    ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
    ctx.put(SecurityConstants.USERNAME, "alice");
    ctx.put(SecurityConstants.PASSWORD, "clarinet");
    STSClient stsClient = new STSClient(bus);
    stsClient.setOnBehalfOf(new UsernameTokenCallbackHandler());
    Map<String, Object> props = stsClient.getProperties();
    props.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
    props.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
    props.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
    props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
    ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) ClientCallbackHandler(org.jboss.as.test.integration.ws.wsse.trust.shared.ClientCallbackHandler) UsernameTokenCallbackHandler(org.jboss.as.test.integration.ws.wsse.trust.shared.UsernameTokenCallbackHandler)

Example 45 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.

the class WSTrustTestUtils method setupWsseAndSTSClientBearer.

public static void setupWsseAndSTSClientBearer(BindingProvider proxy, Bus bus) {
    Map<String, Object> ctx = proxy.getRequestContext();
    STSClient stsClient = new STSClient(bus);
    ctx.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
    ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
    ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myservicekey");
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.USERNAME), "alice");
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.CALLBACK_HANDLER), new ClientCallbackHandler());
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.ENCRYPT_PROPERTIES), Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.ENCRYPT_USERNAME), "mystskey");
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_USERNAME), "myclientkey");
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_PROPERTIES), Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
    ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO), "true");
    ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) ClientCallbackHandler(org.jboss.as.test.integration.ws.wsse.trust.shared.ClientCallbackHandler)

Aggregations

STSClient (org.apache.cxf.ws.security.trust.STSClient)89 Bus (org.apache.cxf.Bus)35 HashMap (java.util.HashMap)33 URL (java.net.URL)31 QName (javax.xml.namespace.QName)29 Service (javax.xml.ws.Service)27 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)24 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)21 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)14 BindingProvider (javax.xml.ws.BindingProvider)11 Test (org.junit.Test)11 Client (org.apache.cxf.endpoint.Client)9 WebService (javax.jws.WebService)5 BusException (org.apache.cxf.BusException)5 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 EndpointException (org.apache.cxf.endpoint.EndpointException)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 ClientCallbackHandler (org.jboss.as.test.integration.ws.wsse.trust.shared.ClientCallbackHandler)5 DOMSource (javax.xml.transform.dom.DOMSource)4