Commit 609c75f3 authored by Jeff Burke's avatar Jeff Burke
Browse files

s1890: get LdapDAOTest to compile

parent 73948bac
Loading
Loading
Loading
Loading
+44 −14
Original line number Diff line number Diff line
@@ -265,9 +265,14 @@ public class LdapUserDAO extends LdapDAO
    public void addUser(final UserRequest userRequest)
        throws TransientException, UserAlreadyExistsException
    {
        Principal userID = getSupportedPrincipal(userRequest.getUser().getIdentities());
        if (userID == null)
        {
            throw new IllegalArgumentException("UserRequest missing supported Principal type");
        }

        try
        {
            Principal userID = userRequest.getUser().getIdentities().iterator().next();
            getUser(userID, config.getUsersDN());
            final String error = userID.getName() + " found in " + config.getUsersDN();
            throw new UserAlreadyExistsException(error);
@@ -294,14 +299,18 @@ public class LdapUserDAO extends LdapDAO
        return userRequest.getUser().personalDetails.email;
    }

    private void checkUsers(final UserRequest userRequest,
            final String usersDN)
    private void checkUsers(final UserRequest userRequest, final String usersDN)
        throws TransientException, UserAlreadyExistsException
    {
        // check current users
        try
        {
            Principal userID = userRequest.getUser().getIdentities().iterator().next();
            Principal userID = getSupportedPrincipal(userRequest.getUser().getIdentities());
            if (userID == null)
            {
                throw new IllegalArgumentException("UserRequest missing supported Principal type");
            }

            getUser(userID, usersDN);
            final String error = "user " + userID.getName() + " found in " + usersDN;
            throw new UserAlreadyExistsException(error);
@@ -340,10 +349,14 @@ public class LdapUserDAO extends LdapDAO
        throws TransientException, UserAlreadyExistsException
    {
        final User user = userRequest.getUser();
        final Principal userID = user.getIdentities().iterator().next();
        final Principal userID = getSupportedPrincipal(user.getIdentities());
        if (userID == null)
        {
            throw new IllegalArgumentException("UserRequest missing supported Principal type");
        }

        final Class userType = userID.getClass();
        final String searchField = userLdapAttrib.get(userType);

        if (searchField == null)
        {
            throw new IllegalArgumentException("Unsupported principal type " + userType);
@@ -564,8 +577,7 @@ public class LdapUserDAO extends LdapDAO
     * @throws AccessControlException If the operation is not permitted.
     * @throws UserAlreadyExistsException A user with the same email address already exists
     */
    private User getUserByEmailAddress(final String emailAddress,
            final String usersDN)
    private User getUserByEmailAddress(final String emailAddress, final String usersDN)
        throws UserNotFoundException, TransientException,
               AccessControlException, UserAlreadyExistsException
    {
@@ -682,8 +694,7 @@ public class LdapUserDAO extends LdapDAO
        profiler.checkpoint("getAugmentedUser.getSearchField");
        if (searchField == null)
        {
            throw new IllegalArgumentException(
                "Unsupported principal type " + userID.getClass());
            throw new IllegalArgumentException("Unsupported principal type " + userID.getClass());
        }

        try
@@ -1303,6 +1314,25 @@ public class LdapUserDAO extends LdapDAO
        return rand.nextInt(Integer.MAX_VALUE - 10000) + 10000;
    }

    /**
     * Get the first supported Principal out of the list of the User's Principals, or
     * null of if the User doesn't have a supported Principal.
     *
     * @param identities Set of User's Principals.
     * @return a Principal.
     */
    protected Principal getSupportedPrincipal(final Set<Principal> identities)
    {
        for (Principal principal : identities)
        {
            if (userLdapAttrib.get(principal.getClass()) != null)
            {
                return principal;
            }
        }
        return null;
    }

    protected InternalID getInternalID(String numericID)
    {
        URI uri;
+3 −1
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ import org.junit.Test;
import javax.security.auth.Subject;
import javax.security.auth.x500.X500Principal;
import java.security.PrivilegedExceptionAction;
import java.util.UUID;

import org.junit.Assert;

import static org.junit.Assert.assertEquals;
@@ -157,7 +159,7 @@ public class LdapDAOTest extends AbstractLdapDAOTest
        });


        NumericPrincipal numPrincipal = new NumericPrincipal(1866);
        NumericPrincipal numPrincipal = new NumericPrincipal(UUID.randomUUID());
        subject.getPrincipals().add(numPrincipal);

        Subject.doAs(subject, new PrivilegedExceptionAction<Object>()
+265 −249

File changed.

Preview size limit exceeded, changes collapsed.

+9 −1
Original line number Diff line number Diff line
@@ -185,7 +185,15 @@ public class User
    @Override
    public String toString()
    {
        return getClass().getSimpleName() + "[" + id + "]";
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append("[");
        if (id != null)
        {
            sb.append(id);
        }
        sb.append("]");
        return sb.toString();
    }

    private class PrincipalComparator implements Comparator<Principal>