GroupImpl extends AuthorizableImpl implements Group { @Override public boolean addMember(@NotNull Authorizable authorizable) throws RepositoryException { if (!isValidAuthorizableImpl(authorizable)) { log.warn("Invalid Authorizable: {}", authorizable); return false; } AuthorizableImpl authorizableImpl = ((AuthorizableImpl) authorizable); if (isEveryone() || authorizableImpl.isEveryone()) { log.debug("Attempt to add member to everyone group or create membership for it."); return false; } String memberID = authorizable.getID(); if (authorizableImpl.isGroup()) { if (getID().equals(memberID)) { String msg = "Attempt to add a group as member of itself (" + getID() + ")."; log.debug(msg); return false; } if (isCyclicMembership((Group) authorizable)) { String msg = "Cyclic group membership detected for group " + getID() + " and member " + authorizable.getID(); throw new ConstraintViolationException(msg); } } boolean success = getMembershipProvider().addMember(getTree(), authorizableImpl.getTree()); if (success) { getUserManager().onGroupUpdate(this, false, authorizable); } return success; } GroupImpl(String id, Tree tree, UserManagerImpl userManager); @Override boolean isGroup(); @NotNull @Override Principal getPrincipal(); @NotNull @Override Iterator<Authorizable> getDeclaredMembers(); @NotNull @Override Iterator<Authorizable> getMembers(); @Override boolean isDeclaredMember(@NotNull Authorizable authorizable); @Override boolean isMember(@NotNull Authorizable authorizable); @Override boolean addMember(@NotNull Authorizable authorizable); @NotNull @Override Set<String> addMembers(@NotNull String... memberIds); @Override boolean removeMember(@NotNull Authorizable authorizable); @NotNull @Override Set<String> removeMembers(@NotNull String... memberIds);  }
@Test public void testAddMemberInvalidAuthorizable() throws Exception { assertFalse(group.addMember(Mockito.mock(Authorizable.class))); }
@Test public void testAddMemberEveryone() throws Exception { Group everyoneGroup = uMgr.createGroup(EveryonePrincipal.getInstance()); assertFalse(group.addMember(everyoneGroup)); }
@Test public void testAddMemberItself() throws Exception { assertFalse(group.addMember(group)); }
@Test(expected = ConstraintViolationException.class) public void testAddMemberWithCycle() throws Exception { Group g2 = uMgr.createGroup("group2"); g2.addMember(group); group.addMember(g2); }
@Test public void testImpactOfOak8054AddingMembers() throws Exception { Tree groupTree = root.getTree(group.getPath()); groupTree.setProperty(REP_MEMBERS, ImmutableList.of(new UserProvider(root, ConfigurationParameters.EMPTY).getContentID(getTestUser().getID())), Type.STRINGS); root.commit(); group.addMember(uMgr.createUser("userid", null)); root.commit(); groupTree = root.getTree(group.getPath()); PropertyState membersProp = groupTree.getProperty(REP_MEMBERS); assertEquals(Type.WEAKREFERENCES, membersProp.getType()); assertEquals(2, membersProp.count()); }