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

s1840: add missing UserPersistence methods.

parent 6928a0c9
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,7 @@ import ca.nrc.cadc.ac.UserAlreadyExistsException; ...@@ -73,6 +73,7 @@ import ca.nrc.cadc.ac.UserAlreadyExistsException;
import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.ac.UserRequest; import ca.nrc.cadc.ac.UserRequest;
import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.net.TransientException;
import com.unboundid.ldap.sdk.DN;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.security.Principal; import java.security.Principal;
...@@ -81,19 +82,9 @@ import java.util.Collection; ...@@ -81,19 +82,9 @@ import java.util.Collection;
public interface UserPersistence<T extends Principal> public interface UserPersistence<T extends Principal>
{ {
/** /**
* Get all user names. * Add the user to the active users tree.
* *
* @return A collection of strings. * @param user The user request to put into the active users tree.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
Collection<User<Principal>> getUsers()
throws TransientException, AccessControlException;
/**
* Add the user to the active user tree.
*
* @param user The user request to put into the active user tree.
* *
* @return User instance. * @return User instance.
* *
...@@ -102,12 +93,12 @@ public interface UserPersistence<T extends Principal> ...@@ -102,12 +93,12 @@ public interface UserPersistence<T extends Principal>
*/ */
void addUser(UserRequest<T> user) void addUser(UserRequest<T> user)
throws TransientException, AccessControlException, throws TransientException, AccessControlException,
UserAlreadyExistsException; UserAlreadyExistsException;
/** /**
* Add the user to the pending user tree. * Add the user to the pending users tree.
* *
* @param user The user request to put into the pending user tree. * @param user The user request to put into the pending users tree.
* *
* @return User instance. * @return User instance.
* *
...@@ -119,7 +110,7 @@ public interface UserPersistence<T extends Principal> ...@@ -119,7 +110,7 @@ public interface UserPersistence<T extends Principal>
UserAlreadyExistsException; UserAlreadyExistsException;
/** /**
* Get the user specified by userID. * Get the user specified by userID from the active users tree.
* *
* @param userID The userID. * @param userID The userID.
* *
...@@ -131,7 +122,7 @@ public interface UserPersistence<T extends Principal> ...@@ -131,7 +122,7 @@ public interface UserPersistence<T extends Principal>
*/ */
User<T> getUser(T userID) User<T> getUser(T userID)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException; AccessControlException;
/** /**
* Get the user specified by userID whose account is pending approval. * Get the user specified by userID whose account is pending approval.
...@@ -145,8 +136,8 @@ public interface UserPersistence<T extends Principal> ...@@ -145,8 +136,8 @@ public interface UserPersistence<T extends Principal>
* @throws AccessControlException If the operation is not permitted. * @throws AccessControlException If the operation is not permitted.
*/ */
User<T> getPendingUser(T userID) User<T> getPendingUser(T userID)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException; AccessControlException;
/** /**
* Get the user specified by userID with all of the users identities. * Get the user specified by userID with all of the users identities.
...@@ -161,26 +152,30 @@ public interface UserPersistence<T extends Principal> ...@@ -161,26 +152,30 @@ public interface UserPersistence<T extends Principal>
*/ */
User<T> getAugmentedUser(T userID) User<T> getAugmentedUser(T userID)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException; AccessControlException;
/** /**
* Attempt to login the specified user. * Get all user names from the active users tree.
*
* @param userID The userID.
* @param password The password.
* *
* @return Boolean * @return A collection of strings.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
Collection<User<Principal>> getUsers()
throws TransientException, AccessControlException;
/**
* Get all user names from the pending users tree.
* *
* @throws UserNotFoundException when the user is not found. * @return A collection of strings.
* @throws TransientException If an temporary, unexpected problem occurred. * @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted. * @throws AccessControlException If the operation is not permitted.
*/ */
Boolean doLogin(String userID, String password) Collection<User<Principal>> getPendingUsers()
throws UserNotFoundException, TransientException, throws TransientException, AccessControlException;
AccessControlException;
/** /**
* Updated the user specified by User. * Updated the user specified by userID in the active users tree.
* *
* @param user The user instance to modify. * @param user The user instance to modify.
* *
...@@ -195,7 +190,7 @@ public interface UserPersistence<T extends Principal> ...@@ -195,7 +190,7 @@ public interface UserPersistence<T extends Principal>
AccessControlException; AccessControlException;
/** /**
* Delete the user specified by userID. * Delete the user specified by userID from the active users tree.
* *
* @param userID The userID. * @param userID The userID.
* *
...@@ -206,4 +201,47 @@ public interface UserPersistence<T extends Principal> ...@@ -206,4 +201,47 @@ public interface UserPersistence<T extends Principal>
void deleteUser(T userID) void deleteUser(T userID)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException; AccessControlException;
/**
* Delete the user specified by userID from the pending users tree.
*
* @param userID The userID.
*
* @throws UserNotFoundException when the user is not found.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
void deletePendingUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException;
/**
* Attempt to login the specified user.
*
* @param userID The userID.
* @param password The password.
*
* @return Boolean
*
* @throws UserNotFoundException when the user is not found.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
Boolean doLogin(String userID, String password)
throws UserNotFoundException, TransientException,
AccessControlException;
/**
* Update a user's password. The given user and authenticating user must match.
*
* @param user
* @param oldPassword current password.
* @param newPassword new password.
* @throws UserNotFoundException If the given user does not exist.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
void setPassword(User<T> user, final String oldPassword, final String newPassword)
throws UserNotFoundException, TransientException, AccessControlException;
} }
...@@ -68,20 +68,20 @@ ...@@ -68,20 +68,20 @@
*/ */
package ca.nrc.cadc.ac.server.ldap; package ca.nrc.cadc.ac.server.ldap;
import ca.nrc.cadc.ac.*; import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserAlreadyExistsException;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.ac.UserRequest;
import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.net.TransientException;
import com.unboundid.ldap.sdk.DN; import com.unboundid.ldap.sdk.DN;
import org.apache.log4j.Logger;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.security.Principal; import java.security.Principal;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger; public class LdapUserPersistence<T extends Principal> implements UserPersistence<T>
public class LdapUserPersistence<T extends Principal>
implements UserPersistence<T>
{ {
private static final Logger logger = Logger.getLogger(LdapUserPersistence.class); private static final Logger logger = Logger.getLogger(LdapUserPersistence.class);
private LdapConfig config; private LdapConfig config;
...@@ -98,26 +98,8 @@ public class LdapUserPersistence<T extends Principal> ...@@ -98,26 +98,8 @@ public class LdapUserPersistence<T extends Principal>
} }
} }
public Collection<User<Principal>> getUsers()
throws TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(config);
return userDAO.getUsers();
}
finally
{
if (userDAO != null)
{
userDAO.close();
}
}
}
/** /**
* Add the user to the active user tree. * Add the user to the active users tree.
* *
* @param user The user request to put into the active user tree. * @param user The user request to put into the active user tree.
* *
...@@ -146,7 +128,7 @@ public class LdapUserPersistence<T extends Principal> ...@@ -146,7 +128,7 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Add the user to the pending user tree. * Add the user to the pending users tree.
* *
* @param user The user request to put into the pending user tree. * @param user The user request to put into the pending user tree.
* *
...@@ -175,7 +157,7 @@ public class LdapUserPersistence<T extends Principal> ...@@ -175,7 +157,7 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Get the user specified by userID. * Get the user specified by userID from the active users tree.
* *
* @param userID The userID. * @param userID The userID.
* *
...@@ -260,24 +242,45 @@ public class LdapUserPersistence<T extends Principal> ...@@ -260,24 +242,45 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Get the user specified by userID. * Get all user names from the active users tree.
*
* @param userID The userID.
* *
* @return Boolean. * @return A collection of strings.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public Collection<User<Principal>> getUsers()
throws TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(config);
return userDAO.getUsers();
}
finally
{
if (userDAO != null)
{
userDAO.close();
}
}
}
/**
* Get all user names from the pending users tree.
* *
* @throws UserNotFoundException when the user is not found. * @return A collection of strings.
* @throws TransientException If an temporary, unexpected problem occurred. * @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted. * @throws AccessControlException If the operation is not permitted.
*/ */
public Boolean doLogin(String userID, String password) public Collection<User<Principal>> getPendingUsers()
throws UserNotFoundException, TransientException, AccessControlException throws TransientException, AccessControlException
{ {
LdapUserDAO<T> userDAO = null; LdapUserDAO<T> userDAO = null;
try try
{ {
userDAO = new LdapUserDAO<T>(this.config); userDAO = new LdapUserDAO<T>(config);
return userDAO.doLogin(userID, password); return userDAO.getPendingUsers();
} }
finally finally
{ {
...@@ -289,7 +292,7 @@ public class LdapUserPersistence<T extends Principal> ...@@ -289,7 +292,7 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Updated the user specified by User. * Updated the user specified by userID in the active users tree.
* *
* @param user The user to update. * @param user The user to update.
* *
...@@ -301,7 +304,7 @@ public class LdapUserPersistence<T extends Principal> ...@@ -301,7 +304,7 @@ public class LdapUserPersistence<T extends Principal>
*/ */
public User<T> modifyUser(User<T> user) public User<T> modifyUser(User<T> user)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException AccessControlException
{ {
LdapUserDAO<T> userDAO = null; LdapUserDAO<T> userDAO = null;
try try
...@@ -319,23 +322,23 @@ public class LdapUserPersistence<T extends Principal> ...@@ -319,23 +322,23 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Update a user's password. The given user and authenticating user must match. * Delete the user specified by userID.
* *
* @param user * @param userID The userID.
* @param oldPassword current password. *
* @param newPassword new password. * @throws UserNotFoundException when the user is not found.
* @throws UserNotFoundException If the given user does not exist. * @throws TransientException If an temporary, unexpected problem occurred.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted. * @throws AccessControlException If the operation is not permitted.
*/ */
public void setPassword(User<T> user, final String oldPassword, final String newPassword) public void deleteUser(T userID)
throws UserNotFoundException, TransientException, AccessControlException throws UserNotFoundException, TransientException,
AccessControlException
{ {
LdapUserDAO<T> userDAO = null; LdapUserDAO<T> userDAO = null;
try try
{ {
userDAO = new LdapUserDAO<T>(this.config); userDAO = new LdapUserDAO<T>(this.config);
userDAO.setPassword(user, oldPassword, newPassword); userDAO.deleteUser(userID);
} }
finally finally
{ {
...@@ -347,7 +350,7 @@ public class LdapUserPersistence<T extends Principal> ...@@ -347,7 +350,7 @@ public class LdapUserPersistence<T extends Principal>
} }
/** /**
* Delete the user specified by userID. * Delete the user specified by userID from the pending users tree.
* *
* @param userID The userID. * @param userID The userID.
* *
...@@ -355,15 +358,72 @@ public class LdapUserPersistence<T extends Principal> ...@@ -355,15 +358,72 @@ public class LdapUserPersistence<T extends Principal>
* @throws TransientException If an temporary, unexpected problem occurred. * @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted. * @throws AccessControlException If the operation is not permitted.
*/ */
public void deleteUser(T userID) public void deletePendingUser(T userID)
throws UserNotFoundException, TransientException, throws UserNotFoundException, TransientException,
AccessControlException AccessControlException
{ {
LdapUserDAO<T> userDAO = null; LdapUserDAO<T> userDAO = null;
try try
{ {
userDAO = new LdapUserDAO<T>(this.config); userDAO = new LdapUserDAO<T>(this.config);
userDAO.deleteUser(userID); userDAO.deletePendingUser(userID);
}
finally
{
if (userDAO != null)
{
userDAO.close();
}
}
}
/**
* Get the user specified by userID.
*
* @param userID The userID.
*
* @return Boolean.
*
* @throws UserNotFoundException when the user is not found.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public Boolean doLogin(String userID, String password)
throws UserNotFoundException, TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(this.config);
return userDAO.doLogin(userID, password);
}
finally
{
if (userDAO != null)
{
userDAO.close();
}
}
}
/**
* Update a user's password. The given user and authenticating user must match.
*
* @param user
* @param oldPassword current password.
* @param newPassword new password.
* @throws UserNotFoundException If the given user does not exist.
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public void setPassword(User<T> user, final String oldPassword, final String newPassword)
throws UserNotFoundException, TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(this.config);
userDAO.setPassword(user, oldPassword, newPassword);
} }
finally finally
{ {
......
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