Search in sources :

Example 86 with STSClient

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

the class SecurityContextTokenCancelTest method requestSecurityToken.

private SecurityToken requestSecurityToken(Bus bus, String wsdlLocation, boolean enableEntropy) throws Exception {
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation(wsdlLocation);
    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("ws-security.sts.token.properties", "serviceKeystore.properties");
    stsClient.setProperties(properties);
    stsClient.setSecureConv(true);
    stsClient.setRequiresEntropy(enableEntropy);
    stsClient.setKeySize(128);
    stsClient.setAddressingNamespace("http://www.w3.org/2005/08/addressing");
    return stsClient.requestSecurityToken(null);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap)

Example 87 with STSClient

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

the class SecurityContextTokenCancelTest method cancelSecurityToken.

private boolean cancelSecurityToken(Bus bus, String wsdlLocation, String port, boolean enableEntropy, SecurityToken securityToken) throws Exception {
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation(wsdlLocation);
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName(port);
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.SIGNATURE_USERNAME, "myservicekey");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, "serviceKeystore.properties");
    properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "serviceKeystore.properties");
    stsClient.setProperties(properties);
    stsClient.setSecureConv(true);
    stsClient.setRequiresEntropy(enableEntropy);
    stsClient.setAddressingNamespace("http://www.w3.org/2005/08/addressing");
    return stsClient.cancelSecurityToken(securityToken);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap)

Example 88 with STSClient

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

the class TokenTestUtils method updateSTSPort.

public static void updateSTSPort(BindingProvider p, String port) {
    STSClient stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT);
    if (stsClient == null) {
        stsClient = (STSClient) p.getRequestContext().get("ws-" + SecurityConstants.STS_CLIENT);
    }
    if (stsClient != null) {
        String location = stsClient.getWsdlLocation();
        if (location != null && location.contains("8080")) {
            stsClient.setWsdlLocation(location.replace("8080", port));
        } else if (location != null && location.contains("8443")) {
            stsClient.setWsdlLocation(location.replace("8443", port));
        }
    }
    stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
    if (stsClient == null) {
        stsClient = (STSClient) p.getRequestContext().get("ws-" + SecurityConstants.STS_CLIENT + ".sct");
    }
    if (stsClient != null) {
        String location = stsClient.getWsdlLocation();
        if (location.contains("8080")) {
            stsClient.setWsdlLocation(location.replace("8080", port));
        } else if (location.contains("8443")) {
            stsClient.setWsdlLocation(location.replace("8443", port));
        }
    }
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient)

Example 89 with STSClient

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

the class IssueUnitTest method requestSecurityToken.

// CHECKSTYLE:OFF
private SecurityToken requestSecurityToken(String tokenType, String keyType, Element supportingToken, Bus bus, String endpointAddress, String context, Map<String, Object> msgProperties, String realmUri, String wsdlPort) throws Exception {
    STSClient stsClient = new STSClient(bus);
    String port = STSPORT;
    if (realmUri != null) {
        stsClient.setWsdlLocation("https://localhost:" + port + "/SecurityTokenService/" + realmUri + "/Transport?wsdl");
    } else {
        stsClient.setWsdlLocation("https://localhost:" + port + "/SecurityTokenService/Transport?wsdl");
    }
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    if (wsdlPort != null) {
        stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}" + wsdlPort);
    } else {
        stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}Transport_Port");
    }
    Map<String, Object> properties = msgProperties;
    if (properties == null) {
        properties = new HashMap<>();
        properties.put(SecurityConstants.USERNAME, "alice");
        properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    }
    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);
    }
    if (supportingToken != null) {
        stsClient.setOnBehalfOf(supportingToken);
    }
    if (context != null) {
        stsClient.setContext(context);
    }
    stsClient.setProperties(properties);
    stsClient.setTokenType(tokenType);
    stsClient.setKeyType(keyType);
    return stsClient.requestSecurityToken(endpointAddress);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient)

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