Search in sources :

Example 26 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient 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, IntermediaryTransformationTest.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", IntermediaryTransformationTest.STSPORT2));
            } else if (location.contains("8443")) {
                stsClient.setWsdlLocation(location.replace("8443", IntermediaryTransformationTest.STSPORT));
            }
        }
    }
    return transportPort.doubleIt(numberToDouble);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) Principal(java.security.Principal) URL(java.net.URL)

Example 27 with STSClient

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

the class IssueUnitTest method requestSecurityTokenTTL.

private SecurityToken requestSecurityTokenTTL(String tokenType, String keyType, Bus bus, String endpointAddress) throws Exception {
    STSClient stsClient = new STSClient(bus);
    String port = STSPORT;
    stsClient.setWsdlLocation("https://localhost:" + port + "/SecurityTokenService/Transport?wsdl");
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}Transport_Port");
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "clientKeystore.properties");
    properties.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
    properties.put(SecurityConstants.IS_BSP_COMPLIANT, "false");
    if (PUBLIC_KEY_KEYTYPE.equals(keyType)) {
        properties.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
        properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, "clientKeystore.properties");
        stsClient.setUseCertificateForConfirmationKeyInfo(true);
    }
    stsClient.setEnableLifetime(true);
    stsClient.setTtl(60 * 30);
    stsClient.setProperties(properties);
    stsClient.setTokenType(tokenType);
    stsClient.setKeyType(keyType);
    stsClient.setAddressingNamespace("http://www.w3.org/2005/08/addressing");
    return stsClient.requestSecurityToken(endpointAddress);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap)

Example 28 with STSClient

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

the class STSTokenOutInterceptorTest method initStsClientTransportBinding.

private STSClient initStsClientTransportBinding(Bus bus) {
    bus.getInInterceptors().add(new LoggingOutInterceptor());
    bus.getOutInterceptors().add(new LoggingInInterceptor());
    bus.getOutFaultInterceptors().add(new LoggingInInterceptor());
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + STS_TRANSPORT_WSDL_LOCATION_RELATIVE);
    stsClient.setServiceName(STS_SERVICE_NAME);
    stsClient.setEndpointName(STS_TRANSPORT_ENDPOINT_NAME);
    stsClient.setTokenType(TOKEN_TYPE_SAML_2_0);
    stsClient.setAllowRenewingAfterExpiry(true);
    stsClient.setEnableLifetime(true);
    Map<String, Object> props = new HashMap<>();
    props.put(SecurityConstants.USERNAME, "alice");
    props.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    stsClient.setProperties(props);
    return stsClient;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor)

Example 29 with STSClient

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

the class STSTokenOutInterceptorTest method testSTSClientAsymmetricBinding.

@Test
public void testSTSClientAsymmetricBinding() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient stsClient = initStsClientAsymmeticBinding(bus);
    STSTokenOutInterceptor interceptor = new STSTokenOutInterceptor(stsClient);
    MessageImpl message = prepareMessage(bus, null, SERVICE_ENDPOINT_ASSYMETRIC);
    interceptor.handleMessage(message);
    SecurityToken token = (SecurityToken) message.getExchange().get(SecurityConstants.TOKEN);
    validateSecurityToken(token);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) STSTokenOutInterceptor(org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 30 with STSClient

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

the class STSTokenRetrieverTest method initStsClientTransportBinding.

private STSClient initStsClientTransportBinding(Bus bus) {
    bus.getInInterceptors().add(new LoggingOutInterceptor());
    bus.getOutInterceptors().add(new LoggingInInterceptor());
    bus.getOutFaultInterceptors().add(new LoggingInInterceptor());
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + STS_TRANSPORT_WSDL_LOCATION_RELATIVE);
    stsClient.setServiceName(STS_SERVICE_NAME);
    stsClient.setEndpointName(STS_TRANSPORT_ENDPOINT_NAME);
    stsClient.setTokenType(TOKEN_TYPE_SAML_2_0);
    stsClient.setAllowRenewingAfterExpiry(true);
    stsClient.setEnableLifetime(true);
    Map<String, Object> props = new HashMap<>();
    props.put(SecurityConstants.USERNAME, "alice");
    props.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    stsClient.setProperties(props);
    return stsClient;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor)

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