Cassandra Springboot Spring Data 中的多个键空间,同时为每个键空间设置凭据
我正在尝试为多个密钥空间配置 cassandra ,我需要为 cassandra 设置用户名和密码,覆盖会话函数,这会给我一个身份验证错误,即使我可以找到在代码中打印的凭据。
我尝试了上面提到的不同方法,但在添加凭据时我无法弄清楚。
我收到此身份验证错误
Caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 3 nodes, use getAllErrors() for more): Node(endPoint=10.0.213.69:9042, hostId=null, hashCode=6453355e): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.213.69:9042: Node 10.0.213.69:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured], Node(endPoint=10.0.211.74:9042, hostId=null, hashCode=6a94c67c): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.211.74:9042: Node 10.0.211.74:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured], Node(endPoint=10.0.208.57:9042, hostId=null, hashCode=606cad0c): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.208.57:9042: Node 10.0.208.57:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured]
我有一个像这样的基本配置
abstract class CassandraBaseConfig :
AbstractCassandraConfiguration() {
override fun getSchemaAction(): SchemaAction {
return SchemaAction.CREATE_IF_NOT_EXISTS
}
override fun getSessionBuilderConfigurer(): SessionBuilderConfigurer? {
return SessionBuilderConfigurer { sessionBuilder: CqlSessionBuilder ->
val builder: ProgrammaticDriverConfigLoaderBuilder = DefaultProgrammaticDriverConfigLoaderBuilder(
{
ConfigFactory.invalidateCaches()
ConfigFactory.defaultOverrides()
.withFallback(buildConfig())
.withFallback(ConfigFactory.defaultReference())
.resolve()
},
DefaultDriverConfigLoader.DEFAULT_ROOT_PATH
).withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(60))
.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(180))
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofSeconds(60))
sessionBuilder.withConfigLoader(builder.build())
return@SessionBuilderConfigurer sessionBuilder
}
}
private companion object CassandraDriverOptions {
private val options: MutableMap<String, Any> = LinkedHashMap()
fun addOption(option: DriverOption, value: Any): CassandraDriverOptions {
val key = createKeyFor(option)
options[key] = value
return this
}
fun buildConfig() = ConfigFactory.parseMap(options, "Environment")
private fun createKeyFor(option: DriverOption) = "${DefaultDriverConfigLoader.DEFAULT_ROOT_PATH}.${option.path}"
}
}
和两个我像这样配置的密钥空间
@Configuration
@EnableCassandraRepositories(
basePackages = ["com.expediagroup.dataquality.api.repository.cassandra.egdq"],
cassandraTemplateRef = "cassandraEgdqPropertiesTemplate"
)
open class CassandraEgdqAppUser(
private val cassandraEgdqProperties: CassandraEgdqProperties
) :
CassandraBaseConfig() {
override fun getKeyspaceName() = cassandraEgdqProperties.keySpace
override fun getContactPoints() = cassandraEgdqProperties.contactPoints
override fun getPort() = cassandraEgdqProperties.portNumber
override fun getLocalDataCenter() = cassandraEgdqProperties.dataCenterName
@Bean("cassandraEgdqPropertiesSession")
open fun session(): CqlSessionFactoryBean {
val cassandraSession = super.cassandraSession()
cassandraSession.setUsername(cassandraEgdqProperties.username)
cassandraSession.setPassword(cassandraEgdqProperties.password)
return cassandraSession
}
@Bean("cassandraEgdqPropertiesTemplate")
@Throws(Exception::class)
open fun cassandraTemplate(
@Qualifier("cassandraEgdqPropertiesSession") session: CqlSessionFactoryBean
): CassandraAdminOperations {
return CassandraAdminTemplate(session.getObject(), cassandraConverter())
}
}
第二个密钥空间
@Configuration
@EnableCassandraRepositories(
basePackages = ["com.expediagroup.dataquality.api.repository.cassandra.egdqprofiles"],
cassandraTemplateRef = "cassandraPropertiesTemplate"
)
open class CassandraEgdqProfilesAppUser(
private val cassandraProperties: CassandraProperties
) : CassandraBaseConfig() {
override fun getKeyspaceName() = cassandraProperties.keySpace
override fun getContactPoints() = cassandraProperties.contactPoints
override fun getPort() = cassandraProperties.portNumber
override fun getLocalDataCenter() = cassandraProperties.dataCenterName
@Bean("cassandraPropertiesSession")
// @Primary
open fun session(): CqlSessionFactoryBean {
val cassandraSession = super.cassandraSession()
cassandraSession.setUsername(cassandraProperties.username)
cassandraSession.setPassword(cassandraProperties.password)
return cassandraSession
}
@Bean("cassandraPropertiesTemplate")
@Throws(Exception::class)
open fun cassandraTemplate(
@Qualifier("cassandraPropertiesSession") session: CqlSessionFactoryBean
): CassandraAdminOperations {
return CassandraAdminTemplate(session.getObject(), cassandraConverter())
}
}
任何帮助表示赞赏。
I am trying to configure cassandra for multiple keyspaces , I need to set userName and Password for cassandra, overriding session function which gives me an authentication error, even though I can find the credentials getting printed in code.
I tried with different approaches mentioned on SO, I haven't been able to figure things out while adding credentials.
I get this Authentication error
Caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 3 nodes, use getAllErrors() for more): Node(endPoint=10.0.213.69:9042, hostId=null, hashCode=6453355e): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.213.69:9042: Node 10.0.213.69:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured], Node(endPoint=10.0.211.74:9042, hostId=null, hashCode=6a94c67c): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.211.74:9042: Node 10.0.211.74:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured], Node(endPoint=10.0.208.57:9042, hostId=null, hashCode=606cad0c): [com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node 10.0.208.57:9042: Node 10.0.208.57:9042 requires authentication (org.apache.cassandra.auth.PasswordAuthenticator), but no authenticator configured]
I have a base config like this
abstract class CassandraBaseConfig :
AbstractCassandraConfiguration() {
override fun getSchemaAction(): SchemaAction {
return SchemaAction.CREATE_IF_NOT_EXISTS
}
override fun getSessionBuilderConfigurer(): SessionBuilderConfigurer? {
return SessionBuilderConfigurer { sessionBuilder: CqlSessionBuilder ->
val builder: ProgrammaticDriverConfigLoaderBuilder = DefaultProgrammaticDriverConfigLoaderBuilder(
{
ConfigFactory.invalidateCaches()
ConfigFactory.defaultOverrides()
.withFallback(buildConfig())
.withFallback(ConfigFactory.defaultReference())
.resolve()
},
DefaultDriverConfigLoader.DEFAULT_ROOT_PATH
).withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(60))
.withDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofSeconds(180))
.withDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofSeconds(60))
sessionBuilder.withConfigLoader(builder.build())
return@SessionBuilderConfigurer sessionBuilder
}
}
private companion object CassandraDriverOptions {
private val options: MutableMap<String, Any> = LinkedHashMap()
fun addOption(option: DriverOption, value: Any): CassandraDriverOptions {
val key = createKeyFor(option)
options[key] = value
return this
}
fun buildConfig() = ConfigFactory.parseMap(options, "Environment")
private fun createKeyFor(option: DriverOption) = "${DefaultDriverConfigLoader.DEFAULT_ROOT_PATH}.${option.path}"
}
}
And two keyspaces which I configure like this
@Configuration
@EnableCassandraRepositories(
basePackages = ["com.expediagroup.dataquality.api.repository.cassandra.egdq"],
cassandraTemplateRef = "cassandraEgdqPropertiesTemplate"
)
open class CassandraEgdqAppUser(
private val cassandraEgdqProperties: CassandraEgdqProperties
) :
CassandraBaseConfig() {
override fun getKeyspaceName() = cassandraEgdqProperties.keySpace
override fun getContactPoints() = cassandraEgdqProperties.contactPoints
override fun getPort() = cassandraEgdqProperties.portNumber
override fun getLocalDataCenter() = cassandraEgdqProperties.dataCenterName
@Bean("cassandraEgdqPropertiesSession")
open fun session(): CqlSessionFactoryBean {
val cassandraSession = super.cassandraSession()
cassandraSession.setUsername(cassandraEgdqProperties.username)
cassandraSession.setPassword(cassandraEgdqProperties.password)
return cassandraSession
}
@Bean("cassandraEgdqPropertiesTemplate")
@Throws(Exception::class)
open fun cassandraTemplate(
@Qualifier("cassandraEgdqPropertiesSession") session: CqlSessionFactoryBean
): CassandraAdminOperations {
return CassandraAdminTemplate(session.getObject(), cassandraConverter())
}
}
Second keyspace
@Configuration
@EnableCassandraRepositories(
basePackages = ["com.expediagroup.dataquality.api.repository.cassandra.egdqprofiles"],
cassandraTemplateRef = "cassandraPropertiesTemplate"
)
open class CassandraEgdqProfilesAppUser(
private val cassandraProperties: CassandraProperties
) : CassandraBaseConfig() {
override fun getKeyspaceName() = cassandraProperties.keySpace
override fun getContactPoints() = cassandraProperties.contactPoints
override fun getPort() = cassandraProperties.portNumber
override fun getLocalDataCenter() = cassandraProperties.dataCenterName
@Bean("cassandraPropertiesSession")
// @Primary
open fun session(): CqlSessionFactoryBean {
val cassandraSession = super.cassandraSession()
cassandraSession.setUsername(cassandraProperties.username)
cassandraSession.setPassword(cassandraProperties.password)
return cassandraSession
}
@Bean("cassandraPropertiesTemplate")
@Throws(Exception::class)
open fun cassandraTemplate(
@Qualifier("cassandraPropertiesSession") session: CqlSessionFactoryBean
): CassandraAdminOperations {
return CassandraAdminTemplate(session.getObject(), cassandraConverter())
}
}
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决第一个问题,我认为我在配置过程中使用了重叠的前缀。
接下来,我之前使用
super.cassandraSession()
修改了会话,而不是使用然后我需要在 yaml 文件中排除 CassandraDataAutoConfiguration
To get rid of the first issue I figured I had overlapping prefixes I was using during configuration.
Next I modified session earlier using
super.cassandraSession()
to instead useThen I needed to exclude CassandraDataAutoConfiguration in my yaml file