Loading cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapUserDAO.java +23 −17 Original line number Diff line number Diff line Loading @@ -223,8 +223,11 @@ public class LdapUserDAO extends LdapDAO { try { HttpPrincipal httpPrincipal = new HttpPrincipal(username); User user = getUser(httpPrincipal); long id = user.getID().getUUID().getLeastSignificantBits(); BindRequest bindRequest = new SimpleBindRequest( getUserDN(username, config.getUsersDN()), new String(password)); getUserDN(String.valueOf(id), config.getUsersDN()), new String(password)); LDAPConnection conn = this.getUnboundReadConnection(); BindResult bindResult = conn.bind(bindRequest); Loading @@ -238,6 +241,10 @@ public class LdapUserDAO extends LdapDAO throw new AccessControlException("Invalid username or password"); } } catch (UserNotFoundException e) { throw new AccessControlException("Invalid username"); } catch (LDAPException e) { logger.debug("doLogin Exception: " + e, e); Loading Loading @@ -325,8 +332,12 @@ public class LdapUserDAO extends LdapDAO try { String emailAddress = getEmailAddress(userRequest); Principal userID = getSupportedPrincipal(userRequest.getUser()); if (userID instanceof HttpPrincipal) { getUserByEmailAddress(emailAddress, usersDN); } } catch (UserNotFoundException ok) { } } Loading Loading @@ -375,12 +386,12 @@ public class LdapUserDAO extends LdapDAO addAttribute(attributes, LDAP_OBJECT_CLASS, LDAP_INET_USER); addAttribute(attributes, LDAP_OBJECT_CLASS, LDAP_CADC_ACCOUNT); addAttribute(attributes, LDAP_UID, numericID); addAttribute(attributes, LADP_USER_PASSWORD, new String(userRequest.getPassword())); if (user.getHttpPrincipal() == null) { addAttribute(attributes, LDAP_COMMON_NAME, EXTERNAL_USER_CN); addAttribute(attributes, LDAP_LAST_NAME, EXTERNAL_USER_SN); addAttribute(attributes, LADP_USER_PASSWORD, UUID.randomUUID().toString()); } else { Loading @@ -397,7 +408,6 @@ public class LdapUserDAO extends LdapDAO throw new IllegalArgumentException(error); } addAttribute(attributes, LDAP_COMMON_NAME, userID.getName()); addAttribute(attributes, LADP_USER_PASSWORD, new String(userRequest.getPassword())); addAttribute(attributes, LDAP_FIRST_NAME, user.personalDetails.getFirstName()); addAttribute(attributes, LDAP_LAST_NAME, user.personalDetails.getLastName()); addAttribute(attributes, LDAP_ADDRESS, user.personalDetails.address); Loading Loading @@ -856,10 +866,10 @@ public class LdapUserDAO extends LdapDAO for (SearchResultEntry next : searchResult.getSearchEntries()) { final String firstName = next.getAttributeValue(LDAP_FIRST_NAME).trim(); next.getAttributeValue(LDAP_FIRST_NAME); final String lastName = next.getAttributeValue(LDAP_LAST_NAME).trim(); final String uid = next.getAttributeValue(LDAP_UID).trim(); final String uid = next.getAttributeValue(LDAP_UID); User user = new User(); user.getIdentities().add(new HttpPrincipal(uid)); Loading @@ -868,7 +878,7 @@ public class LdapUserDAO extends LdapDAO if (StringUtil.hasLength(firstName) && StringUtil.hasLength(lastName)) { user.personalDetails = new PersonalDetails(firstName, lastName); user.personalDetails = new PersonalDetails(firstName.trim(), lastName.trim()); } users.add(user); Loading Loading @@ -901,14 +911,11 @@ public class LdapUserDAO extends LdapDAO throws UserNotFoundException, TransientException, AccessControlException { User pendingUser = getPendingUser(userID); Set<HttpPrincipal> httpPrincipals = pendingUser.getIdentities(HttpPrincipal.class); if (httpPrincipals.isEmpty()) if (pendingUser.getHttpPrincipal() == null) { throw new RuntimeException("BUG: missing HttpPrincipal for " + userID.getName()); } HttpPrincipal httpPrincipal = httpPrincipals.iterator().next(); String uid = "uid=" + httpPrincipal.getName(); String uid = "uid=" + pendingUser.getID().getUUID().getLeastSignificantBits(); String dn = uid + "," + config.getUserRequestsDN(); try Loading Loading @@ -1112,10 +1119,11 @@ public class LdapUserDAO extends LdapDAO private void deleteUser(final Principal userID, final String usersDN, boolean markDelete) throws UserNotFoundException, AccessControlException, TransientException { getUser(userID, usersDN); User user2Delete = getUser(userID, usersDN); try { DN userDN = getUserDN(userID.getName(), usersDN); long id = user2Delete.getID().getUUID().getLeastSignificantBits(); DN userDN = getUserDN(String.valueOf(id), usersDN); if (markDelete) { List<Modification> modifs = new ArrayList<Modification>(); Loading @@ -1132,11 +1140,9 @@ public class LdapUserDAO extends LdapDAO else // real delete { DeleteRequest delRequest = new DeleteRequest(userDN); //delRequest.addControl( // new ProxiedAuthorizationV2RequestControl( // "dn:" + getSubjectDN().toNormalizedString())); LDAPResult result = getReadWriteConnection().delete(delRequest); logger.info("delete result:" + delRequest); LdapDAO.checkLdapResult(result.getResultCode()); } } Loading cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/AbstractGroupAction.java +24 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ package ca.nrc.cadc.ac.server.web.groups; import java.io.IOException; import java.lang.reflect.Field; import java.security.AccessControlException; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; Loading Loading @@ -232,4 +233,27 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O this.logInfo.deletedMembers = deletedMembers; } // set private field using reflection protected void setField(Object object, Object value, String name) { try { Field field = object.getClass().getDeclaredField(name); field.setAccessible(true); field.set(object, value); } catch (NoSuchFieldException e) { final String error = object.getClass().getSimpleName() + " field " + name + "not found"; throw new RuntimeException(error, e); } catch (IllegalAccessException e) { final String error = "unable to update " + name + " in " + object.getClass().getSimpleName(); throw new RuntimeException(error, e); } } } cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberAction.java +1 −7 Original line number Diff line number Diff line Loading @@ -102,13 +102,7 @@ public class RemoveUserMemberAction extends AbstractGroupAction Group group = groupPersistence.getGroup(this.groupName); Principal userPrincipal = AuthenticationUtil.createPrincipal(this.userID, this.userIDType); User user = getUserPersistence().getAugmentedUser(userPrincipal); Set<X500Principal> x500Principals = user.getIdentities(X500Principal.class); X500Principal x500Principal = x500Principals.iterator().next(); User toRemove = new User(); toRemove.getIdentities().add(x500Principal); // User members is a Set of User<X500Principal> User toRemove = getUserPersistence().getUser(userPrincipal); if (!group.getUserMembers().remove(toRemove)) { throw new MemberNotFoundException(); Loading cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/ldap/LdapUserDAOTest.java +56 −55 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest final User pendingUser = new User(); pendingUser.personalDetails = new PersonalDetails("CADCtest", "Request"); pendingUser.personalDetails.email = username + "@canada.ca"; pendingUser.getIdentities().add(httpPrincipal); pendingUser.getIdentities().add(x500Principal); Loading Loading @@ -566,12 +567,13 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest testUser.getIdentities().add(httpPrincipal); testUser.personalDetails = new PersonalDetails("firstName", "lastName"); testUser.personalDetails.email = username + "@canada.ca"; final UserRequest userRequest = new UserRequest(testUser, password); // add the user Subject subject = new Subject(); subject.getPrincipals().add(httpPrincipal); subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); // subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); final User newUser = (User) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public User run() Loading @@ -592,7 +594,6 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest }); // update the user newUser.personalDetails.email = "email2"; newUser.personalDetails.address = "address2"; newUser.personalDetails.institute = "institute2"; newUser.personalDetails.city = "city2"; Loading @@ -603,7 +604,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest // update the userexpected subject.getPrincipals().add(httpPrincipal); subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); // subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); User updatedUser = (User) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() Loading @@ -623,7 +624,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest } }); assertNotNull(updatedUser); check(testUser, updatedUser); check(newUser, updatedUser); } // TODO testUpdateUser for a user that doesn't exist Loading @@ -637,11 +638,11 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest String userID = createUsername(); HttpPrincipal httpPrincipal = new HttpPrincipal(userID); // X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); final User expected = new User(); expected.getIdentities().add(httpPrincipal); // expected.getIdentities().add(x500Principal); expected.getIdentities().add(x500Principal); expected.personalDetails = new PersonalDetails("foo", "bar"); final UserRequest userRequest = new UserRequest(expected, "123456".toCharArray()); Loading Loading @@ -682,11 +683,11 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest String userID = createUsername(); HttpPrincipal httpPrincipal = new HttpPrincipal(userID); // X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); final User expected = new User(); expected.getIdentities().add(httpPrincipal); // expected.getIdentities().add(x500Principal); expected.getIdentities().add(x500Principal); expected.personalDetails = new PersonalDetails("foo", "bar"); expected.personalDetails.email = userID + "@canada.ca"; Loading Loading @@ -723,53 +724,53 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest * Test of getMember. */ // @Test public void testGetX500User() throws Exception { Subject subject = new Subject(); subject.getPrincipals().add(cadcDaoTest1_X500Principal); subject.getPrincipals().add(cadcDaoTest1_DNPrincipal); // do everything as owner Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { try { User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); check(testMember, actual); return null; } catch (Exception e) { throw new Exception("Problems", e); } } }); // should also work as a different user subject = new Subject(); subject.getPrincipals().add(new HttpPrincipal("CadcDaoTest2")); // do everything as owner Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { try { User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); check(testMember, actual); return null; } catch (Exception e) { throw new Exception("Problems", e); } } }); } // public void testGetX500User() throws Exception // { // Subject subject = new Subject(); // subject.getPrincipals().add(cadcDaoTest1_X500Principal); // subject.getPrincipals().add(cadcDaoTest1_DNPrincipal); // // // do everything as owner // Subject.doAs(subject, new PrivilegedExceptionAction<Object>() // { // public Object run() throws Exception // { // try // { // User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); // check(testMember, actual); // return null; // } // catch (Exception e) // { // throw new Exception("Problems", e); // } // } // }); // // // should also work as a different user // subject = new Subject(); // subject.getPrincipals().add(new HttpPrincipal("CadcDaoTest2")); // // // do everything as owner // Subject.doAs(subject, new PrivilegedExceptionAction<Object>() // { // public Object run() // throws Exception // { // try // { // User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); // check(testMember, actual); // return null; // } // catch (Exception e) // { // throw new Exception("Problems", e); // } // } // }); // } @Test public void testGetUsers() throws Exception Loading cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberActionTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ public class RemoveUserMemberActionTest EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.replay(mockGroupPersistence, mockUserPersistence); Loading Loading @@ -176,7 +176,7 @@ public class RemoveUserMemberActionTest EasyMock.expectLastCall(); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.replay(mockGroupPersistence, mockUserPersistence); Loading @@ -193,6 +193,8 @@ public class RemoveUserMemberActionTest GroupLogInfo logInfo = createMock(GroupLogInfo.class); action.setLogInfo(logInfo); action.doAction(); EasyMock.verify(mockGroupPersistence, mockUserPersistence); } catch (Throwable t) { Loading Loading
cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapUserDAO.java +23 −17 Original line number Diff line number Diff line Loading @@ -223,8 +223,11 @@ public class LdapUserDAO extends LdapDAO { try { HttpPrincipal httpPrincipal = new HttpPrincipal(username); User user = getUser(httpPrincipal); long id = user.getID().getUUID().getLeastSignificantBits(); BindRequest bindRequest = new SimpleBindRequest( getUserDN(username, config.getUsersDN()), new String(password)); getUserDN(String.valueOf(id), config.getUsersDN()), new String(password)); LDAPConnection conn = this.getUnboundReadConnection(); BindResult bindResult = conn.bind(bindRequest); Loading @@ -238,6 +241,10 @@ public class LdapUserDAO extends LdapDAO throw new AccessControlException("Invalid username or password"); } } catch (UserNotFoundException e) { throw new AccessControlException("Invalid username"); } catch (LDAPException e) { logger.debug("doLogin Exception: " + e, e); Loading Loading @@ -325,8 +332,12 @@ public class LdapUserDAO extends LdapDAO try { String emailAddress = getEmailAddress(userRequest); Principal userID = getSupportedPrincipal(userRequest.getUser()); if (userID instanceof HttpPrincipal) { getUserByEmailAddress(emailAddress, usersDN); } } catch (UserNotFoundException ok) { } } Loading Loading @@ -375,12 +386,12 @@ public class LdapUserDAO extends LdapDAO addAttribute(attributes, LDAP_OBJECT_CLASS, LDAP_INET_USER); addAttribute(attributes, LDAP_OBJECT_CLASS, LDAP_CADC_ACCOUNT); addAttribute(attributes, LDAP_UID, numericID); addAttribute(attributes, LADP_USER_PASSWORD, new String(userRequest.getPassword())); if (user.getHttpPrincipal() == null) { addAttribute(attributes, LDAP_COMMON_NAME, EXTERNAL_USER_CN); addAttribute(attributes, LDAP_LAST_NAME, EXTERNAL_USER_SN); addAttribute(attributes, LADP_USER_PASSWORD, UUID.randomUUID().toString()); } else { Loading @@ -397,7 +408,6 @@ public class LdapUserDAO extends LdapDAO throw new IllegalArgumentException(error); } addAttribute(attributes, LDAP_COMMON_NAME, userID.getName()); addAttribute(attributes, LADP_USER_PASSWORD, new String(userRequest.getPassword())); addAttribute(attributes, LDAP_FIRST_NAME, user.personalDetails.getFirstName()); addAttribute(attributes, LDAP_LAST_NAME, user.personalDetails.getLastName()); addAttribute(attributes, LDAP_ADDRESS, user.personalDetails.address); Loading Loading @@ -856,10 +866,10 @@ public class LdapUserDAO extends LdapDAO for (SearchResultEntry next : searchResult.getSearchEntries()) { final String firstName = next.getAttributeValue(LDAP_FIRST_NAME).trim(); next.getAttributeValue(LDAP_FIRST_NAME); final String lastName = next.getAttributeValue(LDAP_LAST_NAME).trim(); final String uid = next.getAttributeValue(LDAP_UID).trim(); final String uid = next.getAttributeValue(LDAP_UID); User user = new User(); user.getIdentities().add(new HttpPrincipal(uid)); Loading @@ -868,7 +878,7 @@ public class LdapUserDAO extends LdapDAO if (StringUtil.hasLength(firstName) && StringUtil.hasLength(lastName)) { user.personalDetails = new PersonalDetails(firstName, lastName); user.personalDetails = new PersonalDetails(firstName.trim(), lastName.trim()); } users.add(user); Loading Loading @@ -901,14 +911,11 @@ public class LdapUserDAO extends LdapDAO throws UserNotFoundException, TransientException, AccessControlException { User pendingUser = getPendingUser(userID); Set<HttpPrincipal> httpPrincipals = pendingUser.getIdentities(HttpPrincipal.class); if (httpPrincipals.isEmpty()) if (pendingUser.getHttpPrincipal() == null) { throw new RuntimeException("BUG: missing HttpPrincipal for " + userID.getName()); } HttpPrincipal httpPrincipal = httpPrincipals.iterator().next(); String uid = "uid=" + httpPrincipal.getName(); String uid = "uid=" + pendingUser.getID().getUUID().getLeastSignificantBits(); String dn = uid + "," + config.getUserRequestsDN(); try Loading Loading @@ -1112,10 +1119,11 @@ public class LdapUserDAO extends LdapDAO private void deleteUser(final Principal userID, final String usersDN, boolean markDelete) throws UserNotFoundException, AccessControlException, TransientException { getUser(userID, usersDN); User user2Delete = getUser(userID, usersDN); try { DN userDN = getUserDN(userID.getName(), usersDN); long id = user2Delete.getID().getUUID().getLeastSignificantBits(); DN userDN = getUserDN(String.valueOf(id), usersDN); if (markDelete) { List<Modification> modifs = new ArrayList<Modification>(); Loading @@ -1132,11 +1140,9 @@ public class LdapUserDAO extends LdapDAO else // real delete { DeleteRequest delRequest = new DeleteRequest(userDN); //delRequest.addControl( // new ProxiedAuthorizationV2RequestControl( // "dn:" + getSubjectDN().toNormalizedString())); LDAPResult result = getReadWriteConnection().delete(delRequest); logger.info("delete result:" + delRequest); LdapDAO.checkLdapResult(result.getResultCode()); } } Loading
cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/AbstractGroupAction.java +24 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ package ca.nrc.cadc.ac.server.web.groups; import java.io.IOException; import java.lang.reflect.Field; import java.security.AccessControlException; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; Loading Loading @@ -232,4 +233,27 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O this.logInfo.deletedMembers = deletedMembers; } // set private field using reflection protected void setField(Object object, Object value, String name) { try { Field field = object.getClass().getDeclaredField(name); field.setAccessible(true); field.set(object, value); } catch (NoSuchFieldException e) { final String error = object.getClass().getSimpleName() + " field " + name + "not found"; throw new RuntimeException(error, e); } catch (IllegalAccessException e) { final String error = "unable to update " + name + " in " + object.getClass().getSimpleName(); throw new RuntimeException(error, e); } } }
cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberAction.java +1 −7 Original line number Diff line number Diff line Loading @@ -102,13 +102,7 @@ public class RemoveUserMemberAction extends AbstractGroupAction Group group = groupPersistence.getGroup(this.groupName); Principal userPrincipal = AuthenticationUtil.createPrincipal(this.userID, this.userIDType); User user = getUserPersistence().getAugmentedUser(userPrincipal); Set<X500Principal> x500Principals = user.getIdentities(X500Principal.class); X500Principal x500Principal = x500Principals.iterator().next(); User toRemove = new User(); toRemove.getIdentities().add(x500Principal); // User members is a Set of User<X500Principal> User toRemove = getUserPersistence().getUser(userPrincipal); if (!group.getUserMembers().remove(toRemove)) { throw new MemberNotFoundException(); Loading
cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/ldap/LdapUserDAOTest.java +56 −55 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest final User pendingUser = new User(); pendingUser.personalDetails = new PersonalDetails("CADCtest", "Request"); pendingUser.personalDetails.email = username + "@canada.ca"; pendingUser.getIdentities().add(httpPrincipal); pendingUser.getIdentities().add(x500Principal); Loading Loading @@ -566,12 +567,13 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest testUser.getIdentities().add(httpPrincipal); testUser.personalDetails = new PersonalDetails("firstName", "lastName"); testUser.personalDetails.email = username + "@canada.ca"; final UserRequest userRequest = new UserRequest(testUser, password); // add the user Subject subject = new Subject(); subject.getPrincipals().add(httpPrincipal); subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); // subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); final User newUser = (User) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public User run() Loading @@ -592,7 +594,6 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest }); // update the user newUser.personalDetails.email = "email2"; newUser.personalDetails.address = "address2"; newUser.personalDetails.institute = "institute2"; newUser.personalDetails.city = "city2"; Loading @@ -603,7 +604,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest // update the userexpected subject.getPrincipals().add(httpPrincipal); subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); // subject.getPrincipals().add(cadcDaoTest2_DNPrincipal); User updatedUser = (User) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() Loading @@ -623,7 +624,7 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest } }); assertNotNull(updatedUser); check(testUser, updatedUser); check(newUser, updatedUser); } // TODO testUpdateUser for a user that doesn't exist Loading @@ -637,11 +638,11 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest String userID = createUsername(); HttpPrincipal httpPrincipal = new HttpPrincipal(userID); // X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); final User expected = new User(); expected.getIdentities().add(httpPrincipal); // expected.getIdentities().add(x500Principal); expected.getIdentities().add(x500Principal); expected.personalDetails = new PersonalDetails("foo", "bar"); final UserRequest userRequest = new UserRequest(expected, "123456".toCharArray()); Loading Loading @@ -682,11 +683,11 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest String userID = createUsername(); HttpPrincipal httpPrincipal = new HttpPrincipal(userID); // X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); X500Principal x500Principal = new X500Principal("cn=" + userID + ",ou=cadc,o=hia,c=ca"); final User expected = new User(); expected.getIdentities().add(httpPrincipal); // expected.getIdentities().add(x500Principal); expected.getIdentities().add(x500Principal); expected.personalDetails = new PersonalDetails("foo", "bar"); expected.personalDetails.email = userID + "@canada.ca"; Loading Loading @@ -723,53 +724,53 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest * Test of getMember. */ // @Test public void testGetX500User() throws Exception { Subject subject = new Subject(); subject.getPrincipals().add(cadcDaoTest1_X500Principal); subject.getPrincipals().add(cadcDaoTest1_DNPrincipal); // do everything as owner Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { try { User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); check(testMember, actual); return null; } catch (Exception e) { throw new Exception("Problems", e); } } }); // should also work as a different user subject = new Subject(); subject.getPrincipals().add(new HttpPrincipal("CadcDaoTest2")); // do everything as owner Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { try { User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); check(testMember, actual); return null; } catch (Exception e) { throw new Exception("Problems", e); } } }); } // public void testGetX500User() throws Exception // { // Subject subject = new Subject(); // subject.getPrincipals().add(cadcDaoTest1_X500Principal); // subject.getPrincipals().add(cadcDaoTest1_DNPrincipal); // // // do everything as owner // Subject.doAs(subject, new PrivilegedExceptionAction<Object>() // { // public Object run() throws Exception // { // try // { // User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); // check(testMember, actual); // return null; // } // catch (Exception e) // { // throw new Exception("Problems", e); // } // } // }); // // // should also work as a different user // subject = new Subject(); // subject.getPrincipals().add(new HttpPrincipal("CadcDaoTest2")); // // // do everything as owner // Subject.doAs(subject, new PrivilegedExceptionAction<Object>() // { // public Object run() // throws Exception // { // try // { // User actual = getUserDAO().getX500User(new DN(cadcDaoTest1_DN)); // check(testMember, actual); // return null; // } // catch (Exception e) // { // throw new Exception("Problems", e); // } // } // }); // } @Test public void testGetUsers() throws Exception Loading
cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/groups/RemoveUserMemberActionTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ public class RemoveUserMemberActionTest EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.replay(mockGroupPersistence, mockUserPersistence); Loading Loading @@ -176,7 +176,7 @@ public class RemoveUserMemberActionTest EasyMock.expectLastCall(); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.replay(mockGroupPersistence, mockUserPersistence); Loading @@ -193,6 +193,8 @@ public class RemoveUserMemberActionTest GroupLogInfo logInfo = createMock(GroupLogInfo.class); action.setLogInfo(logInfo); action.doAction(); EasyMock.verify(mockGroupPersistence, mockUserPersistence); } catch (Throwable t) { Loading