Commit b03c2484 by nixonrodrigues

ATLAS-2587:- Set read ACL for /apache_atlas/active_server_info znode in HA for Knox proxy to read.

parent d5540595
...@@ -24,11 +24,13 @@ import org.apache.atlas.AtlasException; ...@@ -24,11 +24,13 @@ import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.ha.HAConfiguration;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock; import org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -37,6 +39,7 @@ import org.springframework.stereotype.Component; ...@@ -37,6 +39,7 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject; import javax.inject.Inject;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -91,9 +94,18 @@ public class ActiveInstanceState { ...@@ -91,9 +94,18 @@ public class ActiveInstanceState {
HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.ZookeeperProperties zookeeperProperties =
HAConfiguration.getZookeeperProperties(configuration); HAConfiguration.getZookeeperProperties(configuration);
String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId); String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId);
List<ACL> acls = Arrays.asList(
new ACL[]{AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(), List<ACL> acls = new ArrayList<ACL>();
ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0))}); ACL parsedACL = AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(),
ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0));
acls.add(parsedACL);
//adding world read permission
if (StringUtils.isNotEmpty(zookeeperProperties.getAcl())) {
ACL worldReadPermissionACL = new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"));
acls.add(worldReadPermissionACL);
}
Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties)); Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties));
if (serverInfo == null) { if (serverInfo == null) {
client.create(). client.create().
......
...@@ -114,9 +114,11 @@ public class ActiveInstanceStateTest { ...@@ -114,9 +114,11 @@ public class ActiveInstanceStateTest {
CreateBuilder createBuilder = mock(CreateBuilder.class); CreateBuilder createBuilder = mock(CreateBuilder.class);
when(curatorFramework.create()).thenReturn(createBuilder); when(curatorFramework.create()).thenReturn(createBuilder);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder); when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "myclient@EXAMPLE.COM")); ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "myclient@EXAMPLE.COM"));
ACL expectedAcl1 = new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"));
when(createBuilder. when(createBuilder.
withACL(Arrays.asList(new ACL[]{expectedAcl}))).thenReturn(createBuilder); withACL(Arrays.asList(new ACL[]{expectedAcl,expectedAcl1}))).thenReturn(createBuilder);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder); when(curatorFramework.setData()).thenReturn(setDataBuilder);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment