简体   繁体   English

升级到 Spring boot 2.3.5.RELEASE 后的 Cassandra 身份验证问题

[英]Cassandra authentication issue after upgrading to Spring boot 2.3.5.RELEASE

We are upgrading to Spring boot 2.3.5.RELEASE.我们正在升级到 Spring Boot 2.3.5.RELEASE。 Our application has cassandra as one of the databases and we have enabled authentication on the nodes.我们的应用程序将 cassandra 作为数据库之一,并且我们在节点上启用了身份验证。 On trying to connect to the casssandra db after updating the spring boot version, I getting this exception and not able to start up the application.在更新 Spring Boot 版本后尝试连接到 casssandra 数据库时,我收到此异常并且无法启动应用程序。

Authentication error on node <IP:PORT> requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured

My cassandra configuration is as follows:我的cassandra配置如下:

   @Configuration
   @ConfigurationProperties("spring.data.cassandra.keyspaceName")
   @EnableCassandraRepositories(basePackages = { "com.company.project.feature.cassandra.repo" }, 
    cassandraTemplateRef = "dbTemplate")
  public class Config extends AbstractCassandraConfiguration {

@Autowired
ServerProperties serverProps;

protected String contactPoints;
protected Integer port;
protected String keyspaceName;
protected String localDataCenter;


@Override
public String getContactPoints() {
    return contactPoints;
}

/**
 * @param contactPoints
 */
public void setContactPoints(String contactPoints) {
    this.contactPoints = contactPoints;
}

/**
 * @param keyspaceName
 */
public void setKeyspaceName(String keyspaceName) {
    this.keyspaceName = keyspaceName;
}

@Override
public String getKeyspaceName() {
    return keyspaceName;
}

@Override
public int getPort() {
    return port;
}

public void setLocalDataCenter(String localDataCenter) {
    this.localDataCenter = localDataCenter;
}

@Override
public String getLocalDataCenter() {
    return localDataCenter;
}

public void setPort(Integer port) {
    this.port = port;
}

@Bean(name = "dbSession")
@Primary
public CqlSession session() {

    String containerIpAddress = getContactPoints();
    int containerPort = getPort();
    InetSocketAddress containerEndPoint = new InetSocketAddress(containerIpAddress, containerPort);
    
    CqlSessionBuilder builder = CqlSession.builder().withLocalDatacenter(getLocalDataCenter()).addContactPoint(containerEndPoint)
    .withAuthCredentials(serverProps.getCassandraUserName(), serverProps.getCassandraPassword())
    .withKeyspace(getKeyspaceName());
    
    
    return builder.build();
}


@Bean("dbOperations")
public CassandraOperations cassandraOperationsB() {
    return new CassandraTemplate(session(), cassandraConverter());
}

@Primary
@Bean(name = "dbTemplate")
@Override
public CassandraAdminTemplate cassandraTemplate() {
    return new CassandraAdminTemplate(session(), cassandraConverter());
}

} }

I am providing the username and password while building the CqlSession but still facing this exception.我在构建 CqlSession 时提供了用户名和密码,但仍然面临此异常。 Is there anything I am doing incorrectly?有什么我做错了吗?

in older Spring data versions you may use: CassandraClusterFactoryBean .在较旧的 Spring 数据版本中,您可以使用: CassandraClusterFactoryBean But here is an example for future if some one else stumbles with spring data cassandra 3.0.1 with user name and password authentication as spring data document if you scroll to the end of the page then you will see CassandraClusterFactoryBean is removed, instead of we have now CqlSessionFactoryBean .但是这里是一个未来的例子,如果其他人在使用用户名和密码身份验证作为spring 数据文档的spring 数据 cassandra 3.0.1 时遇到问题,如果你滚动到页面的末尾,那么你会看到CassandraClusterFactoryBean被删除,而不是我们有现在CqlSessionFactoryBean So sample code with looks like所以示例代码看起来像

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.config.CqlSessionFactoryBean;

@Configuration
@EnableCassandraRepositories(basePackages = {"com.some.package"})
@ConfigurationProperties(prefix = "spring.data.cassandra")
@Getter
@Setter
public class CassandraConfig extends AbstractCassandraConfiguration {

    private String keyspaceName;
    private String contactPoints;
    private int port;
    private String localDataCenter;
    private String username;
    private String password;

    @Bean
    @Override
    public CqlSessionFactoryBean cassandraSession() {
        CqlSessionFactoryBean cassandraSession = super.cassandraSession();//super session should be called only once
        cassandraSession.setUsername(username);
        cassandraSession.setPassword(password);
        return cassandraSession;
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring-boot从2.3.5.RELEASE升级到2.4.0后,在包 reactor.netty.tcp 中找不到ProxyProvider - After upgrading spring-boot from 2.3.5.RELEASE to 2.4.0, ProxyProvider is not found in the package reactor.netty.tcp “依赖&#39;org.springframework.boot:spring-boot-starter-log4j2:2.3.5.RELEASE&#39;未找到” - "Dependency 'org.springframework.boot:spring-boot-starter-log4j2:2.3.5.RELEASE' not found " 将 spring 引导从 2.3.5 升级到 2.6.6 后出现 Hazelcast 错误 - Hazelcast error after upgrading spring boot from 2.3.5 to 2.6.6 Spring 启动 2.3.1.Release 和 Cassandra 驱动程序超时问题 - Spring Boot 2.3.1.Release and Cassandra DriverTimeout issue CachingSessionFactory setPoolSize() 在将 spring boot 从 2.2.1.RELEASE 升级到 2.3.1.Release 后需要更长的时间 - CachingSessionFactory setPoolSize() takes much longer after upgrading spring boot from 2.2.1.RELEASE to 2.3.1.Release 在Spring Boot 1.3.1.RELEASE中升级到Hibernate 5.0.6.Final后,嵌入式字段不起作用 - Embedded field does not work after upgrading to Hibernate 5.0.6.Final in Spring Boot 1.3.1.RELEASE 升级到Spring Boot 1.3.3后,@ Async无法正常工作 - @Async not working after upgrading to Spring Boot 1.3.3 从 Spring Boot 1.5.4 升级到 2.0.0 的问题 - Issue upgrading from Spring Boot 1.5.4 to 2.0.0 升级到 Spring Boot 2 后应用程序无法启动 - Application fails to start after upgrading to Spring Boot 2 升级到 Boot 1.2 后无法访问 Spring Boot 执行器运行状况端点 - Spring Boot actuator health endpoint not accessible after upgrading to Boot 1.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM