This repository was archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 439
ACL Support #211
Open
adrianluisgonzalez
wants to merge
1
commit into
soabase:master
Choose a base branch
from
ef-labs:feature/acl_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ACL Support #211
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |
| import javax.ws.rs.core.Response; | ||
| import javax.ws.rs.ext.ContextResolver; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
@@ -57,6 +58,13 @@ public class ConfigResource | |
|
|
||
| private static final String CANT_UPDATE_CONFIG_MESSAGE = "It appears that another process has updated the config. Your change was not committed."; | ||
|
|
||
| /** | ||
| * Contains a list of all those properties that we don't want returned in the 'get-state' method. | ||
| */ | ||
| private static final List<StringConfigs> EXCLUSIONS = Arrays.asList( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: private static final Set<StringConfigs> EXCLUSIONS = Sets.immutableEnumSet(
StringConfigs.ZK_SUPER_USER_PASSWORD
); |
||
| StringConfigs.ZK_SUPER_USER_PASSWORD | ||
| ); | ||
|
|
||
| public ConfigResource(@Context ContextResolver<UIContext> resolver) | ||
| { | ||
| context = resolver.getContext(UIContext.class); | ||
|
|
@@ -92,7 +100,9 @@ public Response getSystemState(@Context Request request) throws Exception | |
| configNode.put("serverId", (us != null) ? us.getServerId() : -1); | ||
| for ( StringConfigs c : StringConfigs.values() ) | ||
| { | ||
| configNode.put(fixName(c), config.getString(c)); | ||
| if ( !EXCLUSIONS.contains(c) ) { | ||
| configNode.put(fixName(c), config.getString(c)); | ||
| } | ||
| } | ||
| for ( IntConfigs c : IntConfigs.values() ) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import com.netflix.exhibitor.core.analyze.PathAndMax; | ||
| import com.netflix.exhibitor.core.analyze.PathComplete; | ||
| import com.netflix.exhibitor.core.analyze.UsageListing; | ||
| import com.netflix.exhibitor.core.config.IntConfigs; | ||
| import com.netflix.exhibitor.core.entities.IdList; | ||
| import com.netflix.exhibitor.core.entities.PathAnalysis; | ||
| import com.netflix.exhibitor.core.entities.PathAnalysisNode; | ||
|
|
@@ -34,7 +35,10 @@ | |
| import org.apache.curator.utils.CloseableUtils; | ||
| import org.apache.curator.utils.ZKPaths; | ||
| import org.apache.zookeeper.KeeperException; | ||
| import org.apache.zookeeper.data.ACL; | ||
| import org.apache.zookeeper.data.Id; | ||
| import org.apache.zookeeper.data.Stat; | ||
| import org.apache.zookeeper.ZooDefs; | ||
| import org.codehaus.jackson.map.ObjectMapper; | ||
| import org.codehaus.jackson.node.ArrayNode; | ||
| import org.codehaus.jackson.node.JsonNodeFactory; | ||
|
|
@@ -44,10 +48,12 @@ | |
| import javax.ws.rs.core.Context; | ||
| import javax.ws.rs.core.Response; | ||
| import javax.ws.rs.ext.ContextResolver; | ||
| import javax.xml.bind.DatatypeConverter; | ||
| import java.io.PipedInputStream; | ||
| import java.io.PipedOutputStream; | ||
| import java.io.PrintStream; | ||
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
@@ -61,10 +67,12 @@ public class ExplorerResource | |
| private final ExecutorService executorService = Executors.newCachedThreadPool(); | ||
|
|
||
| private static final String ERROR_KEY = "*"; | ||
| private final boolean aclsEnabled; | ||
|
|
||
| public ExplorerResource(@Context ContextResolver<UIContext> resolver) | ||
| { | ||
| context = resolver.getContext(UIContext.class); | ||
| aclsEnabled = context.getExhibitor().getConfigManager().getConfig().getInt(IntConfigs.ENABLE_ACLS) == 1; | ||
| } | ||
|
|
||
| public static String bytesToString(byte[] bytes) | ||
|
|
@@ -139,6 +147,7 @@ private void recursivelyDelete(String path) throws Exception | |
| @HeaderParam("netflix-user-name") String trackingUserName, | ||
| @HeaderParam("netflix-ticket-number") String trackingTicketNumber, | ||
| @HeaderParam("netflix-reason") String trackingReason, | ||
| @HeaderParam("acls") String aclsJsonArray, | ||
| String binaryDataStr | ||
| ) | ||
| { | ||
|
|
@@ -156,6 +165,18 @@ private void recursivelyDelete(String path) throws Exception | |
|
|
||
| try | ||
| { | ||
| List<ACL> acls = new ArrayList<ACL>(); | ||
| boolean processAcls = (aclsEnabled && (aclsJsonArray != null && !aclsJsonArray.equals(""))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: |
||
|
|
||
| if (processAcls) { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| List<ObjectNode> aclsInJson = mapper.readValue(DatatypeConverter.parseBase64Binary(aclsJsonArray), new TypeReference<List<ObjectNode>>() {}); | ||
| for (ObjectNode aclInJson : aclsInJson) { | ||
| Id id = new Id(aclInJson.get("scheme").getTextValue(), aclInJson.get("id").getTextValue()); | ||
| acls.add(new ACL(aclInJson.get("bitmask").getIntValue(), id)); | ||
| } | ||
| } | ||
|
|
||
| binaryDataStr = binaryDataStr.replace(" ", ""); | ||
| byte[] data = new byte[binaryDataStr.length() / 2]; | ||
| for ( int i = 0; i < data.length; ++i ) | ||
|
|
@@ -169,11 +190,21 @@ private void recursivelyDelete(String path) throws Exception | |
| { | ||
| context.getExhibitor().getLocalConnection().setData().forPath(path, data); | ||
| context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() updated node [%s] to data [%s]", path, binaryDataStr)); | ||
|
|
||
| if (processAcls) { | ||
| context.getExhibitor().getLocalConnection().setACL().withACL(acls).forPath(path); | ||
| context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() updated acls for node [%s]", path)); | ||
| } | ||
| } | ||
| catch ( KeeperException.NoNodeException dummy ) | ||
| { | ||
| context.getExhibitor().getLocalConnection().create().creatingParentsIfNeeded().forPath(path, data); | ||
| context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() created node [%s] with data [%s]", path, binaryDataStr)); | ||
|
|
||
| if (processAcls) { | ||
| context.getExhibitor().getLocalConnection().setACL().withACL(acls).forPath(path); | ||
| context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() updated acls for node [%s]" , path)); | ||
| } | ||
| } | ||
| } | ||
| catch ( Exception e ) | ||
|
|
@@ -199,6 +230,21 @@ public String getNodeData(@QueryParam("key") String key) throws Exception | |
| Stat stat = context.getExhibitor().getLocalConnection().checkExists().forPath(key); | ||
| byte[] bytes = context.getExhibitor().getLocalConnection().getData().storingStatIn(stat).forPath(key); | ||
|
|
||
| if (aclsEnabled) { | ||
| List<ACL> acls = context.getExhibitor().getLocalConnection().getACL().forPath(key); | ||
| ArrayNode aclsNode = node.putArray("acls"); | ||
| StringBuilder aclsAsString = new StringBuilder(); | ||
|
|
||
| for (ACL acl : acls) { | ||
| aclsAsString.append(encodeAclToString(acl)); | ||
| aclsAsString.append("<br/>"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should have html tags in return values of the REST API. |
||
|
|
||
| aclsNode.add(encodeAclToJson(acl)); | ||
| } | ||
| node.put("aclsArray", aclsNode); | ||
| node.put("acls", aclsAsString.toString()); | ||
| } | ||
|
|
||
| if (bytes != null) { | ||
| node.put("bytes", bytesToString(bytes)); | ||
| node.put("str", new String(bytes, "UTF-8")); | ||
|
|
@@ -223,6 +269,30 @@ public String getNodeData(@QueryParam("key") String key) throws Exception | |
| return node.toString(); | ||
| } | ||
|
|
||
| private String encodeAclToString(ACL acl) { | ||
| String scheme = acl.getId().getScheme(); | ||
| String id = acl.getId().getId(); | ||
|
|
||
| StringBuilder perms = new StringBuilder(); | ||
| if ((acl.getPerms() & ZooDefs.Perms.READ) > 0) perms.append("R"); | ||
| if ((acl.getPerms() & ZooDefs.Perms.WRITE) > 0) perms.append("W"); | ||
| if ((acl.getPerms() & ZooDefs.Perms.CREATE) > 0) perms.append("C"); | ||
| if ((acl.getPerms() & ZooDefs.Perms.DELETE) > 0) perms.append("D"); | ||
| if ((acl.getPerms() & ZooDefs.Perms.ADMIN) > 0) perms.append("A"); | ||
|
|
||
| return scheme + ":" + id + "=" + perms.toString(); | ||
| } | ||
|
|
||
| private ObjectNode encodeAclToJson(ACL acl) { | ||
| ObjectNode node = JsonNodeFactory.instance.objectNode(); | ||
|
|
||
| node.put("scheme", acl.getId().getScheme()); | ||
| node.put("id", acl.getId().getId()); | ||
| node.put("perms", acl.getPerms()); | ||
|
|
||
| return node; | ||
| } | ||
|
|
||
| @GET | ||
| @Path("node") | ||
| @Produces("application/json") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style:
!Strings.isNullOrEmpty(zkSuperUserPassword)