Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveGroupMemberAction.java +0 −14 Original line number Diff line number Diff line Loading @@ -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); Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberAction.java +7 −11 Original line number Diff line number Diff line Loading @@ -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); } Loading projects/cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberActionTest.java +43 −16 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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 { Loading @@ -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); Loading Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveGroupMemberAction.java +0 −14 Original line number Diff line number Diff line Loading @@ -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); Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberAction.java +7 −11 Original line number Diff line number Diff line Loading @@ -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); } Loading
projects/cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberActionTest.java +43 −16 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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 { Loading @@ -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); Loading