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
Loading
Loading
Loading
Loading
+69 −31
Original line number Diff line number Diff line
@@ -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.
     *
@@ -105,9 +96,9 @@ public interface UserPersistence<T extends Principal>
        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.
     *
@@ -164,23 +155,27 @@ public interface UserPersistence<T extends Principal>
        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;
    
}
+112 −52
Original line number Diff line number Diff line
@@ -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.
     *
@@ -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.
     * @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,7 +358,7 @@ 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
    {
@@ -363,7 +366,64 @@ public class LdapUserPersistence<T extends Principal>
        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
        {