Skip to content

Commit

Permalink
ACLs: Thread session ID through fixup context
Browse files Browse the repository at this point in the history
  • Loading branch information
ztzg committed Jan 23, 2025
1 parent 659526a commit de2823a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ protected void pRequest2Txn(int type, long zxid, Request request, Record record)
SetACLRequest setAclRequest = (SetACLRequest) record;
path = setAclRequest.getPath();
validatePath(path, request.sessionId);
List<ACL> listACL = fixupACL(path, request.authInfo, setAclRequest.getAcl());
List<ACL> listACL = fixupACL(path, request.sessionId, request.authInfo, setAclRequest.getAcl());
nodeRecord = getRecordForPath(path);
zks.checkACL(request.cnxn, nodeRecord.acl, ZooDefs.Perms.ADMIN, request.authInfo, path, listACL);
newVersion = checkAndIncVersion(nodeRecord.stat.getAversion(), setAclRequest.getVersion(), path);
Expand Down Expand Up @@ -661,7 +661,7 @@ private void pRequest2TxnCreate(int type, Request request, Record record) throws
validateCreateRequest(path, createMode, request, ttl);
String parentPath = validatePathForCreate(path, request.sessionId);

List<ACL> listACL = fixupACL(path, request.authInfo, acl);
List<ACL> listACL = fixupACL(path, request.sessionId, request.authInfo, acl);
ChangeRecord parentRecord = getRecordForPath(parentPath);

zks.checkACL(request.cnxn, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo, path, listACL);
Expand Down Expand Up @@ -957,12 +957,16 @@ private void validateCreateRequest(String path, CreateMode createMode, Request r
}
}

private List<ACL> fixupACL(String path, List<Id> authInfo, List<ACL> acls) throws KeeperException.InvalidACLException {
private List<ACL> fixupACL(String path, long sessionId, List<Id> authInfo, List<ACL> acls) throws KeeperException.InvalidACLException {
FixupContext context = new FixupContext() {
public String getPath() {
return path;
}

public long getSessionId() {
return sessionId;
}

public List<Id> getAuthInfo() {
return authInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ private String effectiveACLPath(Request request) throws KeeperException.BadArgum
* we only care about it being well-formed (and if it isn't, an
* exception will be raised).
*/
ACLs.fixupACL(path, request.authInfo, acl);
ACLs.fixupACL(path, request.sessionId, request.authInfo, acl);
}

return path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ public static void initialize() throws InitializationException {
* @return verified and expanded ACLs
* @throws KeeperException.InvalidACLException
*/
public static List<ACL> fixupACL(String path, List<Id> authInfo, List<ACL> acls) throws KeeperException.InvalidACLException {
public static List<ACL> fixupACL(String path, long sessionId, List<Id> authInfo, List<ACL> acls) throws KeeperException.InvalidACLException {
FixupContext context = new FixupContext() {
public String getPath() {
return path;
}

public long getSessionId() {
return sessionId;
}

public List<Id> getAuthInfo() {
return authInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
public interface FixupContext {
String getPath();

long getSessionId();

List<Id> getAuthInfo();

byte[] loadConstraints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public String getPath() {
return path;
}

public long getSessionId() {
return -1;
}

public List<Id> getAuthInfo() {
return ids;
}
Expand Down

0 comments on commit de2823a

Please sign in to comment.