diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java index 901e2192a..5e137b851 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.cassandra.config; import java.util.ArrayList; @@ -63,6 +62,7 @@ import com.datastax.driver.core.policies.RetryPolicy; * @author Kirk Clemens * @author Jorge Davison * @author John Blum + * @author Mark Paluch * @see org.springframework.beans.factory.InitializingBean * @see org.springframework.beans.factory.DisposableBean * @see org.springframework.beans.factory.FactoryBean @@ -185,10 +185,8 @@ public class CassandraCqlClusterFactoryBean if (authProvider != null) { builder.withAuthProvider(authProvider); - - if (username != null) { - builder.withCredentials(username, password); - } + } else if (username != null) { + builder.withCredentials(username, password); } if (nettyOptions != null) { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java index 4e5490445..3b0ed6fe4 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java @@ -173,27 +173,31 @@ public class CassandraCqlClusterFactoryBeanUnitTests { /** * @see DATACASS-226 + * @see DATACASS-263 * @throws Exception */ @Test - public void doesNotSetPlainTextAuthenticationUnlessAuthProviderIsSet() throws Exception { + public void shouldSetAuthenticationProvider() throws Exception { - CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean(); - bean.setUsername("user"); - bean.setPassword("password"); - bean.afterPropertiesSet(); - - AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider(); - assertThat(result, is(AuthProvider.NONE)); - } - - @Test - public void shouldSetAuthentication() throws Exception { - - PlainTextAuthProvider authProvider = new PlainTextAuthProvider("x", "y"); + AuthProvider authProvider = new PlainTextAuthProvider("x", "y"); CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean(); bean.setAuthProvider(authProvider); + bean.afterPropertiesSet(); + + AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider(); + assertThat(result, is(equalTo(authProvider))); + } + + /** + * @see DATACASS-226 + * @see DATACASS-263 + * @throws Exception + */ + @Test + public void shouldSetAuthentication() throws Exception { + + CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean(); bean.setUsername("user"); bean.setPassword("password"); bean.afterPropertiesSet();