|
@@ -44,6 +44,7 @@ import org.apache.zookeeper.proto.SetDataRequest;
|
|
|
import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord;
|
|
|
import org.apache.zookeeper.server.auth.AuthenticationProvider;
|
|
|
import org.apache.zookeeper.server.auth.ProviderRegistry;
|
|
|
+import org.apache.zookeeper.server.auth.ServerAuthenticationProvider;
|
|
|
import org.apache.zookeeper.server.quorum.Leader.XidRolloverException;
|
|
|
import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
|
|
@@ -285,14 +286,16 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
|
|
|
/**
|
|
|
* Grant or deny authorization to an operation on a node as a function of:
|
|
|
- *
|
|
|
- * @param zks: not used.
|
|
|
- * @param acl: set of ACLs for the node
|
|
|
- * @param perm: the permission that the client is requesting
|
|
|
- * @param ids: the credentials supplied by the client
|
|
|
+ * @param zks : the ZooKeeper server
|
|
|
+ * @param cnxn : the server connection
|
|
|
+ * @param acl : set of ACLs for the node
|
|
|
+ * @param perm : the permission that the client is requesting
|
|
|
+ * @param ids : the credentials supplied by the client
|
|
|
+ * @param path : the ZNode path
|
|
|
+ * @param setAcls : for set ACL operations, the list of ACLs being set. Otherwise null.
|
|
|
*/
|
|
|
- static void checkACL(ZooKeeperServer zks, List<ACL> acl, int perm,
|
|
|
- List<Id> ids) throws KeeperException.NoAuthException {
|
|
|
+ static void checkACL(ZooKeeperServer zks, ServerCnxn cnxn, List<ACL> acl, int perm, List<Id> ids,
|
|
|
+ String path, List<ACL> setAcls) throws KeeperException.NoAuthException {
|
|
|
if (skipACL) {
|
|
|
return;
|
|
|
}
|
|
@@ -316,12 +319,13 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
&& id.getId().equals("anyone")) {
|
|
|
return;
|
|
|
}
|
|
|
- AuthenticationProvider ap = ProviderRegistry.getProvider(id
|
|
|
+ ServerAuthenticationProvider ap = ProviderRegistry.getServerProvider(id
|
|
|
.getScheme());
|
|
|
if (ap != null) {
|
|
|
for (Id authId : ids) {
|
|
|
if (authId.getScheme().equals(id.getScheme())
|
|
|
- && ap.matches(authId.getId(), id.getId())) {
|
|
|
+ && ap.matches(new ServerAuthenticationProvider.ServerObjs(zks, cnxn),
|
|
|
+ new ServerAuthenticationProvider.MatchValues(path, authId.getId(), id.getId(), perm, setAcls))) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -398,7 +402,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
String parentPath = getParentPathAndValidate(path);
|
|
|
ChangeRecord parentRecord = getRecordForPath(parentPath);
|
|
|
ChangeRecord nodeRecord = getRecordForPath(path);
|
|
|
- checkACL(zks, parentRecord.acl, ZooDefs.Perms.DELETE, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, parentRecord.acl, ZooDefs.Perms.DELETE, request.authInfo, path, null);
|
|
|
checkAndIncVersion(nodeRecord.stat.getVersion(), deleteRequest.getVersion(), path);
|
|
|
if (nodeRecord.childCount > 0) {
|
|
|
throw new KeeperException.NotEmptyException(path);
|
|
@@ -417,7 +421,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
path = setDataRequest.getPath();
|
|
|
validatePath(path, request.sessionId);
|
|
|
nodeRecord = getRecordForPath(path);
|
|
|
- checkACL(zks, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo, path, null);
|
|
|
int newVersion = checkAndIncVersion(nodeRecord.stat.getVersion(), setDataRequest.getVersion(), path);
|
|
|
request.setTxn(new SetDataTxn(path, setDataRequest.getData(), newVersion));
|
|
|
nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid());
|
|
@@ -552,7 +556,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
}
|
|
|
|
|
|
nodeRecord = getRecordForPath(ZooDefs.CONFIG_NODE);
|
|
|
- checkACL(zks, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo, null, null);
|
|
|
request.setTxn(new SetDataTxn(ZooDefs.CONFIG_NODE, request.qv.toString().getBytes(), -1));
|
|
|
nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid());
|
|
|
nodeRecord.stat.setVersion(-1);
|
|
@@ -567,7 +571,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
validatePath(path, request.sessionId);
|
|
|
List<ACL> listACL = fixupACL(path, request.authInfo, setAclRequest.getAcl());
|
|
|
nodeRecord = getRecordForPath(path);
|
|
|
- checkACL(zks, nodeRecord.acl, ZooDefs.Perms.ADMIN, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, nodeRecord.acl, ZooDefs.Perms.ADMIN, request.authInfo, path, listACL);
|
|
|
newVersion = checkAndIncVersion(nodeRecord.stat.getAversion(), setAclRequest.getVersion(), path);
|
|
|
request.setTxn(new SetACLTxn(path, listACL, newVersion));
|
|
|
nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid());
|
|
@@ -622,7 +626,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
path = checkVersionRequest.getPath();
|
|
|
validatePath(path, request.sessionId);
|
|
|
nodeRecord = getRecordForPath(path);
|
|
|
- checkACL(zks, nodeRecord.acl, ZooDefs.Perms.READ, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, nodeRecord.acl, ZooDefs.Perms.READ, request.authInfo, path, null);
|
|
|
request.setTxn(new CheckVersionTxn(path, checkAndIncVersion(nodeRecord.stat.getVersion(),
|
|
|
checkVersionRequest.getVersion(), path)));
|
|
|
break;
|
|
@@ -664,7 +668,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
List<ACL> listACL = fixupACL(path, request.authInfo, acl);
|
|
|
ChangeRecord parentRecord = getRecordForPath(parentPath);
|
|
|
|
|
|
- checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo);
|
|
|
+ checkACL(zks, request.cnxn, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo, path, listACL);
|
|
|
int parentCVersion = parentRecord.stat.getCversion();
|
|
|
if (createMode.isSequential()) {
|
|
|
path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
|
|
@@ -973,8 +977,8 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
// authenticated ids of the requestor
|
|
|
boolean authIdValid = false;
|
|
|
for (Id cid : authInfo) {
|
|
|
- AuthenticationProvider ap =
|
|
|
- ProviderRegistry.getProvider(cid.getScheme());
|
|
|
+ ServerAuthenticationProvider ap =
|
|
|
+ ProviderRegistry.getServerProvider(cid.getScheme());
|
|
|
if (ap == null) {
|
|
|
LOG.error("Missing AuthenticationProvider for "
|
|
|
+ cid.getScheme());
|
|
@@ -987,7 +991,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
|
|
|
throw new KeeperException.InvalidACLException(path);
|
|
|
}
|
|
|
} else {
|
|
|
- AuthenticationProvider ap = ProviderRegistry.getProvider(id.getScheme());
|
|
|
+ ServerAuthenticationProvider ap = ProviderRegistry.getServerProvider(id.getScheme());
|
|
|
if (ap == null || !ap.isValid(id.getId())) {
|
|
|
throw new KeeperException.InvalidACLException(path);
|
|
|
}
|