Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-1893. Fix bug in removeAcl in Bucket. #1216

Merged
merged 1 commit into from Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -542,6 +542,38 @@ public void testRemoveBucketAcl()
Assert.assertTrue(!bucket.getAcls().contains(acls.get(0)));
}

@Test
public void testRemoveBucketAclUsingRpcClientRemoveAcl()
throws IOException {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
OzoneAcl userAcl = new OzoneAcl(USER, "test",
ACLType.ALL, ACCESS);
List<OzoneAcl> acls = new ArrayList<>();
acls.add(userAcl);
acls.add(new OzoneAcl(USER, "test1",
ACLType.ALL, ACCESS));
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
BucketArgs.Builder builder = BucketArgs.newBuilder();
builder.setAcls(acls);
volume.createBucket(bucketName, builder.build());
OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder()
.setBucketName(bucketName)
.setVolumeName(volumeName)
.setStoreType(OzoneObj.StoreType.OZONE)
.setResType(OzoneObj.ResourceType.BUCKET).build();

// Remove the 2nd acl added to the list.
boolean remove = store.removeAcl(ozoneObj, acls.get(1));
Assert.assertTrue(remove);
Assert.assertFalse(store.getAcl(ozoneObj).contains(acls.get(1)));

remove = store.removeAcl(ozoneObj, acls.get(0));
Assert.assertTrue(remove);
Assert.assertFalse(store.getAcl(ozoneObj).contains(acls.get(0)));
}

@Test
public void testSetBucketVersioning()
throws IOException, OzoneException {
Expand Down
Expand Up @@ -505,6 +505,7 @@ public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
BUCKET_NOT_FOUND);
}

boolean removed = false;
// When we are removing subset of rights from existing acl.
for(OzoneAcl a: bucketInfo.getAcls()) {
if(a.getName().equals(acl.getName()) &&
Expand All @@ -515,20 +516,21 @@ public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
if (bits.equals(ZERO_BITSET)) {
return false;
}
bits = (BitSet) acl.getAclBitSet().clone();
bits.and(a.getAclBitSet());

a.getAclBitSet().xor(bits);

if(a.getAclBitSet().equals(ZERO_BITSET)) {
bucketInfo.getAcls().remove(a);
}
removed = true;
break;
} else {
return false;
}
}

metadataManager.getBucketTable().put(dbBucketKey, bucketInfo);
if (removed) {
metadataManager.getBucketTable().put(dbBucketKey, bucketInfo);
}
return removed;
} catch (IOException ex) {
if (!(ex instanceof OMException)) {
LOG.error("Remove acl operation failed for bucket:{}/{} acl:{}",
Expand All @@ -538,8 +540,6 @@ public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
} finally {
metadataManager.getLock().releaseLock(BUCKET_LOCK, volume, bucket);
}

return true;
}

/**
Expand Down