根据文档,我可以通过调用addAuthInfo为Zookeeper ACL添加认证信息。但是在策展人框架 bean 中,我没有找到方法本身。它抛出了编译问题!.
我的聚甲醛有
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.8</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
如何将动物园管理员身份验证信息添加到春云动物园管理员配置中。任何工作示例都会对我有所帮助。
此问题存在 github 问题,它仍处于打开状态。
只要春酷团队解决了这个问题,就可以创建自定义的策展人配置类,并在 CuratorFrameworkFactory 类的构建器方法中添加认证信息:
@BootstrapConfiguration
@ConditionalOnZookeeperEnabled
public class CustomCuratorFrameworkConfig {
@Autowired(required = false)
private EnsembleProvider ensembleProvider;
@Bean
@ConditionalOnMissingBean
public ZookeeperProperties zookeeperProperties() {
return new ZookeeperProperties();
}
@Bean
@ConditionalOnMissingBean
public CuratorFramework curatorFramework(RetryPolicy retryPolicy, ZookeeperProperties properties) throws Exception{
// username and password of the ACL digest scheme
String zkUsername = "user";
String zkPassword = "password";
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
if (this.ensembleProvider != null) {
builder.ensembleProvider(this.ensembleProvider);
} else {
builder.connectString(properties.getConnectString());
}
builder.retryPolicy(retryPolicy);
String authenticationString = zkUsername + ":" + zkPassword;
builder.authorization("digest", authenticationString.getBytes())
.aclProvider(new ACLProvider() {
@Override
public List<ACL> getDefaultAcl() {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
@Override
public List<ACL> getAclForPath(String path) {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
});
CuratorFramework curator = builder.build();
curator.start();
curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
return curator;
}
@Bean
@ConditionalOnMissingBean
public RetryPolicy exponentialBackoffRetry(ZookeeperProperties properties) {
return new ExponentialBackoffRetry(properties.getBaseSleepTimeMs(), properties.getMaxRetries(), properties.getMaxSleepMs());
}
}
然后像这个春天的文档一样继续:
您可以注册要在此阶段运行的配置类,方法是使用 @BootstrapConfiguration 批注它们并将它们包含在逗号分隔的列表中,该列表设置为 resources/META-INF/spring.factory 文件中的 org.springframework.cloud.bootstrap.BootstrapConfiguration 属性的值。
资源/META-INF/spring.factory
org.springframework.cloud.bootstrap.BootstrapConfiguration=
my.project.CustomCuratorFrameworkConfig