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

This commit is contained in:
Bharat Viswanadham 2019-08-05 10:25:18 -07:00 committed by Xiaoyu Yao
parent 71aad60e51
commit c589983e9c
2 changed files with 39 additions and 7 deletions

View File

@ -542,6 +542,38 @@ public abstract class TestOzoneRpcClientAbstract {
Assert.assertTrue(!bucket.getAcls().contains(acls.get(0))); 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 @Test
public void testSetBucketVersioning() public void testSetBucketVersioning()
throws IOException, OzoneException { throws IOException, OzoneException {

View File

@ -505,6 +505,7 @@ public class BucketManagerImpl implements BucketManager {
BUCKET_NOT_FOUND); BUCKET_NOT_FOUND);
} }
boolean removed = false;
// When we are removing subset of rights from existing acl. // When we are removing subset of rights from existing acl.
for(OzoneAcl a: bucketInfo.getAcls()) { for(OzoneAcl a: bucketInfo.getAcls()) {
if(a.getName().equals(acl.getName()) && if(a.getName().equals(acl.getName()) &&
@ -515,20 +516,21 @@ public class BucketManagerImpl implements BucketManager {
if (bits.equals(ZERO_BITSET)) { if (bits.equals(ZERO_BITSET)) {
return false; return false;
} }
bits = (BitSet) acl.getAclBitSet().clone();
bits.and(a.getAclBitSet());
a.getAclBitSet().xor(bits); a.getAclBitSet().xor(bits);
if(a.getAclBitSet().equals(ZERO_BITSET)) { if(a.getAclBitSet().equals(ZERO_BITSET)) {
bucketInfo.getAcls().remove(a); bucketInfo.getAcls().remove(a);
} }
removed = true;
break; break;
} else {
return false;
} }
} }
if (removed) {
metadataManager.getBucketTable().put(dbBucketKey, bucketInfo); metadataManager.getBucketTable().put(dbBucketKey, bucketInfo);
}
return removed;
} catch (IOException ex) { } catch (IOException ex) {
if (!(ex instanceof OMException)) { if (!(ex instanceof OMException)) {
LOG.error("Remove acl operation failed for bucket:{}/{} acl:{}", LOG.error("Remove acl operation failed for bucket:{}/{} acl:{}",
@ -538,8 +540,6 @@ public class BucketManagerImpl implements BucketManager {
} finally { } finally {
metadataManager.getLock().releaseLock(BUCKET_LOCK, volume, bucket); metadataManager.getLock().releaseLock(BUCKET_LOCK, volume, bucket);
} }
return true;
} }
/** /**