Commit d0d4e77e authored by Jeff Burke's avatar Jeff Burke
Browse files

s1848: match the same principal types when removing a user member from a group.

parent b52469a9
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -91,20 +91,6 @@ public class RemoveGroupMemberAction extends AbstractGroupAction
        Group group = groupPersistence.getGroup(this.groupName);
        Group toRemove = new Group(this.groupMemberName);

//        boolean removedMember = false;
//        if (group.getGroupMembers().remove(toRemove))
//        {
//            removedMember = true;
//        }
//        if (group.getGroupAdmins().remove(toRemove))
//        {
//            removedMember = true;
//        }
//        if (!removedMember)
//        {
//            throw new GroupNotFoundException(this.groupMemberName);
//        }

        if (!group.getGroupMembers().remove(toRemove))
        {
            throw new GroupNotFoundException(this.groupMemberName);
+7 −11
Original line number Diff line number Diff line
@@ -99,26 +99,22 @@ public class RemoveUserMemberAction extends AbstractGroupAction
    public void doAction() throws Exception
    {
        Group group = groupPersistence.getGroup(this.groupName);

        Principal userPrincipal = AuthenticationUtil.createPrincipal(this.userID, this.userIDType);
        User<Principal> toRemove = new User(userPrincipal);
        User<Principal> user = getUserPersistence().getAugmentedUser(userPrincipal);
        Set<X500Principal> x500Principals = user.getIdentities(X500Principal.class);
        X500Principal x500Principal = x500Principals.iterator().next();
        User<X500Principal> toRemove = new User<X500Principal>(x500Principal);

        // User members is a Set of User<X500Principal>
        if (!group.getUserMembers().remove(toRemove))
        {
            throw new MemberNotFoundException();
        }

//        User<Principal> user = getUserPersistence().getAugmentedUser(userPrincipal);
//        Set<X500Principal> x500Principals = user.getIdentities(X500Principal.class);
//        X500Principal x500Principal = x500Principals.iterator().next();
//
//        if (!group.getUserMembers().remove(x500Principal))
//        {
//            throw new MemberNotFoundException();
//        }
        groupPersistence.modifyGroup(group);

        List<String> deletedMembers = new ArrayList<String>();
        deletedMembers.add(toRemove.getUserID().getName());
//        deletedMembers.add(user.getUserID().getName());
        logGroupInfo(group.getID(), deletedMembers, null);
    }

+43 −16
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import static org.junit.Assert.fail;

import java.security.Principal;

import ca.nrc.cadc.ac.server.UserPersistence;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.easymock.EasyMock;
@@ -87,6 +88,8 @@ import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.auth.IdentityType;
import ca.nrc.cadc.util.Log4jInit;

import javax.security.auth.x500.X500Principal;

/**
 *
 * @author jburke
@@ -107,19 +110,32 @@ public class RemoveUserMemberActionTest
    {
        try
        {
            String userID = "foo";
            String userIDType = IdentityType.USERNAME.getValue();
            String userID = "cn=foo,c=ca";
            String userIDType = IdentityType.X500.getValue();
            Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
            User<Principal> user = new User<Principal>(userPrincipal);
            user.getIdentities().add(userPrincipal);

            Group group = new Group("group", null);
            group.getUserMembers().add(new <X500Principal>User(new X500Principal("cn=bar,c=ca")));

            final GroupPersistence mockGroupPersistence = EasyMock.createMock(GroupPersistence.class);
            EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group);

            final UserPersistence<Principal> mockUserPersistence = EasyMock.createMock(UserPersistence.class);
            EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user);

            final GroupPersistence groupPersistence = EasyMock.createMock(GroupPersistence.class);
            EasyMock.expect(groupPersistence.getGroup("group")).andReturn(group);
            EasyMock.replay(groupPersistence);
            EasyMock.replay(mockGroupPersistence, mockUserPersistence);

            RemoveUserMemberAction action = new RemoveUserMemberAction("group", userID, userIDType);
            action.groupPersistence = groupPersistence;
            RemoveUserMemberAction action = new RemoveUserMemberAction("group", userID, userIDType)
            {
                @Override
                protected UserPersistence<Principal> getUserPersistence()
                {
                    return mockUserPersistence;
                }
            };
            action.groupPersistence = mockGroupPersistence;

            try
            {
@@ -141,23 +157,34 @@ public class RemoveUserMemberActionTest
    {
        try
        {
            String userID = "foo";
            String userIDType = IdentityType.USERNAME.getValue();
            String userID = "cn=foo,c=ca";
            String userIDType = IdentityType.X500.getValue();
            Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
            User<Principal> user = new User<Principal>(userPrincipal);
            user.getIdentities().add(new X500Principal(userID));

            Group group = new Group("group", null);
            group.getUserMembers().add(user);
            Group modified = new Group("group", null);

            final GroupPersistence groupPersistence = EasyMock.createMock(GroupPersistence.class);
            EasyMock.expect(groupPersistence.getGroup("group")).andReturn(group);
            groupPersistence.modifyGroup(group);
            final GroupPersistence mockGroupPersistence = EasyMock.createMock(GroupPersistence.class);
            EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group);
            mockGroupPersistence.modifyGroup(group);
            EasyMock.expectLastCall();
            EasyMock.replay(groupPersistence);

            RemoveUserMemberAction action = new RemoveUserMemberAction("group", userID, userIDType);
            action.setGroupPersistence(groupPersistence);
            final UserPersistence<Principal> mockUserPersistence = EasyMock.createMock(UserPersistence.class);
            EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user);

            EasyMock.replay(mockGroupPersistence, mockUserPersistence);

            RemoveUserMemberAction action = new RemoveUserMemberAction("group", userID, userIDType)
            {
                @Override
                protected UserPersistence<Principal> getUserPersistence()
                {
                    return mockUserPersistence;
                }
            };
            action.setGroupPersistence(mockGroupPersistence);

            GroupLogInfo logInfo = createMock(GroupLogInfo.class);
            action.setLogInfo(logInfo);