/** * 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 {@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()); } }