Commit 665f763b authored by Jeff Burke's avatar Jeff Burke
Browse files

s1890: added method to convert from uuid to string.

parent 496ca6bf
Loading
Loading
Loading
Loading
+24 −11
Original line number Original line Diff line number Diff line
@@ -225,9 +225,9 @@ public class LdapUserDAO extends LdapDAO
        {
        {
            HttpPrincipal httpPrincipal = new HttpPrincipal(username);
            HttpPrincipal httpPrincipal = new HttpPrincipal(username);
            User user = getUser(httpPrincipal);
            User user = getUser(httpPrincipal);
            long id = user.getID().getUUID().getLeastSignificantBits();
            String uuid = uuid2string(user.getID().getUUID());
            BindRequest bindRequest = new SimpleBindRequest(
            BindRequest bindRequest = new SimpleBindRequest(
                getUserDN(String.valueOf(id), config.getUsersDN()), new String(password));
                getUserDN(uuid, config.getUsersDN()), new String(password));


            LDAPConnection conn = this.getUnboundReadConnection();
            LDAPConnection conn = this.getUnboundReadConnection();
            BindResult bindResult = conn.bind(bindRequest);
            BindResult bindResult = conn.bind(bindRequest);
@@ -505,11 +505,19 @@ public class LdapUserDAO extends LdapDAO
        SearchResultEntry searchResult = null;
        SearchResultEntry searchResult = null;
        try
        try
        {
        {
            Filter filter = Filter.createEqualityFilter(searchField, userID.getName());
            String name;
            if (userID instanceof NumericPrincipal)
            {
                name = uuid2string(UUID.fromString(userID.getName()));
            }
            else
            {
                name = userID.getName();
            }
            Filter filter = Filter.createEqualityFilter(searchField, name);
            logger.debug("getUser search filter: " + filter);
            logger.debug("getUser search filter: " + filter);


            SearchRequest searchRequest =
            SearchRequest searchRequest = new SearchRequest(usersDN, SearchScope.ONE, filter, userAttribs);
                    new SearchRequest(usersDN, SearchScope.ONE, filter, userAttribs);


            searchResult = getReadOnlyConnection().searchForEntry(searchRequest);
            searchResult = getReadOnlyConnection().searchForEntry(searchRequest);
            if (searchResult == null)
            if (searchResult == null)
@@ -733,7 +741,7 @@ public class LdapUserDAO extends LdapDAO
        }
        }
        catch (LDAPException e)
        catch (LDAPException e)
        {
        {
            logger.debug("getGroup Exception: " + e, e);
            logger.debug("getAugmentedUser Exception: " + e, e);
            LdapDAO.checkLdapResult(e.getResultCode());
            LdapDAO.checkLdapResult(e.getResultCode());
            throw new RuntimeException("BUG: checkLdapResult didn't throw an exception");
            throw new RuntimeException("BUG: checkLdapResult didn't throw an exception");
        }
        }
@@ -846,12 +854,12 @@ public class LdapUserDAO extends LdapDAO
    public User approveUserRequest(final Principal userID)
    public User approveUserRequest(final Principal userID)
        throws UserNotFoundException, TransientException, AccessControlException
        throws UserNotFoundException, TransientException, AccessControlException
    {
    {
        User pendingUser = getUserRequest(userID);
        User userRequest = getUserRequest(userID);
        if (pendingUser.getHttpPrincipal() == null)
        if (userRequest.getHttpPrincipal() == null)
        {
        {
            throw new RuntimeException("BUG: missing HttpPrincipal for " + userID.getName());
            throw new RuntimeException("BUG: missing HttpPrincipal for " + userID.getName());
        }
        }
        String uid = "uid=" + pendingUser.getID().getUUID().getLeastSignificantBits();
        String uid = "uid=" + uuid2string(userRequest.getID().getUUID());
        String dn = uid + "," + config.getUserRequestsDN();
        String dn = uid + "," + config.getUserRequestsDN();


        try
        try
@@ -1058,8 +1066,8 @@ public class LdapUserDAO extends LdapDAO
        User user2Delete = getUser(userID, usersDN);
        User user2Delete = getUser(userID, usersDN);
        try
        try
        {
        {
            long id = user2Delete.getID().getUUID().getLeastSignificantBits();
            String uuid = uuid2string(user2Delete.getID().getUUID());
            DN userDN = getUserDN(String.valueOf(id), usersDN);
            DN userDN = getUserDN(uuid, usersDN);
            if (markDelete)
            if (markDelete)
            {
            {
                List<Modification> modifs = new ArrayList<Modification>();
                List<Modification> modifs = new ArrayList<Modification>();
@@ -1219,6 +1227,11 @@ public class LdapUserDAO extends LdapDAO
        return rand.nextInt(Integer.MAX_VALUE - 10000) + 10000;
        return rand.nextInt(Integer.MAX_VALUE - 10000) + 10000;
    }
    }


    protected String uuid2string(UUID uuid)
    {
        return String.valueOf(uuid.getLeastSignificantBits());
    }

    protected InternalID getInternalID(String numericID)
    protected InternalID getInternalID(String numericID)
    {
    {
        UUID uuid = new UUID(0L, Long.parseLong(numericID));
        UUID uuid = new UUID(0L, Long.parseLong(numericID));