Skip to content
Snippets Groups Projects
Commit 318d6732 authored by Jeff Burke's avatar Jeff Burke
Browse files

s1840, delete user support, getPendingUsers, normalize userDAO api a bit, updated unit tests.

parent 0245eee6
No related branches found
No related tags found
No related merge requests found
Showing
with 544 additions and 334 deletions
......@@ -91,9 +91,9 @@ public interface UserPersistence<T extends Principal>
throws TransientException, AccessControlException;
/**
* Add the new user.
* Add the user to the active user tree.
*
* @param user The user request to put into the request tree.
* @param user The user request to put into the active user tree.
*
* @return User instance.
*
......@@ -104,6 +104,20 @@ public interface UserPersistence<T extends Principal>
throws TransientException, AccessControlException,
UserAlreadyExistsException;
/**
* Add the user to the pending user tree.
*
* @param user The user request to put into the pending user tree.
*
* @return User instance.
*
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
void addPendingUser(UserRequest<T> user)
throws TransientException, AccessControlException,
UserAlreadyExistsException;
/**
* Get the user specified by userID.
*
......
......@@ -978,6 +978,8 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
{
try
{
// TODO Subject has the X500Principal, no need to go to ldap.
// TODO X500Principal is optional???
User<X500Principal> subjectUser =
userPersist.getX500User(getSubjectDN());
if (subjectUser.equals(owner))
......
......@@ -117,9 +117,9 @@ public class LdapUserPersistence<T extends Principal>
}
/**
* Add the new user.
* Add the user to the active user tree.
*
* @param user
* @param user The user request to put into the active user tree.
*
* @return User instance.
*
......@@ -145,6 +145,35 @@ public class LdapUserPersistence<T extends Principal>
}
}
/**
* Add the user to the pending user tree.
*
* @param user The user request to put into the pending user tree.
*
* @return User instance.
*
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public void addPendingUser(UserRequest<T> user)
throws TransientException, AccessControlException,
UserAlreadyExistsException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(this.config);
userDAO.addPendingUser(user);
}
finally
{
if (userDAO != null)
{
userDAO.close();
}
}
}
/**
* Get the user specified by userID.
*
......@@ -183,9 +212,8 @@ public class LdapUserPersistence<T extends Principal>
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public User<T> getPendingUser(final T userID) throws UserNotFoundException,
TransientException,
AccessControlException
public User<T> getPendingUser(final T userID)
throws UserNotFoundException, TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
......
......@@ -93,7 +93,7 @@ public class CreateUserAction extends AbstractUserAction
{
final UserPersistence<Principal> userPersistence = getUserPersistence();
final UserRequest<Principal> userRequest = readUserRequest(this.inputStream);
userPersistence.addUser(userRequest);
userPersistence.addPendingUser(userRequest);
syncOut.setCode(201);
logUserInfo(userRequest.getUser().getUserID().getName());
......
......@@ -68,8 +68,8 @@
*/
package ca.nrc.cadc.ac.server.web.users;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.server.UserPersistence;
import java.security.Principal;
public class DeleteUserAction extends AbstractUserAction
......@@ -85,8 +85,7 @@ public class DeleteUserAction extends AbstractUserAction
public void doAction() throws Exception
{
UserPersistence userPersistence = getUserPersistence();
User<? extends Principal> deletedUser = userPersistence.getUser(userID);
userPersistence.deleteUser(deletedUser.getUserID());
userPersistence.deleteUser(userID);
}
}
......@@ -156,7 +156,6 @@ public class GetUserAction extends AbstractUserAction
user.details.clear();
user.details.add(new PersonalDetails(pd.getFirstName(), pd.getLastName()));
}
}
return user;
......
......@@ -71,6 +71,10 @@ package ca.nrc.cadc.ac.server.web;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.Log4jInit;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.security.auth.Subject;
......@@ -83,9 +87,16 @@ import java.security.PrivilegedExceptionAction;
import static org.easymock.EasyMock.*;
public class WhoAmIServletTest
{
private static final Logger log = Logger.getLogger(WhoAmIServletTest.class);
@BeforeClass
public static void setUpBeforeClass()
throws Exception
{
Log4jInit.setLevel("ca.nrc.cadc.ac", Level.INFO);
}
@Test
public void doGet() throws Exception
{
......@@ -114,10 +125,8 @@ public class WhoAmIServletTest
}
};
final HttpServletRequest mockRequest =
createMock(HttpServletRequest.class);
final HttpServletResponse mockResponse =
createMock(HttpServletResponse.class);
final HttpServletRequest mockRequest = createMock(HttpServletRequest.class);
final HttpServletResponse mockResponse = createMock(HttpServletResponse.class);
expect(mockRequest.getPathInfo()).andReturn("users/CADCtest").once();
expect(mockRequest.getMethod()).andReturn("GET").once();
......@@ -127,7 +136,7 @@ public class WhoAmIServletTest
expectLastCall().once();
expect(mockRegistry.getServiceURL(URI.create(AC.GMS_SERVICE_URI),
"http", "/users/%s?idType=HTTP")).
"https", "/users/%s?idType=HTTP")).
andReturn(new URL("https://mysite.com/ac/users/CADCtest?idType=HTTP")).once();
replay(mockRequest, mockResponse, mockRegistry);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment