Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public long getQuotaInNamespace() {
* for the bucket.
* @throws IOException
*/
public boolean addAcls(OzoneAcl addAcl) throws IOException {
public boolean addAcl(OzoneAcl addAcl) throws IOException {
return proxy.addAcl(ozoneObj, addAcl);
}

Expand All @@ -396,10 +396,21 @@ public boolean addAcls(OzoneAcl addAcl) throws IOException {
* removed does not exist for the bucket.
* @throws IOException
*/
public boolean removeAcls(OzoneAcl removeAcl) throws IOException {
public boolean removeAcl(OzoneAcl removeAcl) throws IOException {
return proxy.removeAcl(ozoneObj, removeAcl);
}

/**
* Acls to be set for given Ozone object. This operations reset ACL for
* given object to list of ACLs provided in argument.
* @param acls List of acls.
*
* @throws IOException if there is error.
* */
public boolean setAcl(List<OzoneAcl> acls) throws IOException {
return proxy.setAcl(ozoneObj, acls);
}

/**
* Sets/Changes the storage type of the bucket.
* @param newStorageType Storage type to be set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.NoSuchElementException;

import org.apache.commons.collections.ListUtils;
import org.apache.hadoop.hdds.client.OzoneQuota;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
Expand All @@ -35,6 +36,8 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;

import static org.apache.hadoop.ozone.OzoneConsts.QUOTA_RESET;

Expand Down Expand Up @@ -89,6 +92,8 @@ public class OzoneVolume extends WithMetadata {

private int listCacheSize;

private OzoneObj ozoneObj;

/**
* Constructs OzoneVolume instance.
* @param conf Configuration object.
Expand Down Expand Up @@ -122,6 +127,10 @@ public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
modificationTime = Instant.ofEpochSecond(
this.creationTime.getEpochSecond(), this.creationTime.getNano());
}
this.ozoneObj = OzoneObjInfo.Builder.newBuilder()
.setVolumeName(name)
.setResType(OzoneObj.ResourceType.VOLUME)
.setStoreType(OzoneObj.StoreType.OZONE).build();
}

/**
Expand Down Expand Up @@ -261,7 +270,53 @@ public Instant getModificationTime() {
* @return aclMap
*/
public List<OzoneAcl> getAcls() {
return acls;
return ListUtils.unmodifiableList(acls);
}

/**
* Adds ACLs to the volume.
* @param addAcl ACL to be added
* @return true - if acl is successfully added, false if acl already exists
* for the bucket.
* @throws IOException
*/
public boolean addAcl(OzoneAcl addAcl) throws IOException {
boolean added = proxy.addAcl(ozoneObj, addAcl);
if (added) {
acls.add(addAcl);
}
return added;
}

/**
* Remove acl for Ozone object. Return true if acl is removed successfully
* else false.
* @param acl Ozone acl to be removed.
*
* @throws IOException if there is error.
* */
public boolean removeAcl(OzoneAcl acl) throws IOException {
boolean removed = proxy.removeAcl(ozoneObj, acl);
if (removed) {
acls.remove(acl);
}
return removed;
}

/**
* Acls to be set for given Ozone object. This operations reset ACL for
* given object to list of ACLs provided in argument.
* @param aclList List of acls.
*
* @throws IOException if there is error.
* */
public boolean setAcl(List<OzoneAcl> aclList) throws IOException {
boolean reset = proxy.setAcl(ozoneObj, aclList);
if (reset) {
acls.clear();
acls.addAll(aclList);
}
return reset;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ public static List<OzoneAcl> getAclList(String userName,
return listOfAcls;
}

/**
* Helper function to get acl list for one user/group.
*
* @param identityName
* @param type
* @param aclList
* @return list of OzoneAcls
* */
public static List<OzoneAcl> filterAclList(String identityName,
IAccessAuthorizer.ACLIdentityType type, List<OzoneAcl> aclList) {

if (aclList == null || aclList.isEmpty()) {
return new ArrayList<>();
}

List retList = aclList.stream().filter(acl -> acl.getType() == type
&& acl.getName().equals(identityName)).collect(Collectors.toList());
return retList;
}

/**
* Check if acl right requested for given RequestContext exist
* in provided acl list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public static String getAclString(ACLType acl) {
throw new IllegalArgumentException("ACL right is not recognized");
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public void testAddBucketAcl()
acls.add(new OzoneAcl(USER, "test", ACLType.ALL, ACCESS));
OzoneBucket bucket = volume.getBucket(bucketName);
for (OzoneAcl acl : acls) {
assertTrue(bucket.addAcls(acl));
assertTrue(bucket.addAcl(acl));
}
OzoneBucket newBucket = volume.getBucket(bucketName);
Assert.assertEquals(bucketName, newBucket.getName());
Expand All @@ -672,7 +672,7 @@ public void testRemoveBucketAcl()
volume.createBucket(bucketName, builder.build());
OzoneBucket bucket = volume.getBucket(bucketName);
for (OzoneAcl acl : acls) {
assertTrue(bucket.removeAcls(acl));
assertTrue(bucket.removeAcl(acl));
}
OzoneBucket newBucket = volume.getBucket(bucketName);
Assert.assertEquals(bucketName, newBucket.getName());
Expand Down Expand Up @@ -2262,10 +2262,10 @@ public void testMultipartUploadWithACL() throws Exception {
OzoneAcl acl2 = new OzoneAcl(USER, "Friday", ACLType.ALL, DEFAULT);
OzoneAcl acl3 = new OzoneAcl(USER, "Jan", ACLType.ALL, ACCESS);
OzoneAcl acl4 = new OzoneAcl(USER, "Feb", ACLType.ALL, ACCESS);
bucket.addAcls(acl1);
bucket.addAcls(acl2);
bucket.addAcls(acl3);
bucket.addAcls(acl4);
bucket.addAcl(acl1);
bucket.addAcl(acl2);
bucket.addAcl(acl3);
bucket.addAcl(acl4);

doMultipartUpload(bucket, keyName, (byte)98);
OzoneObj keyObj = OzoneObjInfo.Builder.newBuilder()
Expand Down
Loading