DATACASS-263 - Fix authentication configuration in CassandraCqlClusterFactoryBean.
Configuring username/password authentication does no longer require setting of an AuthProvider which would be overwritten by the username/password authenticator.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user