Skip to content
Snippets Groups Projects
Commit 9df6ff51 authored by Alinga Yeung's avatar Alinga Yeung
Browse files

Merge branch 's1840' of /srv/cadc/git/wopencadc into s1840

parents 77787224 234fb7c2
No related branches found
No related tags found
No related merge requests found
......@@ -73,6 +73,7 @@ import ca.nrc.cadc.ac.UserAlreadyExistsException;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.ac.UserRequest;
import ca.nrc.cadc.net.TransientException;
import com.unboundid.ldap.sdk.DN;
import java.security.AccessControlException;
import java.security.Principal;
......@@ -81,19 +82,9 @@ import java.util.Collection;
public interface UserPersistence<T extends Principal>
{
/**
* Get all user names.
* Add the user to the active users tree.
*
* @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;
/**
* Add the user to the active user tree.
*
* @param user The user request to put into the active user tree.
* @param user The user request to put into the active users tree.
*
* @return User instance.
*
......@@ -102,12 +93,12 @@ public interface UserPersistence<T extends Principal>
*/
void addUser(UserRequest<T> user)
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.
*
......@@ -119,7 +110,7 @@ public interface UserPersistence<T extends Principal>
UserAlreadyExistsException;
/**
* Get the user specified by userID.
* Get the user specified by userID from the active users tree.
*
* @param userID The userID.
*
......@@ -131,7 +122,7 @@ public interface UserPersistence<T extends Principal>
*/
User<T> getUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException;
AccessControlException;
/**
* Get the user specified by userID whose account is pending approval.
......@@ -145,8 +136,8 @@ public interface UserPersistence<T extends Principal>
* @throws AccessControlException If the operation is not permitted.
*/
User<T> getPendingUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException;
throws UserNotFoundException, TransientException,
AccessControlException;
/**
* Get the user specified by userID with all of the users identities.
......@@ -161,26 +152,30 @@ public interface UserPersistence<T extends Principal>
*/
User<T> getAugmentedUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException;
AccessControlException;
/**
* Attempt to login the specified user.
*
* @param userID The userID.
* @param password The password.
* Get all user names from the active users tree.
*
* @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 AccessControlException If the operation is not permitted.
*/
Boolean doLogin(String userID, String password)
throws UserNotFoundException, TransientException,
AccessControlException;
Collection<User<Principal>> getPendingUsers()
throws TransientException, 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.
*
......@@ -195,7 +190,7 @@ public interface UserPersistence<T extends Principal>
AccessControlException;
/**
* Delete the user specified by userID.
* Delete the user specified by userID from the active users tree.
*
* @param userID The userID.
*
......@@ -206,4 +201,47 @@ public interface UserPersistence<T extends Principal>
void deleteUser(T userID)
throws UserNotFoundException, TransientException,
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 @@
*/
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.net.TransientException;
import com.unboundid.ldap.sdk.DN;
import org.apache.log4j.Logger;
import java.security.AccessControlException;
import java.security.Principal;
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 LdapConfig config;
......@@ -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.
*
......@@ -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.
*
......@@ -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.
*
......@@ -260,24 +242,45 @@ public class LdapUserPersistence<T extends Principal>
}
/**
* Get the user specified by userID.
*
* @param userID The userID.
* Get all user names from the active users tree.
*
* @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 AccessControlException If the operation is not permitted.
*/
public Boolean doLogin(String userID, String password)
throws UserNotFoundException, TransientException, AccessControlException
public Collection<User<Principal>> getPendingUsers()
throws TransientException, AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(this.config);
return userDAO.doLogin(userID, password);
userDAO = new LdapUserDAO<T>(config);
return userDAO.getPendingUsers();
}
finally
{
......@@ -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.
*
......@@ -301,7 +304,7 @@ public class LdapUserPersistence<T extends Principal>
*/
public User<T> modifyUser(User<T> user)
throws UserNotFoundException, TransientException,
AccessControlException
AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
......@@ -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 oldPassword current password.
* @param newPassword new password.
* @throws UserNotFoundException If the given user does not exist.
* @throws TransientException If an temporary, unexpected problem occurred.
* @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.
*/
public void setPassword(User<T> user, final String oldPassword, final String newPassword)
throws UserNotFoundException, TransientException, AccessControlException
public void deleteUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
userDAO = new LdapUserDAO<T>(this.config);
userDAO.setPassword(user, oldPassword, newPassword);
userDAO.deleteUser(userID);
}
finally
{
......@@ -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.
*
......@@ -355,15 +358,72 @@ public class LdapUserPersistence<T extends Principal>
* @throws TransientException If an temporary, unexpected problem occurred.
* @throws AccessControlException If the operation is not permitted.
*/
public void deleteUser(T userID)
public void deletePendingUser(T userID)
throws UserNotFoundException, TransientException,
AccessControlException
AccessControlException
{
LdapUserDAO<T> userDAO = null;
try
{
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
{
......
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