39
39
import javax .net .ssl .TrustManager ;
40
40
import javax .net .ssl .TrustManagerFactory ;
41
41
42
- import org .apache .commons .logging .Log ;
43
- import org .apache .commons .logging .LogFactory ;
44
-
45
42
import org .springframework .amqp .rabbit .support .RabbitExceptionTranslator ;
46
43
import org .springframework .beans .factory .config .AbstractFactoryBean ;
47
44
import org .springframework .core .io .Resource ;
57
54
import com .rabbitmq .client .impl .nio .NioParams ;
58
55
59
56
/**
60
- * Factory bean to create a RabbitMQ ConnectionFactory, delegating most
61
- * setter methods and optionally enabling SSL, with or without
62
- * certificate validation. When {@link #setSslPropertiesLocation(Resource) sslPropertiesLocation}
63
- * is not null, the default implementation loads a {@code PKCS12} keystore and a
64
- * {@code JKS} truststore using the supplied properties and intializes {@code SunX509} key
65
- * and trust manager factories. These are then used to initialize an {@link SSLContext}
66
- * using the {@link #setSslAlgorithm(String) sslAlgorithm} (default TLSv1.1).
57
+ * Factory bean to create a RabbitMQ ConnectionFactory, delegating most setter methods and
58
+ * optionally enabling SSL, with or without certificate validation. When
59
+ * {@link #setSslPropertiesLocation(Resource) sslPropertiesLocation} is not null, the
60
+ * default implementation loads a {@code PKCS12} keystore and a {@code JKS} truststore
61
+ * using the supplied properties and intializes key and trust manager factories, using
62
+ * algorithm {@code SunX509} by default. These are then used to initialize an
63
+ * {@link SSLContext} using the {@link #setSslAlgorithm(String) sslAlgorithm} (default
64
+ * TLSv1.1).
67
65
* <p>
68
- * Override {@link #createSSLContext()} to create and/or perform further modification of the context.
66
+ * Override {@link #createSSLContext()} to create and/or perform further modification of
67
+ * the context.
69
68
* <p>
70
69
* Override {@link #setUpSSL()} to take complete control over setting up SSL.
71
70
*
80
79
*/
81
80
public class RabbitConnectionFactoryBean extends AbstractFactoryBean <ConnectionFactory > {
82
81
83
- private final Log logger = LogFactory . getLog ( getClass ()) ;
82
+ private static final String SUN_X509 = "SunX509" ;
84
83
85
84
private static final String KEY_STORE = "keyStore" ;
86
85
@@ -136,6 +135,10 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
136
135
137
136
private boolean enableHostnameVerification = true ;
138
137
138
+ private String keyStoreAlgorithm = SUN_X509 ;
139
+
140
+ private String trustStoreAlgorithm = SUN_X509 ;
141
+
139
142
public RabbitConnectionFactoryBean () {
140
143
this .connectionFactory .setAutomaticRecoveryEnabled (false );
141
144
}
@@ -629,6 +632,32 @@ public void setEnableHostnameVerification(boolean enable) {
629
632
this .enableHostnameVerification = enable ;
630
633
}
631
634
635
+ protected String getKeyStoreAlgorithm () {
636
+ return this .keyStoreAlgorithm ;
637
+ }
638
+
639
+ /**
640
+ * Set the algorithm used when creating the key store, default {@code SunX509}.
641
+ * @param keyStoreAlgorithm the algorithm.
642
+ * @since 2.1.6
643
+ */
644
+ public void setKeyStoreAlgorithm (String keyStoreAlgorithm ) {
645
+ this .keyStoreAlgorithm = keyStoreAlgorithm ;
646
+ }
647
+
648
+ protected String getTrustStoreAlgorithm () {
649
+ return this .trustStoreAlgorithm ;
650
+ }
651
+
652
+ /**
653
+ * Set the algorithm used when creating the trust store, default {@code SunX509}.
654
+ * @param trustStoreAlgorithm the algorithm.
655
+ * @since 2.1.6
656
+ */
657
+ public void setTrustStoreAlgorithm (String trustStoreAlgorithm ) {
658
+ this .trustStoreAlgorithm = trustStoreAlgorithm ;
659
+ }
660
+
632
661
@ Override
633
662
public void afterPropertiesSet () {
634
663
try {
@@ -703,7 +732,7 @@ private void setupBasicSSL() throws NoSuchAlgorithmException, KeyManagementExcep
703
732
}
704
733
705
734
@ Nullable
706
- private KeyManager [] configureKeyManagers () throws KeyStoreException , IOException , NoSuchAlgorithmException ,
735
+ protected KeyManager [] configureKeyManagers () throws KeyStoreException , IOException , NoSuchAlgorithmException ,
707
736
CertificateException , UnrecoverableKeyException {
708
737
String keyStoreName = getKeyStore ();
709
738
String keyStorePassword = getKeyStorePassphrase ();
@@ -718,15 +747,15 @@ private KeyManager[] configureKeyManagers() throws KeyStoreException, IOExceptio
718
747
: this .resolver .getResource (keyStoreName );
719
748
KeyStore ks = KeyStore .getInstance (storeType );
720
749
ks .load (resource .getInputStream (), keyPassphrase );
721
- KeyManagerFactory kmf = KeyManagerFactory .getInstance ("SunX509" );
750
+ KeyManagerFactory kmf = KeyManagerFactory .getInstance (this . keyStoreAlgorithm );
722
751
kmf .init (ks , keyPassphrase );
723
752
keyManagers = kmf .getKeyManagers ();
724
753
}
725
754
return keyManagers ;
726
755
}
727
756
728
757
@ Nullable
729
- private TrustManager [] configureTrustManagers ()
758
+ protected TrustManager [] configureTrustManagers ()
730
759
throws KeyStoreException , IOException , NoSuchAlgorithmException , CertificateException {
731
760
String trustStoreName = getTrustStore ();
732
761
String trustStorePassword = getTrustStorePassphrase ();
@@ -741,7 +770,7 @@ private TrustManager[] configureTrustManagers()
741
770
: this .resolver .getResource (trustStoreName );
742
771
KeyStore tks = KeyStore .getInstance (storeType );
743
772
tks .load (resource .getInputStream (), trustPassphrase );
744
- TrustManagerFactory tmf = TrustManagerFactory .getInstance ("SunX509" );
773
+ TrustManagerFactory tmf = TrustManagerFactory .getInstance (this . trustStoreAlgorithm );
745
774
tmf .init (tks );
746
775
trustManagers = tmf .getTrustManagers ();
747
776
}
0 commit comments