/** * Deletes an owner. If this is the last owner in the ACL, an exception is raised. *<P> * The caller principal must be an owner of the ACL in order to invoke this method. * * @param caller the principal invoking this method. It must be an owner * of the ACL. * @param owner the owner to be removed from the list of owners. * @return true if successful, false if owner is already an owner. * @exception NotOwnerException if the caller principal is not an owner * of the ACL. * @exception LastOwnerException if there is only one owner left, so that * deleteOwner would leave the ACL owner-less. */ public boolean deleteOwner(Principal caller, Principal owner) throws NotOwnerException,LastOwnerException { if (!ownerList.contains(caller)) throw new NotOwnerException(); if (!ownerList.contains(owner)){ return false; } else { if (ownerList.size() == 1) throw new LastOwnerException(); ownerList.removeElement(owner); return true; } }
@Test public void testCreateCloudAclEntrySetWithAUserOwnerWillNotAddTheSameOwnerMoreThanOnce() throws NotOwnerException, LastOwnerException { TestUserImpl user1 = new TestUserImpl("user1"); TestUserImpl user2 = new TestUserImpl("user2"); CloudAclEntrySet cloudAclEntrySet = new CloudAclEntrySet(Sets.newHashSet(user1, user2)); Assert.assertTrue(cloudAclEntrySet.isOwner(user1)); Assert.assertTrue(cloudAclEntrySet.isOwner(user2)); Assert.assertEquals(2, cloudAclEntrySet.getOwners().size()); Assert.assertFalse(cloudAclEntrySet.addOwner(user1, user2)); Assert.assertEquals(2, cloudAclEntrySet.getOwners().size()); TestUserImpl user3 = new TestUserImpl("user3"); Assert.assertTrue(cloudAclEntrySet.addOwner(user1, user3)); Assert.assertTrue(cloudAclEntrySet.isOwner(user1)); Assert.assertTrue(cloudAclEntrySet.isOwner(user2)); Assert.assertTrue(cloudAclEntrySet.isOwner(user3)); Assert.assertEquals(3, cloudAclEntrySet.getOwners().size()); }
/** * @tests java.security.acl.LastOwnerException#LastOwnerException() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "LastOwnerException", args = {} ) public void test_Constructor() { // Test for method java.security.acl.LastOwnerException() try { throw new LastOwnerException(); } catch (LastOwnerException e) { assertEquals("LastOwnerException.toString() should have been " + "'java.security.acl.LastOwnerException' but was " + e.toString(), "java.security.acl.LastOwnerException", e .toString()); } }
@Override public boolean deleteOwner(Principal caller, Principal owner) throws NotOwnerException, LastOwnerException { ownersLock.readLock().lock(); try { checkWriteAccess(caller); // Upgrade to a write lock ownersLock.readLock().unlock(); ownersLock.writeLock().lock(); boolean returnValue = false; try { // Cannot delete if this would violate the size constraint if (owners.contains(owner)) { if (owners.size() == 1) { throw new LastOwnerException(); } returnValue = owners.remove(owner); } } finally { // Downgrade back to a read lock ownersLock.readLock().lock(); ownersLock.writeLock().unlock(); } return returnValue; } finally { ownersLock.readLock().unlock(); } }
/** * @tests java.security.acl.LastOwnerException#LastOwnerException() */ public void test_Constructor() { // Test for method java.security.acl.LastOwnerException() try { throw new LastOwnerException(); } catch (LastOwnerException e) { assertEquals("LastOwnerException.toString() should have been " + "'java.security.acl.LastOwnerException' but was " + e.toString(), "java.security.acl.LastOwnerException", e .toString()); } }
public void testLastOwnerException() { assertNotNull(new LastOwnerException()); assertNull(new LastOwnerException().getMessage()); assertNull(new LastOwnerException().getCause()); }
/** * @tests java.security.acl.LastOwnerException#LastOwnerException() */ public void testLastOwnerException() { LastOwnerException ex = new LastOwnerException(); assertNull(ex.getMessage()); assertNull(ex.getCause()); }