You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ni...@apache.org on 2005/11/29 16:22:11 UTC
svn commit: r349728 - in /directory/network/trunk: ./
src/java/org/apache/mina/integration/spring/ssl/
src/test/org/apache/mina/integration/spring/ssl/
Author: niklas
Date: Tue Nov 29 07:21:54 2005
New Revision: 349728
URL: http://svn.apache.org/viewcvs?rev=349728&view=rev
Log:
Added Spring factory beans for configuration of SSLContext instances using Spring
Added:
directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/
directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java (with props)
directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java (with props)
directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java (with props)
directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/
directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java (with props)
directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/keystore.cert (with props)
Modified:
directory/network/trunk/project.xml
Modified: directory/network/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/trunk/project.xml?rev=349728&r1=349727&r2=349728&view=diff
==============================================================================
--- directory/network/trunk/project.xml (original)
+++ directory/network/trunk/project.xml Tue Nov 29 07:21:54 2005
@@ -210,6 +210,15 @@
<exclude>**/DatagramBindTest*</exclude>
<exclude>**/*RegressionTest*</exclude>
</excludes>
+
+ <resources>
+ <resource>
+ <directory>${basedir}/src/test</directory>
+ <includes>
+ <include>**/*.cert</include>
+ </includes>
+ </resource>
+ </resources>
</unitTest>
<resources>
Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java?rev=349728&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java Tue Nov 29 07:21:54 2005
@@ -0,0 +1,91 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.mina.integration.spring.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.Provider;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.TrustManagerFactorySpi;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ * Bogus {@link javax.net.ssl.TrustManagerFactory} which creates
+ * {@link javax.net.ssl.X509TrustManager} trusting everything.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev: 326586 $, $Date: 2005-10-19 17:50:29 +0200 (ons, 19 okt 2005) $
+ */
+public class BogusTrustManagerFactory extends TrustManagerFactory
+{
+
+ public BogusTrustManagerFactory()
+ {
+ super( new BogusTrustManagerFactorySpi(),
+ new Provider("MinaBogus", 1.0, "") {}, "MinaBogus" );
+ }
+
+ private static final X509TrustManager X509 = new X509TrustManager()
+ {
+ public void checkClientTrusted( X509Certificate[] x509Certificates,
+ String s ) throws CertificateException
+ {
+ }
+
+ public void checkServerTrusted( X509Certificate[] x509Certificates,
+ String s ) throws CertificateException
+ {
+ }
+
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ return new X509Certificate[ 0 ];
+ }
+ };
+
+ private static final TrustManager[] X509_MANAGERS = new TrustManager[] { X509 };
+
+ private static class BogusTrustManagerFactorySpi extends TrustManagerFactorySpi
+ {
+
+ protected TrustManager[] engineGetTrustManagers()
+ {
+ return X509_MANAGERS;
+ }
+
+ protected void engineInit( KeyStore keystore ) throws KeyStoreException
+ {
+ // noop
+ }
+
+ protected void engineInit(
+ ManagerFactoryParameters managerFactoryParameters )
+ throws InvalidAlgorithmParameterException
+ {
+ // noop
+ }
+
+ }
+}
Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/BogusTrustManagerFactory.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java?rev=349728&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java Tue Nov 29 07:21:54 2005
@@ -0,0 +1,170 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.mina.integration.spring.ssl;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+
+/**
+ * Spring {@link org.springframework.beans.factory.FactoryBean} implementation
+ * which makes it possible to configure {@link java.security.KeyStore} instances
+ * using Spring.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class KeyStoreFactoryBean extends AbstractFactoryBean
+{
+ private String type = "JKS";
+ private String provider = null;
+ private char[] password = null;
+ private File file = null;
+ private Resource resource = null;
+
+ /**
+ * Creates a new {@link KeyStore}. This method will be called
+ * by the base class when Spring creates a bean using this FactoryBean.
+ *
+ * @return the {@link KeyStore} instance.
+ */
+ protected Object createInstance() throws Exception
+ {
+ if( file == null && resource == null )
+ {
+ throw new IllegalArgumentException( "Required property missing. " +
+ "Either 'file' or 'resource' have to be specified" );
+ }
+
+ KeyStore ks = null;
+ if( provider == null )
+ {
+ ks = KeyStore.getInstance( type );
+ }
+ else
+ {
+ ks = KeyStore.getInstance( type, provider );
+ }
+
+ InputStream is = null;
+ if( file != null )
+ {
+ is = new BufferedInputStream( new FileInputStream( file ) );
+ }
+ else
+ {
+ is = resource.getInputStream();
+ }
+
+ try
+ {
+ ks.load( is, password );
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch( IOException ignored )
+ {
+ }
+ }
+
+ return ks;
+ }
+
+ public Class getObjectType()
+ {
+ return KeyStore.class;
+ }
+
+ /**
+ * Sets the file which contains the key store. Either this
+ * property or {@link #setProvider(String)} have to be set.
+ *
+ * @param file the file to load the key store from.
+ */
+ public void setFile( File file )
+ {
+ this.file = file;
+ }
+
+ /**
+ * Sets the key store password. If this value is <code>null</code> no
+ * password will be used to check the integrity of the key store.
+ *
+ * @param password the password or <code>null</code> if no password is
+ * needed.
+ */
+ public void setPassword( String password )
+ {
+ if( password != null )
+ {
+ this.password = password.toCharArray();
+ }
+ else
+ {
+ this.password = null;
+ }
+ }
+
+ /**
+ * Sets the name of the provider to use when creating the key store. The
+ * default is to use the platform default provider.
+ *
+ * @param provider the name of the provider, e.g. SUN.
+ */
+ public void setProvider( String provider )
+ {
+ this.provider = provider;
+ }
+
+ /**
+ * Sets a Spring {@link Resource} which contains the key store. Either this
+ * property or {@link #setFile(File)} have to be set.
+ *
+ * @param resource the resource to load the key store from.
+ */
+ public void setResource( Resource resource )
+ {
+ this.resource = resource;
+ }
+
+ /**
+ * Sets the type of key store to create. The default is to create a
+ * JKS key store.
+ *
+ * @param type the type to use when creating the key store.
+ * @throws IllegalArgumentException if the specified value is
+ * <code>null</code>.
+ */
+ public void setType( String type )
+ {
+ Assert.notNull( type, "Property 'type' may not be null" );
+ this.type = type;
+ }
+}
Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java?rev=349728&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java Tue Nov 29 07:21:54 2005
@@ -0,0 +1,370 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.mina.integration.spring.ssl;
+
+import java.security.KeyStore;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.util.Assert;
+
+/**
+ * Spring {@link org.springframework.beans.factory.FactoryBean} implementation
+ * which makes it possible to configure {@link javax.net.ssl.SSLContext}
+ * instances using Spring.
+ * <p>
+ * If no properties are set the returned {@link javax.net.ssl.SSLContext} will
+ * be equivalent to what the following creates:
+ * <pre>
+ * SSLContext c = SSLContext.getInstance( "TLS" );
+ * c.init( null, null, null );
+ * </pre>
+ * </p>
+ * <p>
+ * Use the properties prefixed with <code>keyManagerFactory</code> to control
+ * the creation of the {@link javax.net.ssl.KeyManager} to be used.
+ * </p>
+ * <p>
+ * Use the properties prefixed with <code>trustManagerFactory</code> to control
+ * the creation of the {@link javax.net.ssl.TrustManagerFactory} to be used.
+ * </p>
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SSLContextFactoryBean extends AbstractFactoryBean
+{
+ private String protocol = "TLS";
+ private String provider = null;
+ private SecureRandom secureRandom = null;
+
+ private KeyStore keyManagerFactoryKeyStore = null;
+ private char[] keyManagerFactoryKeyStorePassword = null;
+ private KeyManagerFactory keyManagerFactory = null;
+ private String keyManagerFactoryAlgorithm = null;
+ private String keyManagerFactoryProvider = null;
+ private boolean keyManagerFactoryAlgorithmUseDefault = false;
+
+ private KeyStore trustManagerFactoryKeyStore = null;
+ private TrustManagerFactory trustManagerFactory = null;
+ private String trustManagerFactoryAlgorithm = null;
+ private String trustManagerFactoryProvider = null;
+ private boolean trustManagerFactoryAlgorithmUseDefault = false;
+
+ protected Object createInstance() throws Exception
+ {
+ KeyManagerFactory kmf = this.keyManagerFactory;
+ TrustManagerFactory tmf = this.trustManagerFactory;
+
+ if( kmf == null )
+ {
+ String algorithm = keyManagerFactoryAlgorithm;
+ if( algorithm == null && keyManagerFactoryAlgorithmUseDefault )
+ {
+ algorithm = KeyManagerFactory.getDefaultAlgorithm();
+ }
+ if( algorithm != null )
+ {
+ if( keyManagerFactoryProvider == null )
+ {
+ kmf = KeyManagerFactory.getInstance( algorithm );
+ }
+ else
+ {
+ kmf = KeyManagerFactory.getInstance( algorithm,
+ keyManagerFactoryProvider );
+ }
+ }
+ }
+
+ if( tmf == null )
+ {
+ String algorithm = trustManagerFactoryAlgorithm;
+ if( algorithm == null && trustManagerFactoryAlgorithmUseDefault )
+ {
+ algorithm = TrustManagerFactory.getDefaultAlgorithm();
+ }
+ if( algorithm != null )
+ {
+ if( trustManagerFactoryProvider == null )
+ {
+ tmf = TrustManagerFactory.getInstance( algorithm );
+ }
+ else
+ {
+ tmf = TrustManagerFactory.getInstance( algorithm,
+ trustManagerFactoryProvider );
+ }
+ }
+ }
+
+ KeyManager[] keyManagers = null;
+ if( kmf != null )
+ {
+ kmf.init( keyManagerFactoryKeyStore,
+ keyManagerFactoryKeyStorePassword );
+ keyManagers = kmf.getKeyManagers();
+ }
+ TrustManager[] trustManagers = null;
+ if( tmf != null )
+ {
+ tmf.init( trustManagerFactoryKeyStore );
+ trustManagers = tmf.getTrustManagers();
+ }
+
+ SSLContext context = null;
+ if( provider == null )
+ {
+ context = SSLContext.getInstance( protocol );
+ }
+ else
+ {
+ context = SSLContext.getInstance( protocol, provider );
+ }
+
+ context.init( keyManagers, trustManagers, secureRandom );
+
+ return context;
+ }
+
+ public Class getObjectType()
+ {
+ return SSLContext.class;
+ }
+
+ /**
+ * Sets the protocol to use when creating the {@link SSLContext}. The
+ * default is <code>TLS</code>.
+ *
+ * @param protocol the name of the protocol.
+ * @throws IllegalArgumentException if the specified value is
+ * <code>null</code>.
+ */
+ public void setProtocol( String protocol )
+ {
+ Assert.notNull( protocol, "Property 'protocol' may not be null" );
+ this.protocol = protocol;
+ }
+
+ /**
+ * If this is set to <code>true</code> while no {@link KeyManagerFactory}
+ * has been set using {@link #setKeyManagerFactory(KeyManagerFactory)} and
+ * no algorithm has been set using
+ * {@link #setKeyManagerFactoryAlgorithm(String)} the default algorithm
+ * return by {@link KeyManagerFactory#getDefaultAlgorithm()} will be used.
+ *
+ * @param useDefault <code>true</code> or <code>false</code>.
+ */
+ public void setKeyManagerFactoryAlgorithmUseDefault( boolean useDefault )
+ {
+ this.keyManagerFactoryAlgorithmUseDefault = useDefault;
+ }
+
+ /**
+ * If this is set to <code>true</code> while no {@link TrustManagerFactory}
+ * has been set using {@link #setTrustManagerFactory(TrustManagerFactory)} and
+ * no algorithm has been set using
+ * {@link #setTrustManagerFactoryAlgorithm(String)} the default algorithm
+ * return by {@link TrustManagerFactory#getDefaultAlgorithm()} will be used.
+ *
+ * @param useDefault <code>true</code> or <code>false</code>.
+ */
+ public void setTrustManagerFactoryAlgorithmUseDefault( boolean useDefault )
+ {
+ this.trustManagerFactoryAlgorithmUseDefault = useDefault;
+ }
+
+ /**
+ * Sets the {@link KeyManagerFactory} to use. If this is set the properties
+ * which are used by this factory bean to create a {@link KeyManagerFactory}
+ * will all be ignored.
+ *
+ * @param factory the factory.
+ */
+ public void setKeyManagerFactory( KeyManagerFactory factory )
+ {
+ this.keyManagerFactory = factory;
+ }
+
+ /**
+ * Sets the algorithm to use when creating the {@link KeyManagerFactory}
+ * using {@link KeyManagerFactory#getInstance(java.lang.String)} or
+ * {@link KeyManagerFactory#getInstance(java.lang.String, java.lang.String)}.
+ * <p>
+ * This property will be ignored if a {@link KeyManagerFactory} has been
+ * set directly using {@link #setKeyManagerFactory(KeyManagerFactory)}.
+ * </p>
+ * <p>
+ * If this property isn't set while no {@link KeyManagerFactory} has been
+ * set using {@link #setKeyManagerFactory(KeyManagerFactory)} and
+ * {@link #setKeyManagerFactoryAlgorithmUseDefault(boolean)} has been set to
+ * <code>true</code> the value returned
+ * by {@link KeyManagerFactory#getDefaultAlgorithm()} will be used instead.
+ * </p>
+ *
+ * @param algorithm the algorithm to use.
+ */
+ public void setKeyManagerFactoryAlgorithm( String algorithm )
+ {
+ this.keyManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * Sets the provider to use when creating the {@link KeyManagerFactory}
+ * using
+ * {@link KeyManagerFactory#getInstance(java.lang.String, java.lang.String)}.
+ * <p>
+ * This property will be ignored if a {@link KeyManagerFactory} has been
+ * set directly using {@link #setKeyManagerFactory(KeyManagerFactory)}.
+ * </p>
+ * <p>
+ * If this property isn't set and no {@link KeyManagerFactory} has been set
+ * using {@link #setKeyManagerFactory(KeyManagerFactory)}
+ * {@link KeyManagerFactory#getInstance(java.lang.String)} will be used
+ * to create the {@link KeyManagerFactory}.
+ * </p>
+ *
+ * @param provider the name of the provider.
+ */
+ public void setKeyManagerFactoryProvider( String provider )
+ {
+ this.keyManagerFactoryProvider = provider;
+ }
+
+ /**
+ * Sets the {@link KeyStore} which will be used in the call to
+ * {@link KeyManagerFactory#init(java.security.KeyStore, char[])} when
+ * the {@link SSLContext} is created.
+ *
+ * @param keyStore the key store.
+ */
+ public void setKeyManagerFactoryKeyStore( KeyStore keyStore )
+ {
+ this.keyManagerFactoryKeyStore = keyStore;
+ }
+
+ /**
+ * Sets the password which will be used in the call to
+ * {@link KeyManagerFactory#init(java.security.KeyStore, char[])} when
+ * the {@link SSLContext} is created.
+ *
+ * @param password the password. Use <code>null</code> to disable password.
+ */
+ public void setKeyManagerFactoryKeyStorePassword( String password )
+ {
+ if( password != null )
+ {
+ this.keyManagerFactoryKeyStorePassword = password.toCharArray();
+ }
+ else
+ {
+ this.keyManagerFactoryKeyStorePassword = null;
+ }
+ }
+
+ /**
+ * Sets the {@link TrustManagerFactory} to use. If this is set the properties
+ * which are used by this factory bean to create a {@link TrustManagerFactory}
+ * will all be ignored.
+ *
+ * @param factory the factory.
+ */
+ public void setTrustManagerFactory( TrustManagerFactory factory )
+ {
+ this.trustManagerFactory = factory;
+ }
+
+ /**
+ * Sets the algorithm to use when creating the {@link TrustManagerFactory}
+ * using {@link TrustManagerFactory#getInstance(java.lang.String)} or
+ * {@link TrustManagerFactory#getInstance(java.lang.String, java.lang.String)}.
+ * <p>
+ * This property will be ignored if a {@link TrustManagerFactory} has been
+ * set directly using {@link #setTrustManagerFactory(TrustManagerFactory)}.
+ * </p>
+ * <p>
+ * If this property isn't set while no {@link TrustManagerFactory} has been
+ * set using {@link #setTrustManagerFactory(TrustManagerFactory)} and
+ * {@link #setTrustManagerFactoryAlgorithmUseDefault(boolean)} has been set to
+ * <code>true</code> the value returned
+ * by {@link TrustManagerFactory#getDefaultAlgorithm()} will be used instead.
+ * </p>
+ *
+ * @param algorithm the algorithm to use.
+ */
+ public void setTrustManagerFactoryAlgorithm( String algorithm )
+ {
+ this.trustManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * Sets the {@link KeyStore} which will be used in the call to
+ * {@link TrustManagerFactory#init(java.security.KeyStore)} when
+ * the {@link SSLContext} is created.
+ *
+ * @param keyStore the key store.
+ */
+ public void setTrustManagerFactoryKeyStore( KeyStore keyStore )
+ {
+ this.trustManagerFactoryKeyStore = keyStore;
+ }
+
+ /**
+ * Sets the provider to use when creating the {@link TrustManagerFactory}
+ * using
+ * {@link TrustManagerFactory#getInstance(java.lang.String, java.lang.String)}.
+ * <p>
+ * This property will be ignored if a {@link TrustManagerFactory} has been
+ * set directly using {@link #setTrustManagerFactory(TrustManagerFactory)}.
+ * </p>
+ * <p>
+ * If this property isn't set and no {@link TrustManagerFactory} has been set
+ * using {@link #setTrustManagerFactory(TrustManagerFactory)}
+ * {@link TrustManagerFactory#getInstance(java.lang.String)} will be used
+ * to create the {@link TrustManagerFactory}.
+ * </p>
+ *
+ * @param provider the name of the provider.
+ */
+ public void setTrustManagerFactoryProvider( String provider )
+ {
+ this.trustManagerFactoryProvider = provider;
+ }
+
+ /**
+ * Sets the {@link SecureRandom} to use when initializing the
+ * {@link SSLContext}. The JVM's default will be used if this isn't set.
+ *
+ * @param secureRandom the {@link SecureRandom} or <code>null</code> if the
+ * JVM's default should be used.
+ * @see SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)
+ */
+ public void setSecureRandom( SecureRandom secureRandom )
+ {
+ this.secureRandom = secureRandom;
+ }
+
+
+}
Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/ssl/SSLContextFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java?rev=349728&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java Tue Nov 29 07:21:54 2005
@@ -0,0 +1,78 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.mina.integration.spring.ssl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.KeyStore;
+
+import junit.framework.TestCase;
+
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.ssl.KeyStoreFactoryBean}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class KeyStoreFactoryBeanTest extends TestCase
+{
+ public void testCreateInstanceFromResource() throws Exception
+ {
+ // Test using default for now.
+ KeyStoreFactoryBean factory = new KeyStoreFactoryBean();
+ factory.setResource( new ClassPathResource( "keystore.cert", getClass() ) );
+ factory.setPassword( "boguspw" );
+
+ KeyStore ks = ( KeyStore ) factory.createInstance();
+
+ ks.getCertificate( "bogus" );
+ ks.getKey( "bogus", "boguspw".toCharArray() );
+ }
+
+ public void testCreateInstanceFromFile() throws Exception
+ {
+ // Copy the keystore from the class path to a temporary file.
+ File file = File.createTempFile( "keystoretest ", null );
+ file.deleteOnExit();
+ InputStream in = getClass().getResourceAsStream( "keystore.cert" );
+ OutputStream out = new FileOutputStream(file);
+ int b;
+ while( ( b = in.read() ) != -1 )
+ {
+ out.write( b );
+ }
+ in.close();
+ out.close();
+
+ // Test using default for now.
+ KeyStoreFactoryBean factory = new KeyStoreFactoryBean();
+ factory.setFile( file );
+ factory.setPassword( "boguspw" );
+
+ KeyStore ks = ( KeyStore ) factory.createInstance();
+
+ ks.getCertificate( "bogus" );
+ ks.getKey( "bogus", "boguspw".toCharArray() );
+ }
+
+}
Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/KeyStoreFactoryBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/keystore.cert
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/keystore.cert?rev=349728&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/ssl/keystore.cert
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream