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 @@ -56,15 +56,15 @@
* </ul>
*/
@Immutable
public class OzoneAcl {
public final class OzoneAcl {

private static final String ACL_SCOPE_REGEX = ".*\\[(ACCESS|DEFAULT)\\]";
/**
* Link bucket default acl defined [world::rw]
* which is similar to Linux POSIX symbolic.
*/
public static final OzoneAcl LINK_BUCKET_DEFAULT_ACL =
new OzoneAcl(IAccessAuthorizer.ACLIdentityType.WORLD, "", ACCESS, READ, WRITE);
OzoneAcl.of(IAccessAuthorizer.ACLIdentityType.WORLD, "", ACCESS, READ, WRITE);

private final ACLIdentityType type;
private final String name;
Expand All @@ -77,12 +77,12 @@ public class OzoneAcl {
@JsonIgnore
private final Supplier<Integer> hashCodeMethod;

public OzoneAcl(ACLIdentityType type, String name, AclScope scope, ACLType... acls) {
this(type, name, scope, toInt(acls));
public static OzoneAcl of(ACLIdentityType type, String name, AclScope scope, ACLType... acls) {
return new OzoneAcl(type, name, scope, toInt(acls));
}

public OzoneAcl(ACLIdentityType type, String name, AclScope scope, EnumSet<ACLType> acls) {
this(type, name, scope, toInt(acls));
public static OzoneAcl of(ACLIdentityType type, String name, AclScope scope, EnumSet<ACLType> acls) {
return new OzoneAcl(type, name, scope, toInt(acls));
}

private OzoneAcl(ACLIdentityType type, String name, AclScope scope, int acls) {
Expand Down Expand Up @@ -194,7 +194,7 @@ public static OzoneAcl parseAcl(String acl)

// TODO : Support sanitation of these user names by calling into
// userAuth Interface.
return new OzoneAcl(aclType, parts[1], aclScope, acls);
return OzoneAcl.of(aclType, parts[1], aclScope, acls);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public static List<OzoneAcl> getDefaultAclList(UserGroupInformation ugi, OzoneCo
}
List<OzoneAcl> listOfAcls = new ArrayList<>();
// User ACL.
listOfAcls.add(new OzoneAcl(USER, ugi.getShortUserName(), ACCESS, userRights));
listOfAcls.add(OzoneAcl.of(USER, ugi.getShortUserName(), ACCESS, userRights));
try {
String groupName = ugi.getPrimaryGroupName();
listOfAcls.add(new OzoneAcl(GROUP, groupName, ACCESS, groupRights));
listOfAcls.add(OzoneAcl.of(GROUP, groupName, ACCESS, groupRights));
} catch (IOException e) {
// do nothing, since user has the permission, user can add ACL for selected groups later.
LOG.warn("Failed to get primary group from user {}", ugi);
Expand All @@ -82,10 +82,10 @@ public static List<OzoneAcl> getDefaultAclList(UserGroupInformation ugi, OzoneCo
public static List<OzoneAcl> getAclList(UserGroupInformation ugi, ACLType userPrivilege, ACLType groupPrivilege) {
List<OzoneAcl> listOfAcls = new ArrayList<>();
// User ACL.
listOfAcls.add(new OzoneAcl(USER, ugi.getShortUserName(), ACCESS, userPrivilege));
listOfAcls.add(OzoneAcl.of(USER, ugi.getShortUserName(), ACCESS, userPrivilege));
try {
String groupName = ugi.getPrimaryGroupName();
listOfAcls.add(new OzoneAcl(GROUP, groupName, ACCESS, groupPrivilege));
listOfAcls.add(OzoneAcl.of(GROUP, groupName, ACCESS, groupPrivilege));
} catch (IOException e) {
// do nothing, since user has the permission, user can add ACL for selected groups later.
LOG.warn("Failed to get primary group from user {}", ugi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testClone() {
.setCreationTime(Time.now())
.setIsVersionEnabled(false)
.setStorageType(StorageType.ARCHIVE)
.setAcls(Collections.singletonList(new OzoneAcl(
.setAcls(Collections.singletonList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER,
"defaultUser",
OzoneAcl.AclScope.ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL
Expand All @@ -91,7 +91,7 @@ public void testClone() {
+ " to be equal");

/* Reset acl & check not equal. */
omBucketInfo.setAcls(Collections.singletonList(new OzoneAcl(
omBucketInfo.setAcls(Collections.singletonList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER,
"newUser",
OzoneAcl.AclScope.ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL
Expand All @@ -108,7 +108,7 @@ public void testClone() {
cloneBucketInfo.getAcls().get(0));

/* Remove acl & check. */
omBucketInfo.removeAcl(new OzoneAcl(
omBucketInfo.removeAcl(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER,
"newUser",
OzoneAcl.AclScope.ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL
Expand All @@ -124,7 +124,7 @@ public void getProtobufMessageEC() {
OmBucketInfo.newBuilder().setBucketName("bucket").setVolumeName("vol1")
.setCreationTime(Time.now()).setIsVersionEnabled(false)
.setStorageType(StorageType.ARCHIVE).setAcls(Collections
.singletonList(new OzoneAcl(
.singletonList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER,
"defaultUser", OzoneAcl.AclScope.ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL
))).build();
Expand All @@ -143,7 +143,7 @@ public void getProtobufMessageEC() {
.setCreationTime(Time.now())
.setIsVersionEnabled(false)
.setStorageType(StorageType.ARCHIVE)
.setAcls(Collections.singletonList(new OzoneAcl(
.setAcls(Collections.singletonList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER,
"defaultUser", OzoneAcl.AclScope.ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL
)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void createdAndTest(boolean isMPU) {
}
}

key.setAcls(Arrays.asList(new OzoneAcl(
key.setAcls(Arrays.asList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER, "user1",
ACCESS, IAccessAuthorizer.ACLType.WRITE)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public void testClone() throws Exception {
.setObjectID(1L).setUpdateID(1L).setQuotaInBytes(Long.MAX_VALUE)
.addMetadata("key1", "value1").addMetadata("key2", "value2")
.addOzoneAcls(
new OzoneAcl(IAccessAuthorizer.ACLIdentityType.USER, "user1",
OzoneAcl.of(IAccessAuthorizer.ACLIdentityType.USER, "user1",
ACCESS, IAccessAuthorizer.ACLType.READ)).build();

OmVolumeArgs cloneVolumeArgs = omVolumeArgs.copyObject();

assertEquals(omVolumeArgs, cloneVolumeArgs);

// add user acl to write.
omVolumeArgs.addAcl(new OzoneAcl(
omVolumeArgs.addAcl(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER, "user1",
ACCESS, IAccessAuthorizer.ACLType.WRITE));

Expand All @@ -60,7 +60,7 @@ public void testClone() throws Exception {
omVolumeArgs.getAcls().get(0));

// Set user acl to Write_ACL.
omVolumeArgs.setAcls(Collections.singletonList(new OzoneAcl(
omVolumeArgs.setAcls(Collections.singletonList(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER, "user1",
ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL)));

Expand All @@ -74,7 +74,7 @@ public void testClone() throws Exception {
assertEquals(cloneVolumeArgs.getAcls().get(0),
omVolumeArgs.getAcls().get(0));

omVolumeArgs.removeAcl(new OzoneAcl(
omVolumeArgs.removeAcl(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER, "user1",
ACCESS, IAccessAuthorizer.ACLType.WRITE_ACL));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public class TestOzoneAclUtil {
private static final List<OzoneAcl> DEFAULT_ACLS =
getDefaultAcls();

private static final OzoneAcl USER1 = new OzoneAcl(USER, "user1",
private static final OzoneAcl USER1 = OzoneAcl.of(USER, "user1",
ACCESS, ACLType.READ_ACL);

private static final OzoneAcl GROUP1 = new OzoneAcl(GROUP, "group1",
private static final OzoneAcl GROUP1 = OzoneAcl.of(GROUP, "group1",
ACCESS, ACLType.ALL);

@Test
Expand All @@ -59,7 +59,7 @@ public void testAddAcl() throws IOException {

// Add new permission to existing acl entry.
OzoneAcl oldAcl = currentAcls.get(0);
OzoneAcl newAcl = new OzoneAcl(oldAcl.getType(), oldAcl.getName(),
OzoneAcl newAcl = OzoneAcl.of(oldAcl.getType(), oldAcl.getName(),
ACCESS, ACLType.READ_ACL);

addAndVerifyAcl(currentAcls, newAcl, true, DEFAULT_ACLS.size());
Expand Down Expand Up @@ -91,7 +91,7 @@ public void testRemoveAcl() {

// Add new permission to existing acl entru.
OzoneAcl oldAcl = currentAcls.get(0);
OzoneAcl newAcl = new OzoneAcl(oldAcl.getType(), oldAcl.getName(),
OzoneAcl newAcl = OzoneAcl.of(oldAcl.getType(), oldAcl.getName(),
ACCESS, ACLType.READ_ACL);

// Remove non existing acl entry
Expand Down Expand Up @@ -185,12 +185,12 @@ private static List<OzoneAcl> getDefaultAcls() {
IAccessAuthorizer.ACLType[] userRights = aclConfig.getUserDefaultRights();
IAccessAuthorizer.ACLType[] groupRights = aclConfig.getGroupDefaultRights();

OzoneAclUtil.addAcl(ozoneAcls, new OzoneAcl(USER,
OzoneAclUtil.addAcl(ozoneAcls, OzoneAcl.of(USER,
ugi.getUserName(), ACCESS, userRights));
//Group ACLs of the User
List<String> userGroups = Arrays.asList(ugi.getGroupNames());
userGroups.stream().forEach((group) -> OzoneAclUtil.addAcl(ozoneAcls,
new OzoneAcl(GROUP, group, ACCESS, groupRights)));
OzoneAcl.of(GROUP, group, ACCESS, groupRights)));
return ozoneAcls;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ void testSharedTmpDir() throws IOException {
VolumeArgs volumeArgs = VolumeArgs.newBuilder()
.setAdmin("admin")
.setOwner("admin")
.addAcl(new OzoneAcl(ACLIdentityType.WORLD, "", ACCESS, aclRights))
.addAcl(new OzoneAcl(ACLIdentityType.USER, "admin", ACCESS, userRights))
.addAcl(OzoneAcl.of(ACLIdentityType.WORLD, "", ACCESS, aclRights))
.addAcl(OzoneAcl.of(ACLIdentityType.USER, "admin", ACCESS, userRights))
.setQuotaInNamespace(1000)
.setQuotaInBytes(Long.MAX_VALUE).build();
// Sanity check
Expand Down Expand Up @@ -1240,8 +1240,8 @@ void testSharedTmpDir() throws IOException {
// bucket acls have all access to admin and read+write+list access to world
BucketArgs bucketArgs = new BucketArgs.Builder()
.setOwner("admin")
.addAcl(new OzoneAcl(ACLIdentityType.WORLD, "", ACCESS, READ, WRITE, LIST))
.addAcl(new OzoneAcl(ACLIdentityType.USER, "admin", ACCESS, userRights))
.addAcl(OzoneAcl.of(ACLIdentityType.WORLD, "", ACCESS, READ, WRITE, LIST))
.addAcl(OzoneAcl.of(ACLIdentityType.USER, "admin", ACCESS, userRights))
.setQuotaInNamespace(1000)
.setQuotaInBytes(Long.MAX_VALUE).build();

Expand Down Expand Up @@ -1300,7 +1300,7 @@ void testTempMount() throws IOException {
OzoneAclConfig aclConfig = conf.getObject(OzoneAclConfig.class);
ACLType[] userRights = aclConfig.getUserDefaultRights();
// Construct ACL for world access
OzoneAcl aclWorldAccess = new OzoneAcl(ACLIdentityType.WORLD, "",
OzoneAcl aclWorldAccess = OzoneAcl.of(ACLIdentityType.WORLD, "",
ACCESS, userRights);
// Construct VolumeArgs
VolumeArgs volumeArgs = VolumeArgs.newBuilder()
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void testNonPrivilegedUserMkdirCreateBucket() throws IOException {
OzoneAclConfig aclConfig = conf.getObject(OzoneAclConfig.class);
ACLType[] userRights = aclConfig.getUserDefaultRights();
// Construct ACL for world access
OzoneAcl aclWorldAccess = new OzoneAcl(ACLIdentityType.WORLD, "",
OzoneAcl aclWorldAccess = OzoneAcl.of(ACLIdentityType.WORLD, "",
ACCESS, userRights);
// Construct VolumeArgs, set ACL to world access
VolumeArgs volumeArgs = VolumeArgs.newBuilder()
Expand Down
Loading