Skip to content

Docs for adding authentication are wrong #239

Closed

Description

@Alfred-Mountfield

The code snippets provided in the docs for adding authentication to the CuratorFramework suggest methods that don't exist i.e.

@BoostrapConfiguration
public class CustomCuratorFrameworkConfig {

  @Bean
  public CuratorFramework curatorFramework() {
    CuratorFramework curator = new CuratorFramework();
    curator.addAuthInfo("digest", "user:password".getBytes());
    return curator;
  }

}

And

@BoostrapConfiguration
public class DefaultCuratorFrameworkConfig {

  public ZookeeperConfig(CuratorFramework curator) {
    curator.addAuthInfo("digest", "user:password".getBytes());
  }

The CuratorFramework interface doesn't have a method called addAuthInfo, and the code snippet also has @BootstrapConfiguration spelled incorrectly.

Furthermore I think the initial code snippet wouldn't work as it would override the standard implementation in spring cloud zookeeper rather than extending it.

What is the currently suggested way for adding authentication information? I can see the CuratorFrameworkImpl and CuratorFrameworkFactory now have variables called authInfos that's set through the builder by calling authorization(List authInfos).

Is the suggested/correct way to add authentication now to override the curatorFramework bean from the ZookeeperAutoConfiguration and add that option within the builder? Does this still have to happen at the Bootstrapping phase?

Activity

  1. spencergibb commented on Apr 8, 2020

    @spencergibb
    Member

    The functionality will be available after #244 adds a CuratorFrameworkFactory.Builder customizer has been added. There are then authorization() methods on the build. The docs will need to be updated when #244 is done.

  2. Alfred-Mountfield commented on Apr 16, 2020

    @Alfred-Mountfield
    Author

    Sounds good. Looking at how the proposed changes could solve our problems, thanks

  3. chingjustwe commented on Sep 2, 2022

    @chingjustwe

    I still don't see the updated doc, can anybody share how to set ACL in new way?

  4. chingjustwe commented on Sep 2, 2022

    @chingjustwe

    @berngp can you explain how to use CuratorFrameworkCustomizer please? In my case, CuratorFramework always created before CuratorFrameworkCustomizer.

  5. aofall commented on Jun 9, 2023

    @aofall

    Define the following configuration in the code.

    @Data
    @ConfigurationProperties("spring.cloud.zookeeper")
    public class SpringCloudZookeeperProperties {
        private String username;
        private String password;
    }
    
    @Slf4j
    @Configuration
    @EnableConfigurationProperties(SpringCloudZookeeperProperties.class)
    public class DefaultSpringCloudZookeeperConfig {
    
        @Resource
        private SpringCloudZookeeperProperties springCloudZookeeperProperties;
    
        @Bean(destroyMethod = "close")
        public CuratorFramework curatorFramework(RetryPolicy retryPolicy, org.springframework.cloud.zookeeper.ZookeeperProperties properties) throws Exception {
            CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
            builder.connectString(properties.getConnectString());
            if (StringUtils.isNotEmpty(springCloudZookeeperProperties.getUsername())
                    && StringUtils.isNotEmpty(springCloudZookeeperProperties.getPassword())) {
                builder.authorization("digest", (springCloudZookeeperProperties.getUsername() + ":" + springCloudZookeeperProperties.getPassword()).getBytes());
            }
            CuratorFramework curator = builder.retryPolicy(retryPolicy).build();
            curator.start();
            curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
            log.trace("connected to zookeeper");
            return curator;
        }
    
    }
    

    The StringUtils class from the commons-lang3 package, you can import from maven. The current final version is 3.12.0 now

    <dependency>
    	<groupId>org.apache.commons</groupId>
    	<artifactId>commons-lang3</artifactId>
    	<version>${commons-lang3.version}</version>
    </dependency>
    

    And defined in application.yml, if ACL authentication is not required, just keep the username and password empty.

    spring:
      cloud:
        zookeeper: 
    	  connect-string: localhost:2181
    	  username: username
    	  password: password
    
  6. spencergibb commented on Jul 13, 2023

    @spencergibb
    Member

    Please stop commenting on multiple issues

  7. WhiteStart commented on Aug 16, 2023

    @WhiteStart

    I solved it by the following codes,the docs missed a 't' at @BootstrapConfiguration,maybe need to update the docs or pr?
    I don't no why the codes can not display properly when using Add code option.
    `
    @BootstrapConfiguration
    public class CustomCuratorFrameworkConfig {

    @Autowired(required = false)
    private EnsembleProvider ensembleProvider;
    
    @Bean
    public ZookeeperProperties zookeeperProperties() {
        return new ZookeeperProperties();
    }
    
    @Bean
    public CuratorFramework curatorFramework(RetryPolicy retryPolicy, ZookeeperProperties properties) throws Exception{
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
        if (this.ensembleProvider != null) {
            builder.ensembleProvider(this.ensembleProvider);
        } else {
            builder.connectString(properties.getConnectString());
        }
    
        builder.retryPolicy(retryPolicy);
    
        String digestString = "user:password";
        List<ACL> list = new ArrayList<>();
        String digest = DigestAuthenticationProvider.generateDigest(digestString);
        ACL acl = new ACL(ZooDefs.Perms.ALL, new Id("digest", digest));
        list.add(acl);
    
        builder.authorization("digest", digestString.getBytes())
                .aclProvider(new ACLProvider() {
                    @Override
                    public List<ACL> getDefaultAcl() {
                        return list;
                    }
    
                    @Override
                    public List<ACL> getAclForPath(String path) {
                        return list;
                    }
                });
    
        CuratorFramework curator =  builder.build();
        curator.start();
        curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
        return curator;
    }
    
    @Bean
    public RetryPolicy exponentialBackoffRetry(ZookeeperProperties properties) {
        return new ExponentialBackoffRetry(properties.getBaseSleepTimeMs(), properties.getMaxRetries(), properties.getMaxSleepMs());
    }
    

    }`

    spring.factories
    org.springframework.cloud.bootstrap.BootstrapConfiguration=\ com.example.registration.config.CustomCuratorFrameworkConfig

    bootstrap.yml
    spring: cloud: zookeeper: connect-string: 127.0.0.1:2181 enabled: true
    org.springframework.cloud
    spring-cloud-starter-bootstrap
    `

  8. AzazelSensei commented on Sep 3, 2026

    @AzazelSensei
    Contributor

    Opened #460 with the CuratorFrameworkCustomizer / authorization() docs Spencer mentioned after #244.

  9. moved this from Todo to In Progress in 2025.1.4on Sep 8, 2026
  10. added this to the 5.0.3 milestone on Sep 8, 2026
  11. added a commit that references this issue on Sep 8, 2026
  12. moved this from In Progress to Done in 2025.1.4on Sep 8, 2026
  13. moved this from In Progress to Done in 2026.0.0-M1on Sep 8, 2026
  14. added a commit that references this issue on Sep 8, 2026
  15. added a commit that references this issue on Sep 30, 2026
    488c4ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions