1
votes

My project needed SSL authentication mechanism to be EXTERNAL(using SSL certificates only and avoiding username/password on rabbitmq). For the connectionfactory bean we gave property name="saslConfig" value= "DefaultSaslConfig.EXTERNAL", but we are getting an error: "Cannot convert value of type [java.lang.String] to required type [com.rabbitmq.client.SaslConfig] for property 'saslConfig': no matching editors or conversion strategy found". we tried other values like value= "com.rabbitmq.client.DefaultSaslConfig.EXTERNAL" and value="EXTERNAL", but still the error persists. Can you please check on the configuration and logs below and provide me your suggestions.

Bean configuration

  <rabbit:connection-factory id="connectionFactory" connection-factory="clientConnectionFactory" host="x.y.z.m" port="5671"/>
    <bean id="clientConnectionFactory" class="org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean">
     <property name="useSSL" value="true" />
     <property name="saslConfig" value=com.rabbitmq.client.DefaultSaslConfig.EXTERNAL"/> 
     <property name="sslPropertiesLocation" value="classpath:/rabbitSSL.properties"/></bean>

Logs

Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.rabbitmq.client.SaslConfig] for property 'saslConfig': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
3

3 Answers

1
votes

The following worked for me (source: https://github.com/spring-projects/spring-boot/issues/6719#issuecomment-259268574):

@PostConstruct
public void init() {
    if (rabbitProperties.getSsl().isEnabled() && rabbitProperties.getSsl().getKeyStore() != null) {
        cachingConnectionFactory.getRabbitConnectionFactory().setSaslConfig(DefaultSaslConfig.EXTERNAL);
    }
}
0
votes

EXTERNAL is a static variable, not an enum.

Use

"#{T(com.rabbitmq.client.DefaultSaslConfig).EXTERNAL}"

which is a SpEL expression using the type operator (T) to get a reference to the static.

See SpEL

0
votes

We can use ConnectionFactoryCustomizer in package org.springframework.boot.autoconfigure.amqp to set sasl config on rabbitmq connection factory on bean creation.

@Autowired
RabbitProperties rabbitProperties

@Bean
ConnectionFactoryCustomizer connectionFactoryCustomizer() {
    if (rabbitProperties.getSsl().getEnabled() && rabbitProperties.getSsl().getKeyStore() != null) {
        return (connectionFactory) -> connectionFactory.setSaslConfig(DefaultSaslConfig.EXTERNAL)
    }
    return (connectionFactory) -> connectionFactory.setSaslConfig(DefaultSaslConfig.PLAIN)
}