Search in sources :

Example 46 with STSClient

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

the class WSTrustTestUtils method createSTSClient.

/**
     * Create and configure an STSClient for use by service ServiceImpl.
     * <p/>
     * Whenever an "<sp:IssuedToken>" policy is configured on a WSDL port, as is the
     * case for ServiceImpl, a STSClient must be created and configured in
     * order for the service to connect to the STS-server to obtain a token.
     *
     * @param bus
     * @param stsWsdlLocation
     * @param stsService
     * @param stsPort
     * @return
     */
private static STSClient createSTSClient(Bus bus, String stsWsdlLocation, QName stsService, QName stsPort) {
    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.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");
    return stsClient;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) ClientCallbackHandler(org.jboss.as.test.integration.ws.wsse.trust.shared.ClientCallbackHandler)

Example 47 with STSClient

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

the class ActAsServiceImpl method sayHello.

public String sayHello(String host, String port) {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final String serviceURL = "http://" + host + ":" + port + "/jaxws-samples-wsse-policy-trust/SecurityService";
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        Map<String, Object> ctx = ((BindingProvider) proxy).getRequestContext();
        ctx.put(SecurityConstants.CALLBACK_HANDLER, new ActAsCallbackHandler());
        ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myactaskey");
        ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("../../META-INF/clientKeystore.properties"));
        ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myservicekey");
        STSClient stsClient = new STSClient(bus);
        Map<String, Object> props = stsClient.getProperties();
        props.put(SecurityConstants.USERNAME, "alice");
        props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
        props.put(SecurityConstants.STS_TOKEN_USERNAME, "myactaskey");
        props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
        ctx.put(SecurityConstants.STS_CLIENT, stsClient);
        return "ActAs " + proxy.sayHello();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) MalformedURLException(java.net.MalformedURLException) ServiceIface(org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface) QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 48 with STSClient

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

the class AbstractStsRealm method renewSecurityToken.

/**
     * Renew a security token (SAML assertion) from the STS.
     *
     * @param securityToken The token being renewed.
     * @return security token (SAML assertion)
     */
protected SecurityToken renewSecurityToken(SecurityToken securityToken) {
    SecurityToken token = null;
    String stsAddress = getAddress();
    try {
        LOGGER.debug("Renewing security token from STS at: {}.", stsAddress);
        if (securityToken != null) {
            LOGGER.debug("Telling the STS to renew a security token on behalf of the auth token");
            STSClient stsClient = configureStsClient();
            stsClient.setWsdlLocation(stsAddress);
            stsClient.setTokenType(getAssertionType());
            stsClient.setKeyType(getKeyType());
            stsClient.setKeySize(Integer.parseInt(getKeySize()));
            stsClient.setAllowRenewing(true);
            token = stsClient.renewSecurityToken(securityToken);
            LOGGER.debug("Finished renewing security token.");
        }
    } catch (Exception e) {
        String msg = "Error renewing the security token from STS at: " + stsAddress + ".";
        LOGGER.debug(msg, e);
        throw new AuthenticationException(msg, e);
    }
    return token;
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) STSClient(org.apache.cxf.ws.security.trust.STSClient) AuthenticationException(org.apache.shiro.authc.AuthenticationException) XMLStreamException(javax.xml.stream.XMLStreamException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 49 with STSClient

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

the class AbstractStsRealm method requestSecurityToken.

/**
     * Request a security token (SAML assertion) from the STS.
     *
     * @param authToken The subject the security token is being request for.
     * @return security token (SAML assertion)
     */
protected SecurityToken requestSecurityToken(Object authToken) {
    SecurityToken token = null;
    String stsAddress = getAddress();
    try {
        LOGGER.debug("Requesting security token from STS at: {}.", stsAddress);
        if (authToken != null) {
            LOGGER.debug("Telling the STS to request a security token on behalf of the auth token");
            STSClient stsClient = configureStsClient();
            stsClient.setWsdlLocation(stsAddress);
            stsClient.setOnBehalfOf(authToken);
            stsClient.setTokenType(getAssertionType());
            stsClient.setKeyType(getKeyType());
            stsClient.setKeySize(Integer.parseInt(getKeySize()));
            token = stsClient.requestSecurityToken(stsAddress);
            LOGGER.debug("Finished requesting security token.");
        }
    } catch (Exception e) {
        String msg = "Error requesting the security token from STS at: " + stsAddress + ".";
        LOGGER.debug(msg, e);
        throw new AuthenticationException(msg, e);
    }
    return token;
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) STSClient(org.apache.cxf.ws.security.trust.STSClient) AuthenticationException(org.apache.shiro.authc.AuthenticationException) XMLStreamException(javax.xml.stream.XMLStreamException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 50 with STSClient

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

the class AbstractStsRealm method configureBaseStsClient.

/**
     * Helper method to setup STS Client.
     */
private STSClient configureBaseStsClient() {
    STSClient stsClient = new STSClient(bus);
    String stsAddress = getAddress();
    String stsServiceName = getServiceName();
    String stsEndpointName = getEndpointName();
    if (stsAddress != null) {
        LOGGER.debug("Setting WSDL location on STSClient: " + stsAddress);
        stsClient.setWsdlLocation(stsAddress);
    }
    if (stsServiceName != null) {
        LOGGER.debug("Setting service name on STSClient: {}", stsServiceName);
        stsClient.setServiceName(stsServiceName);
    }
    if (stsEndpointName != null) {
        LOGGER.debug("Setting endpoint name on STSClient: {}", stsEndpointName);
        stsClient.setEndpointName(stsEndpointName);
    }
    LOGGER.debug("Setting addressing namespace on STSClient: {}", ADDRESSING_NAMESPACE);
    stsClient.setAddressingNamespace(ADDRESSING_NAMESPACE);
    return stsClient;
}
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