Commit 5be9dbb3 authored by Jeff Burke's avatar Jeff Burke
Browse files

s1890: added unit test for getAugmentedSubject

parent 60c3ecde
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ public class LdapUserDAO extends LdapDAO
    private String[] identityAttribs = new String[]
    {
        LDAP_UID, LDAP_DISTINGUISHED_NAME, LDAP_ENTRYDN,
        LDAP_MEMBEROF // for group cache
        LDAP_USER_NAME, LDAP_MEMBEROF // for group cache
    };

    public LdapUserDAO(LdapConnections connections)
@@ -678,8 +678,9 @@ public class LdapUserDAO extends LdapDAO
            }

            User user = new User();
            user.getIdentities().add(new HttpPrincipal(
                searchResult.getAttributeValue(LDAP_UID)));
            String username = searchResult.getAttributeValue(LDAP_USER_NAME);
            logger.debug("username is " + username);
            user.getIdentities().add(new HttpPrincipal(username));

            String numericID = searchResult.getAttributeValue(LDAP_UID);
            logger.debug("numericID is " + numericID);
@@ -1092,6 +1093,7 @@ public class LdapUserDAO extends LdapDAO
    DN getUserDN(User user)
        throws UserNotFoundException, TransientException
    {
        // Could be a DNPrincipal from a memberOf or uniquemember entrydn
        Principal userID = user.getHttpPrincipal();
        String searchField = userLdapAttrib.get(userID.getClass());
        if (searchField == null)
+16 −13
Original line number Diff line number Diff line
@@ -102,8 +102,7 @@ import java.util.Set;

public class UserRequestServlet extends HttpServlet
{

    private static final long serialVersionUID = 5289130885807305288L;
    private static final long serialVersionUID = 6290241995918416399L;
    private static final Logger log = Logger.getLogger(UserRequestServlet.class);

    private List<Subject> privilegedSubjects;
@@ -129,7 +128,6 @@ public class UserRequestServlet extends HttpServlet
            {
                x500List = x500Users.split(" ");
                httpList = httpUsers.split(" ");
            }

                if (x500List.length != httpList.length)
                {
@@ -144,6 +142,11 @@ public class UserRequestServlet extends HttpServlet
                    s.getPrincipals().add(new HttpPrincipal(httpList[i]));
                    privilegedSubjects.add(s);
                }
            }
            else
            {
                log.warn("No Privileged users configured.");
            }

            PluginFactory pluginFactory = new PluginFactory();
            userPersistence = pluginFactory.createUserPersistence();
+32 −0
Original line number Diff line number Diff line
@@ -326,6 +326,38 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest
        });
    }

    /**
     * Test of getAugmentedUser method, of class LdapUserDAO.
     */
    @Test
    public void getGetAugmentedUser() throws Exception
    {
        Subject subject = new Subject();
        subject.getPrincipals().add(cadcDaoTest1_HttpPrincipal);
        subject.getPrincipals().add(cadcDaoTest1_DNPrincipal);

        // do everything as owner
        Subject.doAs(subject, new PrivilegedExceptionAction<Object>()
        {
            public Object run()
                throws Exception
            {
                try
                {
                    final LdapUserDAO userDAO = getUserDAO();
                    final User actual = userDAO.getUser(cadcDaoTest1_HttpPrincipal);
                    assertEquals(cadcDaoTest1_User.getHttpPrincipal(), actual.getHttpPrincipal());

                    return null;
                }
                catch (Exception e)
                {
                    throw new Exception("Problems", e);
                }
            }
        });
    }

    /**
     * Test of getUserByEmailAddress method, of class LdapUserDAO.
     */