CuratorFactory { @VisibleForTesting void enhanceBuilderWithSecurityParameters(HAConfiguration.ZookeeperProperties zookeeperProperties, CuratorFrameworkFactory.Builder builder) { ACLProvider aclProvider = getAclProvider(zookeeperProperties); AuthInfo authInfo = null; if (zookeeperProperties.hasAuth()) { authInfo = AtlasZookeeperSecurityProperties.parseAuth(zookeeperProperties.getAuth()); } if (aclProvider != null) { LOG.info("Setting up acl provider."); builder.aclProvider(aclProvider); if (authInfo != null) { byte[] auth = authInfo.getAuth(); LOG.info("Setting up auth provider with scheme: {} and id: {}", authInfo.getScheme(), getIdForLogging(authInfo.getScheme(), new String(auth, Charsets.UTF_8))); builder.authorization(authInfo.getScheme(), auth); } } } CuratorFactory();  CuratorFactory(Configuration configuration); void close(); CuratorFramework clientInstance(); LeaderLatch leaderLatchInstance(String serverId, String zkRoot); InterProcessMutex lockInstance(String zkRoot); static final String APACHE_ATLAS_LEADER_ELECTOR_PATH; static final String SASL_SCHEME; static final String WORLD_SCHEME; static final String ANYONE_ID; static final String AUTH_SCHEME; static final String DIGEST_SCHEME; static final String IP_SCHEME; static final String SETUP_LOCK; }
@Test public void shouldAddAuthorization() { when(zookeeperProperties.hasAcl()).thenReturn(true); when(zookeeperProperties.getAcl()).thenReturn("sasl:myclient@EXAMPLE.COM"); when(zookeeperProperties.hasAuth()).thenReturn(true); when(zookeeperProperties.getAuth()).thenReturn("sasl:myclient@EXAMPLE.COM"); CuratorFactory curatorFactory = new CuratorFactory(configuration) { @Override protected void initializeCuratorFramework() { } }; curatorFactory.enhanceBuilderWithSecurityParameters(zookeeperProperties, builder); verify(builder).aclProvider(any(ACLProvider.class)); verify(builder).authorization(eq("sasl"), eq("myclient@EXAMPLE.COM".getBytes(Charsets.UTF_8))); }
@Test public void shouldAddAclProviderWithRightACL() { when(zookeeperProperties.hasAcl()).thenReturn(true); when(zookeeperProperties.getAcl()).thenReturn("sasl:myclient@EXAMPLE.COM"); when(zookeeperProperties.hasAuth()).thenReturn(false); CuratorFactory curatorFactory = new CuratorFactory(configuration) { @Override protected void initializeCuratorFramework() { } }; curatorFactory.enhanceBuilderWithSecurityParameters(zookeeperProperties, builder); verify(builder).aclProvider(argThat(new ArgumentMatcher<ACLProvider>() { @Override public boolean matches(Object o) { ACLProvider aclProvider = (ACLProvider) o; ACL acl = aclProvider.getDefaultAcl().get(0); return acl.getId().getId().equals("myclient@EXAMPLE.COM") && acl.getId().getScheme().equals("sasl"); } })); }