Examples of STSClient


Examples of org.apache.cxf.ws.security.trust.STSClient

            TokenTestUtils.updateSTSPort((BindingProvider)asymmetricSaml1EncryptedPort, STSPORT2);
        }
       
        // Set the X509Certificate manually on the STSClient (just to test that we can)
        BindingProvider bindingProvider = (BindingProvider)asymmetricSaml1EncryptedPort;
        STSClient stsClient =
            (STSClient)bindingProvider.getRequestContext().get(SecurityConstants.STS_CLIENT);
        Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
        CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
        cryptoType.setAlias("myclientkey");
        X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
        stsClient.setUseKeyCertificate(certs[0]);
       
        doubleIt(asymmetricSaml1EncryptedPort, 40);
       
        ((java.io.Closeable)asymmetricSaml1EncryptedPort).close();
        bus.shutdown(true);
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

            String tokenType,
            String keyType,
            Bus bus,
            String endpointAddress
    ) throws Exception {
        STSClient stsClient = new STSClient(bus);
        String port = "8443";
        if (standalone) {
            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<String, Object>();
        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);
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

        String context,
        Map<String, Object> msgProperties,
        String realmUri,
        String wsdlPort
    ) throws Exception {
        STSClient stsClient = new STSClient(bus);
        String port = "8443";
        if (standalone) {
            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<String, Object>();
            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);
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

                if (isRequestor(message)) {
                    IssuedToken itok = (IssuedToken)ais.iterator().next().getAssertion();
                   
                    SecurityToken tok = retrieveCachedToken(message);
                    if (tok == null) {
                        STSClient client = STSUtils.getClient(message, "sts", itok);
                        AddressingProperties maps =
                            (AddressingProperties)message
                                .get("javax.xml.ws.addressing.context.outbound");
                        if (maps == null) {
                            maps = (AddressingProperties)message
                                .get("javax.xml.ws.addressing.context");
                        }
                        synchronized (client) {
                            try {
                                // Transpose ActAs/OnBehalfOf info from original request to the STS client.
                                Object token =
                                    message.getContextualProperty(SecurityConstants.STS_TOKEN_ACT_AS);
                                if (token != null) {
                                    client.setActAs(token);
                                }
                                token =
                                    message.getContextualProperty(SecurityConstants.STS_TOKEN_ON_BEHALF_OF);
                                if (token != null) {
                                    client.setOnBehalfOf(token);
                                }
                                Map<String, Object> ctx = client.getRequestContext();
                                mapSecurityProps(message, ctx);
                           
                                Object o = message.getContextualProperty(SecurityConstants.STS_APPLIES_TO);
                                String appliesTo = o == null ? null : o.toString();
                                appliesTo = appliesTo == null
                                    ? message.getContextualProperty(Message.ENDPOINT_ADDRESS).toString()
                                        : appliesTo;
                                boolean enableAppliesTo = client.isEnableAppliesTo();
                               
                                client.setMessage(message);
                                Element onBehalfOfToken = client.getOnBehalfOfToken();
                                Element actAsToken = client.getActAsToken();
                               
                                SecurityToken secToken =
                                    handleDelegation(
                                        message, onBehalfOfToken, actAsToken, appliesTo, enableAppliesTo
                                    );
                                if (secToken == null) {
                                    secToken = getTokenFromSTS(message, client, aim, maps, itok, appliesTo);
                                }
                                tok = secToken;
                                storeDelegationTokens(
                                    message, tok, onBehalfOfToken, actAsToken, appliesTo, enableAppliesTo
                                );
                            } catch (RuntimeException e) {
                                throw e;
                            } catch (Exception e) {
                                throw new Fault(e);
                            } finally {
                                client.setTrust((Trust10)null);
                                client.setTrust((Trust13)null);
                                client.setTemplate(null);
                                client.setAddressingNamespace(null);
                            }
                        }
                    } else {
                        //renew token?
                    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

        }
       
        //
        // Now initiate WS-Trust exchange
        //
        STSClient client = STSUtils.getClient(message, "spnego");
        AddressingProperties maps =
            (AddressingProperties)message.get("javax.xml.ws.addressing.context.outbound");
        if (maps == null) {
            maps = (AddressingProperties)message.get("javax.xml.ws.addressing.context");
        }
        synchronized (client) {
            try {
                String s = SpnegoTokenInterceptorProvider.setupClient(client, message, aim);
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                SecurityToken tok = client.requestSecurityToken(s, Base64.encode(spnegoToken.getToken()));
               
                byte[] wrappedTok = spnegoToken.unwrapKey(tok.getSecret());
                tok.setSecret(wrappedTok);
                spnegoToken.clear();
               
                return tok;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
            } finally {
                client.setTrust((Trust10)null);
                client.setTrust((Trust13)null);
                client.setTemplate(null);
                client.setLocation(null);
                client.setAddressingNamespace(null);
            }
        }
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

        message.getExchange().get(Endpoint.class).remove(SecurityConstants.TOKEN_ID);
        message.getExchange().remove(SecurityConstants.TOKEN_ID);
        message.getExchange().remove(SecurityConstants.TOKEN);
        NegotiationUtils.getTokenStore(message).remove(tok);
       
        STSClient client = STSUtils.getClient(message, "sct");
        AddressingProperties maps =
            (AddressingProperties)message
                .get("javax.xml.ws.addressing.context.outbound");
        if (maps == null) {
            maps = (AddressingProperties)message
                .get("javax.xml.ws.addressing.context");
        } else if (maps.getAction().getValue().endsWith("Renew")) {
            return;
        }
        synchronized (client) {
            try {
                SecureConversationTokenInterceptorProvider.setupClient(client, message, aim, itok, true);

                String s = message
                    .getContextualProperty(Message.ENDPOINT_ADDRESS).toString();
                client.setLocation(s);
               
                Map<String, Object> ctx = client.getRequestContext();
                ctx.put(SecurityConstants.TOKEN, tok);
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                client.renewSecurityToken(tok);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
            } finally {
                client.setTrust((Trust10)null);
                client.setTrust((Trust13)null);
                client.setTemplate(null);
                client.setLocation(null);
                client.setAddressingNamespace(null);
            }
        }           
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

        }           
    }
    private SecurityToken issueToken(SoapMessage message,
                                     AssertionInfoMap aim,
                                     SecureConversationToken itok) {
        STSClient client = STSUtils.getClient(message, "sct");
        AddressingProperties maps =
            (AddressingProperties)message
                .get("javax.xml.ws.addressing.context.outbound");
        if (maps == null) {
            maps = (AddressingProperties)message
                .get("javax.xml.ws.addressing.context");
        }
        synchronized (client) {
            try {
                String s = SecureConversationTokenInterceptorProvider
                    .setupClient(client, message, aim, itok, false);

                SecurityToken tok = null;
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                tok = client.requestSecurityToken(s);
                String tokenType = tok.getTokenType();
                tok.setTokenType(tokenType);
                if (tokenType == null || "".equals(tokenType)) {
                    tok.setTokenType(WSConstants.WSC_SCT);
                }
                return tok;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
            } finally {
                client.setTrust((Trust10)null);
                client.setTrust((Trust13)null);
                client.setTemplate(null);
                client.setLocation(null);
                client.setAddressingNamespace(null);
            }
        }
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

                            SecureConversationToken itok) {
        if (tok.getState() != SecurityToken.State.EXPIRED) {
            return;
        }
       
        STSClient client = SecureConversationTokenInterceptorProvider.getClient(message);
        AddressingProperties maps =
            (AddressingProperties)message
                .get("javax.xml.ws.addressing.context.outbound");
        if (maps == null) {
            maps = (AddressingProperties)message
                .get("javax.xml.ws.addressing.context");
        } else if (maps.getAction().getValue().endsWith("Renew")) {
            return;
        }
        synchronized (client) {
            try {
                SecureConversationTokenInterceptorProvider.setupClient(client, message, aim, itok, true);

                String s = message
                    .getContextualProperty(Message.ENDPOINT_ADDRESS).toString();
                client.setLocation(s);
               
                Map<String, Object> ctx = client.getRequestContext();
                ctx.put(SecurityConstants.TOKEN, tok);
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                client.renewSecurityToken(tok);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
            } finally {
                client.setTrust((Trust10)null);
                client.setTrust((Trust13)null);
                client.setTemplate(null);
                client.setLocation(null);
                client.setAddressingNamespace(null);
            }
        }           
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

        }           
    }
    private SecurityToken issueToken(SoapMessage message,
                                     AssertionInfoMap aim,
                                     SecureConversationToken itok) {
        STSClient client = SecureConversationTokenInterceptorProvider.getClient(message);
        AddressingProperties maps =
            (AddressingProperties)message
                .get("javax.xml.ws.addressing.context.outbound");
        if (maps == null) {
            maps = (AddressingProperties)message
                .get("javax.xml.ws.addressing.context");
        }
        synchronized (client) {
            try {
                String s = SecureConversationTokenInterceptorProvider
                    .setupClient(client, message, aim, itok, false);

                SecurityToken tok = null;
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                tok = client.requestSecurityToken(s);
                tok.setTokenType(WSConstants.WSC_SCT);
                return tok;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
            } finally {
                client.setTrust((Trust10)null);
                client.setTrust((Trust13)null);
                client.setTemplate(null);
                client.setLocation(null);
                client.setAddressingNamespace(null);
            }
        }
    }
View Full Code Here

Examples of org.apache.cxf.ws.security.trust.STSClient

                ctx.put(s, v);
            }
        }
    }
    static STSClient getClient(Message message) {
        STSClient client = (STSClient)message
            .getContextualProperty(SecurityConstants.STS_CLIENT);
        if (client == null) {
            client = new STSClient(message.getExchange().get(Bus.class));
            Endpoint ep = message.getExchange().get(Endpoint.class);
            client.setEndpointName(ep.getEndpointInfo().getName().toString() + ".sct-client");
            client.setBeanName(ep.getEndpointInfo().getName().toString() + ".sct-client");
        }
        return client;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.