|
1 | 1 | package io.smallrye.reactive.messaging.mqtt; |
2 | 2 |
|
| 3 | +import java.util.Optional; |
3 | 4 | import java.util.concurrent.TimeUnit; |
4 | 5 |
|
5 | 6 | import io.vertx.core.net.JksOptions; |
@@ -46,17 +47,18 @@ static MqttClientOptions createMqttClientOptions(MqttConnectorCommonConfiguratio |
46 | 47 | * Description: Set whether keystore type, location and password. In case of pem type the location and password are the cert |
47 | 48 | * and key path. |
48 | 49 | * Default Value: PfxOptions |
49 | | - * |
| 50 | + * |
50 | 51 | * @return the KeyCertOptions |
51 | 52 | */ |
52 | 53 | private static KeyCertOptions getKeyCertOptions(MqttConnectorCommonConfiguration config) { |
53 | | - |
54 | | - if (config.getSsl() && config.getSslKeystoreLocation().isPresent()) { |
55 | | - String keyStoreLocation = config.getSslKeystoreLocation().get(); |
| 54 | + Optional<String> sslKeystoreLocation = config.getSslKeystoreLocation(); |
| 55 | + Optional<String> sslKeystorePassword = config.getSslKeystorePassword(); |
| 56 | + if (config.getSsl() && sslKeystoreLocation.isPresent()) { |
| 57 | + String keyStoreLocation = sslKeystoreLocation.get(); |
56 | 58 | String sslKeystoreType = config.getSslKeystoreType(); |
57 | 59 |
|
58 | | - if (config.getSslKeystorePassword().isPresent()) { |
59 | | - String keyStorePassword = config.getSslKeystorePassword().get(); |
| 60 | + if (sslKeystorePassword.isPresent()) { |
| 61 | + String keyStorePassword = sslKeystorePassword.get(); |
60 | 62 | if ("jks".equalsIgnoreCase(sslKeystoreType)) { |
61 | 63 | return new JksOptions() |
62 | 64 | .setPath(keyStoreLocation) |
@@ -84,34 +86,37 @@ private static KeyCertOptions getKeyCertOptions(MqttConnectorCommonConfiguration |
84 | 86 | * Attribute Name: ssl.truststore |
85 | 87 | * Description: Set whether keystore type, location and password. In case of pem type the location is the cert path. |
86 | 88 | * Default Value: PfxOptions |
87 | | - * |
| 89 | + * |
88 | 90 | * @return the TrustOptions |
89 | 91 | */ |
90 | 92 |
|
91 | 93 | private static TrustOptions getTrustOptions(MqttConnectorCommonConfiguration config) { |
92 | | - |
93 | | - if (config.getSsl() && config.getSslTruststoreLocation().isPresent()) { |
94 | | - String truststoreLocation = config.getSslTruststoreLocation().get(); |
| 94 | + Optional<String> sslTruststoreLocation = config.getSslTruststoreLocation(); |
| 95 | + Optional<String> sslTruststorePassword = config.getSslTruststorePassword(); |
| 96 | + if (config.getSsl() && sslTruststoreLocation.isPresent()) { |
| 97 | + String truststoreLocation = sslTruststoreLocation.get(); |
95 | 98 | String truststoreType = config.getSslTruststoreType(); |
96 | 99 |
|
97 | 100 | if ("pem".equalsIgnoreCase(truststoreType)) { |
98 | 101 | return new PemTrustOptions() |
99 | 102 | .addCertPath(truststoreLocation); |
100 | | - } else if (config.getSslTruststorePassword().isPresent()) { |
101 | | - String truststorePassword = config.getSslTruststorePassword().get(); |
102 | | - if ("jks".equalsIgnoreCase(truststoreType)) { |
103 | | - return new JksOptions() |
| 103 | + } else { |
| 104 | + if (sslTruststorePassword.isPresent()) { |
| 105 | + String truststorePassword = sslTruststorePassword.get(); |
| 106 | + if ("jks".equalsIgnoreCase(truststoreType)) { |
| 107 | + return new JksOptions() |
| 108 | + .setPath(truststoreLocation) |
| 109 | + .setPassword(truststorePassword); |
| 110 | + } |
| 111 | + // Default |
| 112 | + return new PfxOptions() |
104 | 113 | .setPath(truststoreLocation) |
105 | 114 | .setPassword(truststorePassword); |
| 115 | + } else { |
| 116 | + throw new IllegalArgumentException( |
| 117 | + "The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: " |
| 118 | + + config.getChannel() + ") must be set for `ssl.keystore.type`" + truststoreType); |
106 | 119 | } |
107 | | - // Default |
108 | | - return new PfxOptions() |
109 | | - .setPath(truststoreLocation) |
110 | | - .setPassword(truststorePassword); |
111 | | - } else { |
112 | | - throw new IllegalArgumentException( |
113 | | - "The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: " |
114 | | - + config.getChannel() + ") must be set for `ssl.keystore.type`" + truststoreType); |
115 | 120 | } |
116 | 121 | } |
117 | 122 | return null; |
|
0 commit comments