/** * @return a copy of actions */ public AclActions getActions() { return new AclActions(mActions); }
/** * Creates a new builder where type is null, subject is an empty string, and no action is * permitted. */ public Builder() { mSubject = ""; mActions = new AclActions(); }
/** * Creates an empty extended ACL. */ public ExtendedACLEntries() { mNamedUserActions = new TreeMap<>(); mNamedGroupActions = new TreeMap<>(); mMaskActions = new AclActions(); }
/** * Creates a copy. * * @param other the object to copy */ public ExtendedACLEntries(ExtendedACLEntries other) { mNamedUserActions = new TreeMap<>(other.mNamedUserActions); mNamedGroupActions = new TreeMap<>(other.mNamedGroupActions); mMaskActions = new AclActions(other.mMaskActions); }
/** * @param actions the protobuf representation of {@link AclActions} * @return the {@link AclActions} decoded from the protobuf representation */ public static AclActions fromProto(Acl.AclActions actions) { AclActions ret = new AclActions(); for (Acl.AclAction action : actions.getActionsList()) { ret.add(fromProto(action)); } return ret; }
/** * Removes the specified entry. A base entry is not allowed to be removed. * * @param entry the entry to be removed */ public void removeEntry(AclEntry entry) { switch (entry.getType()) { case NAMED_USER: mNamedUserActions.remove(entry.getSubject()); return; case NAMED_GROUP: mNamedGroupActions.remove(entry.getSubject()); return; case MASK: if (hasExtended()) { throw new IllegalStateException( "Deleting the mask for extended ACLs is not allowed. entry: " + entry); } else { mMaskActions = new AclActions(); } return; case OWNING_USER: // fall through case OWNING_GROUP: // fall through case OTHER: throw new IllegalStateException( "Deleting base entry is not allowed. entry: " + entry); default: throw new IllegalStateException("Unknown ACL entry type: " + entry.getType()); } }
return new AclActions(getOwningUserActions()); AclActions result = new AclActions(actions); result.mask(mExtendedEntries.mMaskActions); return result; AclActions groupActions = new AclActions(); if (groups.contains(mOwningGroup)) { isGroupKnown = true;
/** * Update the mask to be the union of owning group entry, named user entry and named group entry. * @param groupActions the group entry to be integrated into the mask */ public void updateMask(AclActions groupActions) { AclActions result = new AclActions(groupActions); for (Map.Entry<String, AclActions> kv : mNamedUserActions.entrySet()) { AclActions userAction = kv.getValue(); result.merge(userAction); for (AclAction action : AclAction.values()) { if (result.contains(action) || userAction.contains(action)) { result.add(action); } } } for (Map.Entry<String, AclActions> kv : mNamedGroupActions.entrySet()) { AclActions userAction = kv.getValue(); result.merge(userAction); for (AclAction action : AclAction.values()) { if (result.contains(action) || userAction.contains(action)) { result.add(action); } } } mMaskActions = result; }
/** * Tests constructor contract. */ @Test public void constructor() { AclActions actions = new AclActions(); Assert.assertTrue(actions.getActions().isEmpty()); AclActions copiedActions = new AclActions(actions); copiedActions.add(AclAction.READ); Assert.assertEquals(1, copiedActions.getActions().size()); Assert.assertEquals(0, actions.getActions().size()); }
/** * @return the set of {@link AclAction}s implied by this mode */ public AclActions toAclActions() { AclActions actions = new AclActions(); if (imply(READ)) { actions.add(AclAction.READ); } if (imply(WRITE)) { actions.add(AclAction.WRITE); } if (imply(EXECUTE)) { actions.add(AclAction.EXECUTE); } return actions; } }
/** * Tests {@link Mode.Bits#toAclActionSet()}. */ @Test public void toAclActions() { for (Mode.Bits bits : Mode.Bits.values()) { Assert.assertEquals(bits, new AclActions(bits.toAclActionSet()).toModeBits()); } } }
/** * Tests {@link AclActions#updateByModeBits(Mode.Bits)}. */ @Test public void updateByModeBits() { AclActions actions = new AclActions(); actions.updateByModeBits(Mode.Bits.NONE); Assert.assertEquals(Mode.Bits.NONE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.READ); Assert.assertEquals(Mode.Bits.READ, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.WRITE); Assert.assertEquals(Mode.Bits.WRITE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.EXECUTE); Assert.assertEquals(Mode.Bits.EXECUTE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.READ_WRITE); Assert.assertEquals(Mode.Bits.READ_WRITE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.READ_EXECUTE); Assert.assertEquals(Mode.Bits.READ_EXECUTE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.WRITE_EXECUTE); Assert.assertEquals(Mode.Bits.WRITE_EXECUTE, actions.toModeBits()); actions = new AclActions(); actions.updateByModeBits(Mode.Bits.ALL); Assert.assertEquals(Mode.Bits.ALL, actions.toModeBits()); }
/** * Tests {@link AclActions#merge(AclActions)}. */ @Test public void merge() { AclActions actions = new AclActions(); Assert.assertEquals(Mode.Bits.NONE, actions.toModeBits()); // Merge empty actions. actions.merge(new AclActions()); Assert.assertEquals(Mode.Bits.NONE, actions.toModeBits()); // Merge read and write actions. AclActions readWrite = new AclActions(); readWrite.add(AclAction.READ); readWrite.add(AclAction.WRITE); actions.merge(readWrite); Assert.assertEquals(Mode.Bits.READ_WRITE, actions.toModeBits()); // Merge execute action. AclActions execute = new AclActions(); execute.add(AclAction.EXECUTE); actions.merge(execute); Assert.assertEquals(Mode.Bits.ALL, actions.toModeBits()); } }
AclActions actions = new AclActions(); Assert.assertEquals(Mode.Bits.NONE, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.READ); Assert.assertEquals(Mode.Bits.READ, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.WRITE); Assert.assertEquals(Mode.Bits.WRITE, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.EXECUTE); Assert.assertEquals(Mode.Bits.EXECUTE, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.READ); actions.add(AclAction.WRITE); Assert.assertEquals(Mode.Bits.READ_WRITE, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.READ); actions.add(AclAction.EXECUTE); Assert.assertEquals(Mode.Bits.READ_EXECUTE, actions.toModeBits()); actions = new AclActions(); actions.add(AclAction.WRITE); actions.add(AclAction.EXECUTE); Assert.assertEquals(Mode.Bits.WRITE_EXECUTE, actions.toModeBits());
AclActions groupAction = new AclActions(); groupAction.updateByModeBits(defaultMode.getGroupBits()); mask.mask(groupAction);
/** * Tests {@link AclActions#contains(AclAction)}. */ @Test public void contains() { AclActions actions = new AclActions(); Assert.assertFalse(actions.contains(AclAction.READ)); Assert.assertFalse(actions.contains(AclAction.WRITE)); Assert.assertFalse(actions.contains(AclAction.EXECUTE)); actions.add(AclAction.READ); Assert.assertTrue(actions.contains(AclAction.READ)); actions.add(AclAction.WRITE); Assert.assertTrue(actions.contains(AclAction.WRITE)); actions.add(AclAction.EXECUTE); Assert.assertTrue(actions.contains(AclAction.EXECUTE)); }