camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1096398 [2/4] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/util/jsse/ camel-core/src/test/java/org/apache/camel/util/jsse/ camel-core/src/test/resources/org/apache/camel/util/ camel-core/src/test/resources/org/apache/camel/...
Date Mon, 25 Apr 2011 02:52:46 GMT
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,382 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.util.List;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents {@link SSLContext} configuration options used in instantiating an
+ * {@code SSLContext} instance.
+ */
+public class SSLContextParameters extends BaseSSLContextParameters {
+    
+    protected static final String DEFAULT_SECURE_SOCKET_PROTOCOL = "TLS";
+    
+    private static final Logger LOG = LoggerFactory.getLogger(SSLContextParameters.class);
+
+    /**
+     * The optional key manager configuration for creating the
+     * {@link KeyManager}s used in constructing an {@link SSLContext}.
+     */
+    private KeyManagersParameters keyManagers;
+    
+    /**
+     * The optional trust manager configuration for creating the
+     * {@link TrustManager}s used in constructing an {@link SSLContext}.
+     */
+    private TrustManagersParameters trustManagers;
+        
+    /**
+     * The optional secure random configuration options to use for constructing
+     * the {@link SecureRandom} used in the creation of an {@link SSLContext].
+     */
+    private SecureRandomParameters secureRandom;
+    
+    /**
+     * The optional configuration options to be applied purely to the client side settings
+     * of the {@link SSLContext}.  Settings specified here override any duplicate settings
+     * provided at the overall level by this class.  These parameters apply to 
+     * {@link SSLSocketFactory}s and {@link SSLEngine}s produced by the the {@code SSLContext}
+     * produced from this class as well as to the {@code SSLContext} itself.
+     */
+    private SSLContextClientParameters clientParameters;
+    
+    /**
+     * The optional configuration options to be applied purely to the server side settings
+     * of the {@link SSLContext}.  Settings specified here override any duplicate settings
+     * provided at the overall level by this class.  These parameters apply to 
+     * {@link SSLServerSocketFactory}s and {@link SSLEngine}s produced by the the {@code SSLContext}
+     * produced from this class as well as to the {@code SSLContext} itself.
+     */
+    private SSLContextServerParameters serverParameters;
+
+    /**
+     * The optional provider identifier for the JSSE implementation to use when
+     * constructing an {@link SSLContext}.
+     */
+    private String provider;
+
+    /**
+     * The optional protocol for the secure sockets created by the {@link SSLContext}
+     * represented by this instance's configuration. See Appendix A in the <a
+     * href="http://download.oracle.com/javase/6/docs/technotes/guides//security/jsse/JSSERefGuide.html#AppA"
+     * >Java Secure Socket Extension Reference Guide</a> for information about
+     * standard protocol names.
+     */
+    private String secureSocketProtocol;    
+
+    /**
+     * @see #setKeyManagers(KeyManager)
+     */
+    public KeyManagersParameters getKeyManagers() {
+        return keyManagers;
+    }
+
+    /**
+     * Sets the optional key manager configuration for creating the
+     * {@link KeyManager}s used in constructing an {@link SSLContext}.
+     * 
+     * @param keyManagers the options or {@code null} to provide no
+     *            {@code KeyManager}s
+     */
+    public void setKeyManagers(KeyManagersParameters keyManagers) {
+        this.keyManagers = keyManagers;
+    }
+
+    /**
+     * @see #setTrustManagers(TrustManagersParameters)
+     */
+    public TrustManagersParameters getTrustManagers() {
+        return trustManagers;
+    }
+
+    /**
+     * Sets the optional trust manager configuration for creating the
+     * {@link TrustManager}s used in constructing an {@link SSLContext}.
+     * 
+     * @param trustManagers the options or {@code null} to provide no
+     *            {@code TrustManager}s
+     */
+    public void setTrustManagers(TrustManagersParameters trustManagers) {
+        this.trustManagers = trustManagers;
+    }
+
+    /**
+     * @see #setSecureRandom(SecureRandomParameters)
+     */
+    public SecureRandomParameters getSecureRandom() {
+        return secureRandom;
+    }
+
+    /**
+     * Sets the optional secure random configuration options to use for 
+     * constructing the {@link SecureRandom} used in the creation of an {@link SSLContext].
+     *
+     * @param secureRandom the options or {@code null} to use the default
+     */
+    public void setSecureRandom(SecureRandomParameters secureRandom) {
+        this.secureRandom = secureRandom;
+    }
+    
+    /**
+     * @see #setClientParameters(SSLContextClientParameters)
+     */
+    public SSLContextClientParameters getClientParameters() {
+        return clientParameters;
+    }
+
+    /**
+     * The optional configuration options to be applied purely to the client side settings
+     * of the {@link SSLContext}.  Settings specified here override any duplicate settings
+     * provided at the overall level by this class.  These parameters apply to 
+     * {@link SSLSocketFactory}s and {@link SSLEngine}s produced by the the {@code SSLContext}
+     * produced from this class as well as to the {@code SSLContext} itself.
+     *
+     * @param clientParameters the optional additional client-side parameters
+     */
+    public void setClientParameters(SSLContextClientParameters clientParameters) {
+        this.clientParameters = clientParameters;
+    }
+
+    /**
+     * @see #setServerParameters(SSLContextServerParameters)
+     */
+    public SSLContextServerParameters getServerParameters() {
+        return serverParameters;
+    }
+
+    /**
+     * The optional configuration options to be applied purely to the server side settings
+     * of the {@link SSLContext}.  Settings specified here override any duplicate settings
+     * provided at the overall level by this class.  These parameters apply to 
+     * {@link SSLServerSocketFactory}s and {@link SSLEngine}s produced by the the {@code SSLContext}
+     * produced from this class as well as to the {@code SSLContext} itself.
+     *
+     * @param serverParameters the optional additional client-side parameters
+     */
+    public void setServerParameters(SSLContextServerParameters serverParameters) {
+        this.serverParameters = serverParameters;
+    }
+
+    /**
+     * @see #setProvider(String)
+     */
+    public String getProvider() {
+        return provider;
+    }
+
+    /**
+     * Sets the optional provider identifier to use when constructing an
+     * {@link SSLContext}.
+     * 
+     * @param the provider identifier (from the list of available providers
+     *            returned by {@link Security#getProviders()}) or {@code null}
+     *            to use the highest priority provider implementing the secure
+     *            socket protocol
+     *
+     * @see Security#getProviders(java.util.Map)
+     * @see #setSecureSocketProtocol(String)            
+     */
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    /**
+     * @see #setSecureSocketProtocol(String)
+     */
+    public String getSecureSocketProtocol() {
+        if (this.secureSocketProtocol == null) {
+            return DEFAULT_SECURE_SOCKET_PROTOCOL;
+        }
+        return this.secureSocketProtocol;
+    }
+
+    /**
+     * Sets the optional protocol for the secure sockets created by the
+     * {@link SSLContext} represented by this instance's configuration. Defaults
+     * to TLS. See Appendix A in the <a href=
+     * "http://download.oracle.com/javase/6/docs/technotes/guides//security/jsse/JSSERefGuide.html#AppA"
+     * >Java Secure Socket Extension Reference Guide</a> for information about
+     * standard protocol names.
+     * 
+     * @param secureSocketProtocol the name of the protocol or {@code null} to
+     *            use the default (TLS)
+     */
+    public void setSecureSocketProtocol(String secureSocketProtocol) {
+        this.secureSocketProtocol = secureSocketProtocol;
+    }
+    
+    ////////////////////////////////////////////
+    
+    /**
+     * Creates an {@link SSLContext} based on the related configuration options
+     * of this instance. Namely, {@link #keyManagers}, {@link #trustManagers}, and
+     * {@link #secureRandom}, but also respecting the chosen provider and secure
+     * socket protocol as well.
+     * 
+     * @return a newly configured instance
+     *
+     * @throws GeneralSecurityException if there is a problem in this instances
+     *             configuration or that of its nested configuration options
+     * @throws IOException if there is an error reading a key/trust store
+     */
+    public SSLContext createSSLContext() throws GeneralSecurityException, IOException {
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Creating SSLContext from SSLContextParameters: " + this);
+        }
+
+        KeyManager[] keyManagers = this.keyManagers == null ? null : this.keyManagers.createKeyManagers();
+        TrustManager[] trustManagers = this.trustManagers == null ? null : this.trustManagers.createTrustManagers();
+        SecureRandom secureRandom = this.secureRandom == null ? null : this.secureRandom.createSecureRandom();
+
+        SSLContext context = null;
+        if (this.getProvider() == null) {
+            context = SSLContext.getInstance(this.getSecureSocketProtocol());
+        } else {
+            context = SSLContext.getInstance(this.getSecureSocketProtocol(), this.getProvider());
+        }
+        
+        context.init(keyManagers, trustManagers, secureRandom);
+        
+        this.configureSSLContext(context);
+        
+        // Decorate the context.
+        context = new SSLContextDecorator(
+                new SSLContextSpiDecorator(
+                        context,
+                        this.getSSLEngineConfigurers(context),
+                        this.getSSLSocketFactoryConfigurers(context),
+                        this.getSSLServerSocketFactoryConfigurers(context)));
+        
+        return context;
+    }
+    
+    @Override
+    protected void configureSSLContext(SSLContext context) throws GeneralSecurityException {
+        LOG.debug("Configuring client and server side SSLContext parameters...");
+        super.configureSSLContext(context);
+        
+        if (this.getClientParameters() != null) {
+            LOG.debug("Overriding client-side SSLContext parameters with configured client parameters.");
+            this.getClientParameters().configureSSLContext(context);
+        }
+
+        if (this.getServerParameters() != null) {
+            LOG.debug("Overriding server-side SSLContext parameters with configured server parameters.");
+            this.getServerParameters().configureSSLContext(context);
+        }        
+        
+        LOG.debug("Configured client and server side SSLContext parameters.");
+    }
+    
+    @Override
+    protected List<Configurer<SSLEngine>> getSSLEngineConfigurers(SSLContext context) {
+        
+        LOG.debug("Collecting client and server side SSLEngine configurers...");
+        List<Configurer<SSLEngine>> configurers = super.getSSLEngineConfigurers(context);
+        
+        if (this.getClientParameters() != null) {
+            LOG.debug("Augmenting SSLEngine configurers with configurers from client parameters.");
+            configurers.addAll(this.getClientParameters().getSSLEngineConfigurers(context));
+        }
+        
+        if (this.getServerParameters() != null) {
+            LOG.debug("Augmenting SSLEngine configurers with configurers from server parameters.");
+            configurers.addAll(this.getServerParameters().getSSLEngineConfigurers(context));
+        }
+        
+        LOG.debug("Collected client and server side SSLEngine configurers.");
+        
+        return configurers;
+    }
+    
+    @Override
+    protected List<Configurer<SSLSocketFactory>> getSSLSocketFactoryConfigurers(SSLContext context) {
+        LOG.debug("Collecting SSLSocketFactory configurers...");
+        List<Configurer<SSLSocketFactory>> configurers = super.getSSLSocketFactoryConfigurers(context);
+        
+        if (this.getClientParameters() != null) {
+            LOG.debug("Augmenting SSLSocketFactory configurers with configurers from client parameters.");
+            configurers.addAll(this.getClientParameters().getSSLSocketFactoryConfigurers(context));
+        }
+        
+        LOG.debug("Collected SSLSocketFactory configurers.");
+        
+        return configurers;
+    }
+
+    @Override
+    protected List<Configurer<SSLServerSocketFactory>> getSSLServerSocketFactoryConfigurers(SSLContext context) {
+        LOG.debug("Collecting SSLServerSocketFactory configurers...");
+        List<Configurer<SSLServerSocketFactory>> configurers = super.getSSLServerSocketFactoryConfigurers(context);
+        
+        if (this.getServerParameters() != null) {
+            LOG.debug("Augmenting SSLServerSocketFactory configurers with configurers from server parameters.");
+            configurers.addAll(this.getServerParameters().getSSLServerSocketFactoryConfigurers(context));
+        }
+        
+        LOG.debug("Collected client and server side SSLServerSocketFactory configurers.");
+        
+        return configurers;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SSLContextParameters [keyManagers=");
+        builder.append(keyManagers);
+        builder.append(", trustManagers=");
+        builder.append(trustManagers);
+        builder.append(", secureRandom=");
+        builder.append(secureRandom);
+        builder.append(", clientParameters=");
+        builder.append(clientParameters);
+        builder.append(", serverParameters=");
+        builder.append(serverParameters);
+        builder.append(", provider=");
+        builder.append(provider);
+        builder.append(", secureSocketProtocol=");
+        builder.append(secureSocketProtocol);
+        builder.append(", getCipherSuites()=");
+        builder.append(getCipherSuites());
+        builder.append(", getCipherSuitesFilter()=");
+        builder.append(getCipherSuitesFilter());
+        builder.append(", getSecureSocketProtocols()=");
+        builder.append(getSecureSocketProtocols());
+        builder.append(", getSecureSocketProtocolsFilter()=");
+        builder.append(getSecureSocketProtocolsFilter());
+        builder.append(", getSessionTimeout()=");
+        builder.append(getSessionTimeout());
+        builder.append("]");
+        return builder.toString();
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,189 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.security.GeneralSecurityException;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.camel.RuntimeCamelException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLContextServerParameters extends BaseSSLContextParameters {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(SSLContextServerParameters.class);
+
+    /**
+     * The optional configuration options for server-side client-authentication
+     * requirements.
+     */
+    protected ClientAuthentication clientAuthentication;
+    
+    /**
+     * @see #setClientAuthentication(ClientAuthenticationParameters)   
+     */
+    public ClientAuthentication getClientAuthentication() {
+        return clientAuthentication;
+    }
+
+    /**
+     * Sets the configuration options for server-side client-authentication requirements.
+     * 
+     * @param value the desired configuration options or {@code null} to use the defaults
+     */
+    public void setClientAuthentication(ClientAuthentication value) {
+        this.clientAuthentication = value;
+    }
+    
+    @Override
+    protected void configureSSLContext(SSLContext context) throws GeneralSecurityException {
+        LOG.debug("Configuring server-side SSLContext parameters...");
+        if (this.getSessionTimeout() != null) {
+            LOG.debug("Configuring server-side SSLContext session timeout: " + this.getSessionTimeout());
+            this.configureSessionContext(context.getServerSessionContext(), this.getSessionTimeout());
+        }
+        LOG.debug("Configured server-side SSLContext parameters.");   
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * This implementation allows for configuration of the need and want settings
+     * for client authentication, but ignores the enabled cipher suites
+     * and protocols as they are not client and server side specific in an
+     * {@code SSLEngine}. Consequently, overriding them here would be a bit odd
+     * as the server side specific configuration shouldn't really override a
+     * shared client/server configuration option.
+     */
+    @Override
+    protected List<Configurer<SSLEngine>> getSSLEngineConfigurers(SSLContext context) {
+        // NOTE: if the super class gets additional shared configuration options beyond
+        // cipher suites and protocols, this method needs to address that.
+        // As is, we do NOT pass the configurers along for those two settings.
+        
+        List<Configurer<SSLEngine>> sslEngineConfigurers = new LinkedList<Configurer<SSLEngine>>();
+        
+        if (this.getClientAuthentication() != null) { 
+            
+            final ClientAuthentication clientAuthValue = this.getClientAuthentication();
+        
+            Configurer<SSLEngine> sslEngineConfigurer = new Configurer<SSLEngine>() {
+                
+                @Override
+                public SSLEngine configure(SSLEngine engine) {
+                
+                    switch (clientAuthValue) {
+                    case NONE:
+                        engine.setWantClientAuth(false);
+                        engine.setNeedClientAuth(false);
+                        break;
+                    case WANT:
+                        engine.setWantClientAuth(true);
+                        break;
+                    case REQUIRE:
+                        engine.setNeedClientAuth(true);
+                        break;
+                    default:
+                        throw new RuntimeCamelException("Unhandled ClientAuthentication enumeration value: " + clientAuthValue);
+                    }
+                    
+                    return engine;
+                }
+            };
+            
+            sslEngineConfigurers.add(sslEngineConfigurer);
+        }
+        
+        return sslEngineConfigurers;
+    }
+    
+    @Override
+    protected List<Configurer<SSLServerSocket>> getSSLServerSocketFactorySSLServerSocketConfigurers(SSLContext context) {
+        List<Configurer<SSLServerSocket>> sslServerSocketConfigurers = 
+            super.getSSLServerSocketFactorySSLServerSocketConfigurers(context);
+        
+
+        if (this.getClientAuthentication() != null) { 
+            
+            final ClientAuthentication clientAuthValue = this.getClientAuthentication();
+        
+            Configurer<SSLServerSocket> sslServerSocketConfigurer = new Configurer<SSLServerSocket>() {
+                
+                @Override
+                public SSLServerSocket configure(SSLServerSocket socket) {
+                    
+                    switch (clientAuthValue) {
+                    case NONE:
+                        socket.setWantClientAuth(false);
+                        socket.setNeedClientAuth(false);
+                        break;
+                    case WANT:
+                        socket.setWantClientAuth(true);
+                        break;
+                    case REQUIRE:
+                        socket.setNeedClientAuth(true);
+                        break;
+                    default:
+                        throw new RuntimeCamelException("Unhandled ClientAuthentication enumeration value: " + clientAuthValue);
+                    }
+                    
+                    return socket;
+                }
+            };
+            
+            sslServerSocketConfigurers.add(sslServerSocketConfigurer);
+        }
+        
+        
+        return sslServerSocketConfigurers;
+    }
+
+    /**
+     * This class has no bearing on {@code SSLSocketFactory} instances and therefore provides no
+     * configurers for that purpose.
+     */
+    @Override
+    protected List<Configurer<SSLSocketFactory>> getSSLSocketFactoryConfigurers(SSLContext context) {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SSLContextServerParameters [clientAuthentication=");
+        builder.append(clientAuthentication);
+        builder.append(", getCipherSuites()=");
+        builder.append(getCipherSuites());
+        builder.append(", getCipherSuitesFilter()=");
+        builder.append(getCipherSuitesFilter());
+        builder.append(", getSecureSocketProtocols()=");
+        builder.append(getSecureSocketProtocols());
+        builder.append(", getSecureSocketProtocolsFilter()=");
+        builder.append(getSecureSocketProtocolsFilter());
+        builder.append(", getSessionTimeout()=");
+        builder.append(getSessionTimeout());
+        builder.append("]");
+        return builder.toString();
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SSLContextServerParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.security.GeneralSecurityException;
+import java.security.SecureRandom;
+import java.security.Security;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SecureRandomParameters {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(SecureRandomParameters.class);
+
+    /**
+     * The Random Number Generator algorithm identifier for the
+     * {@link SecureRandom} factory method used to create the
+     * {@link SecureRandom} represented by this object's configuration. See
+     * Appendix A in the <a href=
+     * "http://download.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA"
+     * > Java Cryptography Architecture API Specification &amp; Reference</a>
+     * for information about standard RNG algorithm names.
+     */
+    protected String algorithm;
+    
+    /**
+     * The optional provider identifier for the {@link SecureRandom} factory
+     * method used to create the {@link SecureRandom} represented by this
+     * object's configuration.
+     */
+    protected String provider;
+
+    /**
+     * Returns a {@code SecureRandom} instance initialized using the configured
+     * algorithm and provider, if specified.
+     * 
+     * @return the configured instance
+     *
+     * @throws GeneralSecurityException if the algorithm is not implemented by
+     *             any registered provider or if the identified provider does
+     *             not exist.
+     */
+    public SecureRandom createSecureRandom() throws GeneralSecurityException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Creating SecureRandom from SecureRandomParameters: " + this);
+        }
+        
+        SecureRandom secureRandom = null;
+        
+        if (this.getProvider() != null) {
+            secureRandom = SecureRandom.getInstance(this.getAlgorithm(), this.getProvider());
+        } else {
+            secureRandom = SecureRandom.getInstance(this.getAlgorithm());
+        }
+
+        return secureRandom;
+    }
+    
+    /**
+     * @see #setAlgorithm(String)
+     */
+    public String getAlgorithm() {
+        return algorithm;
+    }
+
+    /**
+     * Sets the Random Number Generator (RNG) algorithm identifier for the
+     * {@link SecureRandom} factory method used to create the
+     * {@link SecureRandom} represented by this object's configuration.
+     * See Appendix A in the <a href=
+     * "http://download.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA"
+     * > Java Cryptography Architecture Reference Guide</a>
+     * for information about standard RNG algorithm names.
+     *
+     * @param value the algorithm identifier
+     */
+    public void setAlgorithm(String value) {
+        this.algorithm = value;
+    }
+
+    /**
+     * @see #setProvider(String)
+     */
+    public String getProvider() {
+        return provider;
+    }
+
+    /**
+     * Sets the optional provider identifier for the {@link SecureRandom}
+     * factory method used to create the {@link SecureRandom} represented by
+     * this object's configuration.
+     * 
+     * @param value the provider identifier or {@code null} to use the highest
+     *            priority provider implementing the desired algorithm
+     *            
+     * @see Security#getProviders()
+     */
+    public void setProvider(String value) {
+        this.provider = value;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SecureRandomParameters [algorithm=");
+        builder.append(algorithm);
+        builder.append(", provider=");
+        builder.append(provider);
+        builder.append("]");
+        return builder.toString();
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureRandomParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Represents a list of TLS/SSL cipher suite names.
+ */
+public class SecureSocketProtocolsParameters {
+
+    private List<String> secureSocketProtocol;
+
+    /**
+     * Returns a live reference to the list of secure socket protocol names.
+     *
+     * @return a reference to the list, never {@code null}
+     */
+    public List<String> getSecureSocketProtocol() {
+        if (this.secureSocketProtocol == null) {
+            this.secureSocketProtocol = new ArrayList<String>();
+        }
+        return this.secureSocketProtocol;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SecureSocketProtocolsParameters [secureSocketProtocol=");
+        builder.append(Arrays.toString(getSecureSocketProtocol().toArray(new String[getSecureSocketProtocol().size()])));
+        builder.append("]");
+        return builder.toString();
+    }
+    
+    
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/SecureSocketProtocolsParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,176 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.Security;
+
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TrustManagersParameters {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TrustManagersParameters.class);
+    
+    /**
+     * The key store configuration used to create the {@link KeyStoreParameters} that the
+     * {@link TrustManager}s produced by this object's configuration expose.
+     */
+    protected KeyStoreParameters keyStore;
+
+    /**
+     * The optional provider identifier for the {@link TrustManagerFactory} used to create
+     * the {@link TrustManager}s represented by this object's configuration.
+     */
+    protected String provider;
+
+    /**
+     * The optional algorithm name for the {@link TrustManagerFactory} used to
+     * create the {@link TrustManager}s represented by this object's
+     * configuration. See the <a href=
+     * "http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html"
+     * >Java Secure Socket Extension Reference Guide</a> for information about
+     * standard algorithm names.
+     */
+    protected String algorithm;
+    
+    /**
+     * Creates {@link TrustManager}s based on this instance's configuration and the
+     * {@code KeyStore} produced by the configuration returned from
+     * {@link #getKeyStore()}. The {@code KeyManager}s are produced from a
+     * factory created by using the provider and algorithm identifiers returned
+     * by {@link #getProvider()} and {@link #getAlgorithm()}, respectively. If
+     * either of these methods returns null, the default JSSE value is used
+     * instead.
+     * 
+     * @return the initialized {@code TrustManager}s
+     * @throws GeneralSecurityException if there is an error creating the
+     *             {@code TrustManagers}s or in creating the {@code KeyStore}
+     * @throws IOException if there is an error loading the {@code KeyStore}
+     *
+     * @see KeyStoreParameters#createKeyStore()
+     */
+    public TrustManager[] createTrustManagers() throws GeneralSecurityException, IOException {
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Creating TrustManager[] from TrustManagersParameters: " + this);
+        }
+        
+        TrustManager[] trustManagers = null;
+
+        if (this.getKeyStore() != null) {
+        
+            String tmfAlgorithm = this.getAlgorithm();
+            if (tmfAlgorithm == null) {
+                tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
+            }
+            
+            TrustManagerFactory tmf;
+            if (this.getProvider() == null) {
+                tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
+            } else {
+                tmf = TrustManagerFactory.getInstance(tmfAlgorithm, this.getProvider());
+            }
+            
+            KeyStore ks = this.getKeyStore() == null ? null : this.getKeyStore().createKeyStore();
+    
+            tmf.init(ks);
+            trustManagers = tmf.getTrustManagers();
+           
+        }
+        
+        return trustManagers;
+    }
+
+    /**
+     * @see #setKeyStore(KeyStoreParameters)
+     */
+    public KeyStoreParameters getKeyStore() {
+        return keyStore;
+    }
+
+    /**
+     * Sets the key store configuration used to create the {@link KeyStoreParameters} that the
+     * {@link TrustManager}s produced by this object's configuration expose.
+     * 
+     * @param value the configuration to use
+     */
+    public void setKeyStore(KeyStoreParameters value) {
+        this.keyStore = value;
+    }
+
+    /**
+     * @see #setProvider(String)
+     */
+    public String getProvider() {
+        return provider;
+    }
+
+    /**
+     * Sets the optional provider identifier for the {@link TrustManagerFactory}
+     * used to create the {@link TrustManager}s represented by this object's
+     * configuration.
+     * 
+     * @param value the desired provider identifier or {@code null} to use the
+     *            highest priority provider implementing the algorithm
+     *            
+     * @see Security#getProviders()
+     */
+    public void setProvider(String value) {
+        this.provider = value;
+    }
+
+    /**
+     * @see KeyManagersParametersTest#setAlgorithm(String)
+     */
+    public String getAlgorithm() {
+        return algorithm;
+    }
+
+    /**
+     * Sets optional algorithm name for the {@link TrustManagerFactory} used to create
+     * the {@link TrustManager}s represented by this object's configuration.  See the <a href=
+     * "http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html"
+     * >Java Secure Socket Extension Reference Guide</a> for information about
+     * standard algorithm names.
+     * 
+     * @param value the desired algorithm or {@code null} to use default
+     * 
+     * @see TrustManagerFactory#getDefaultAlgorithm()
+     */
+    public void setAlgorithm(String value) {
+        this.algorithm = value;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("TrustManagerType [keyStore=");
+        builder.append(keyStore);
+        builder.append(", provider=");
+        builder.append(provider);
+        builder.append(", algorithm=");
+        builder.append(algorithm);
+        builder.append("]");
+        return builder.toString();
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/TrustManagersParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html Mon Apr 25 02:52:44 2011
@@ -0,0 +1,25 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+A collection of utility classes for configuring a JSSE SSLContext and other JSSE classes.  The classes provider a builder pattern approach to the complex task of configuring low level TLS settings.
+
+</body>
+</html>

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jsse/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+public class FilterParametersTest extends TestCase {
+    public void testGetIncludePatterns() {
+        FilterParameters filter = new FilterParameters();
+        filter.getInclude().add("asdfsadfsadfsadf");
+        
+        List<Pattern> includes = filter.getIncludePatterns();
+        List<Pattern> excludes = filter.getExcludePatterns();
+        
+        assertNotNull(includes);
+        assertEquals(1, includes.size());
+        
+        assertNotNull(excludes);
+        assertEquals(0, excludes.size());
+        
+        assertNotNull(includes.get(0));
+        
+        Matcher matcher = includes.get(0).matcher("asdfsadfsadfsadf");
+        assertTrue(matcher.matches());
+    }
+    
+    public void testGetExcludePatterns() {
+        FilterParameters filter = new FilterParameters();
+        filter.getExclude().add("asdfsadfsadfsadf");
+        
+        List<Pattern> includes = filter.getIncludePatterns();
+        List<Pattern> excludes = filter.getExcludePatterns();
+        
+        assertNotNull(excludes);
+        assertEquals(1, excludes.size());
+        
+        assertNotNull(includes);
+        assertEquals(0, includes.size());
+        
+        assertNotNull(excludes.get(0));
+        
+        Matcher matcher = excludes.get(0).matcher("asdfsadfsadfsadf");
+        assertTrue(matcher.matches());
+    }
+    
+    public void test() {
+        FilterParameters filter = new FilterParameters();
+        filter.getInclude().add("asdfsadfsadfsadf");
+        filter.getExclude().add("aa");
+        
+        FilterParameters.Patterns patterns = filter.getPatterns();
+        
+        List<Pattern> includes = patterns.getIncludes();
+        List<Pattern> excludes = patterns.getExcludes();
+        
+        assertNotNull(includes);
+        assertNotNull(excludes);
+        
+        assertEquals(1, includes.size());
+        assertEquals(1, excludes.size());
+        
+        Matcher includeMatcher = includes.get(0).matcher("asdfsadfsadfsadf");
+        assertTrue(includeMatcher.matches());
+        
+        Matcher excludeMatcher = excludes.get(0).matcher("aa");
+        assertTrue(excludeMatcher.matches());
+        
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/FilterParametersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.UnrecoverableKeyException;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.X509KeyManager;
+
+import junit.framework.TestCase;
+
+public class KeyManagersParametersTest extends TestCase {
+    
+    protected KeyStoreParameters createMinimalKeyStoreParameters() {
+        KeyStoreParameters ksp = new KeyStoreParameters();
+        
+        ksp.setResource("org/apache/camel/util/jsse/localhost.ks");
+        ksp.setPassword("changeit");
+        
+        return ksp;
+    }
+    
+    protected KeyManagersParameters createMinimalKeyManagersParameters() {
+        KeyManagersParameters kmp = new KeyManagersParameters();
+        kmp.setKeyStore(this.createMinimalKeyStoreParameters());
+        kmp.setKeyPassword("changeit");
+        
+        return kmp;
+    }
+    
+    public void testCreateKeyManagers() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        
+        KeyManager[] kms = kmp.createKeyManagers();
+        validateKeyManagers(kms);
+    }
+    
+    public void testExplicitAlgorithm() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        kmp.setAlgorithm(KeyManagerFactory.getDefaultAlgorithm());
+        
+        KeyManager[] kms = kmp.createKeyManagers();
+        validateKeyManagers(kms);
+    }
+    
+    public void testExplicitProvider() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        kmp.setProvider(KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
+                        .getProvider().getName());
+        
+        KeyManager[] kms = kmp.createKeyManagers();
+        validateKeyManagers(kms);
+    }
+    
+    public void testInvalidPassword() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        kmp.setKeyPassword("");
+        
+        try {
+            kmp.createKeyManagers();
+            fail();
+        } catch (UnrecoverableKeyException e) {
+            // expected
+        }
+    }
+    
+    public void testInvalidExplicitAlgorithm() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        kmp.setAlgorithm("dsfsdfsdfdsfdsF");
+        
+        try {
+            kmp.createKeyManagers();
+            fail();
+        } catch (NoSuchAlgorithmException e) {
+            // expected
+        }
+    }
+    
+    public void testInvalidExplicitProvider() throws Exception {
+        KeyManagersParameters kmp = this.createMinimalKeyManagersParameters();
+        kmp.setProvider("dsfsdfsdfdsfdsF");
+        
+        try {
+            kmp.createKeyManagers();
+            fail();
+        } catch (NoSuchProviderException e) {
+            // expected
+        }
+    }
+
+    protected void validateKeyManagers(KeyManager[] kms) {
+        assertEquals(1, kms.length);
+        assertTrue(kms[0] instanceof X509KeyManager);
+        X509KeyManager km = (X509KeyManager) kms[0];
+        assertNotNull(km.getPrivateKey("server"));
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyManagersParametersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java?rev=1096398&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java Mon Apr 25 02:52:44 2011
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.jsse;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.NoSuchProviderException;
+
+import org.apache.camel.TestSupport;
+
+public class KeyStoreParametersTest extends TestSupport {
+    
+    protected KeyStoreParameters createMinimalKeyStoreParameters() {
+        KeyStoreParameters ksp = new KeyStoreParameters();
+        
+        ksp.setResource("org/apache/camel/util/jsse/localhost.ks");
+        ksp.setPassword("changeit");
+        
+        return ksp;
+    }
+    
+    public void testValidParameters() throws GeneralSecurityException, IOException, URISyntaxException {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        
+        KeyStore ks = ksp.createKeyStore();
+        assertNotNull(ks.getCertificate("server"));
+        
+        
+        URL resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
+        ksp.setResource(resourceUrl.toExternalForm());
+        ks = ksp.createKeyStore();
+        assertNotNull(ks.getCertificate("server"));
+        
+        
+        resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
+        File file = new File(resourceUrl.toURI());
+        ksp.setResource(file.getAbsolutePath());
+        ks = ksp.createKeyStore();
+        assertNotNull(ks.getCertificate("server"));
+    }
+    
+    public void testExplicitType() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setType("jks");
+        
+        KeyStore ks = ksp.createKeyStore();
+        assertNotNull(ks.getCertificate("server"));
+    }
+    
+    public void testExplicitProvider() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setProvider(ksp.createKeyStore().getProvider().getName());
+        
+        KeyStore ks = ksp.createKeyStore();
+        assertNotNull(ks.getCertificate("server"));
+    }
+    
+    public void testExplicitInvalidProvider() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setProvider("sdfdsfgfdsgdsfg");
+        
+        try {
+            ksp.createKeyStore();
+            fail();
+        } catch (NoSuchProviderException e) {
+            // expected
+        }
+    }
+    
+    public void testExplicitInvalidType() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setType("pkcs12");
+        
+        try {
+            ksp.createKeyStore();
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+    }
+    
+    public void testIncorrectPassword() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setPassword("");
+        
+        try {
+            ksp.createKeyStore();
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+    }
+    
+    public void testIncorrectResource() throws Exception {
+        KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
+        ksp.setResource("");
+        
+        try {
+            ksp.createKeyStore();
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/jsse/KeyStoreParametersTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message