Commit 67c5adc7 authored by Brian Major's avatar Brian Major
Browse files

s1666 - start of work to list all group names

parent d89a7a2c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -81,6 +81,16 @@ import ca.nrc.cadc.net.TransientException;

public abstract interface GroupPersistence<T extends Principal>
{
    /**
     * Get all group names.
     * 
     * @return A collection of strings.
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public Collection<String> getGroupNames()
            throws TransientException, AccessControlException;
    
    /**
     * Get the group with the given Group ID.
     *
+55 −0
Original line number Diff line number Diff line
@@ -306,6 +306,61 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        }
    }
    
    
    /**
     * Get all group names.
     * 
     * @return A collection of strings
     * 
     * @throws TransientException If an temporary, unexpected problem occurred.
     */
    public Collection<String> getGroupNames() throws TransientException,
               AccessControlException
    {
        try
        {
            Filter filter = null;
            String [] attributes = new String[] {"cn", "nsaccountlock"};
            
            SearchRequest searchRequest = 
                    new SearchRequest(config.getGroupsDN(), 
                                      SearchScope.SUB, filter, attributes);
    
            searchRequest.addControl(
                    new ProxiedAuthorizationV2RequestControl("dn:" + 
                            getSubjectDN().toNormalizedString()));
    
            SearchResult searchResult = null;
            try
            {
                searchResult = getConnection().search(searchRequest);
            }
            catch (LDAPSearchException e)
            {
                if (e.getResultCode() == ResultCode.NO_SUCH_OBJECT)
                {
                    logger.debug("Count not find groups root", e);
                    throw new IllegalStateException("Count not find groups root");
                }
            }
            
            LdapDAO.checkLdapResult(searchResult.getResultCode());
            List<String> groupNames = new ArrayList<String>();
            for (SearchResultEntry next : searchResult.getSearchEntries())
            {
                groupNames.add(next.getAttributeValue("cn"));
            }
            
            return groupNames;
        }
        catch (LDAPException e1)
        {
            LdapDAO.checkLdapResult(e1.getResultCode());
            throw new IllegalStateException("Unexpected exception: " + e1.getMatchedDN(), e1);
        }
        
    }

    /**
     * Get the group with the given Group ID.
     * 
+26 −1
Original line number Diff line number Diff line
@@ -94,6 +94,31 @@ public class LdapGroupPersistence<T extends Principal>
        config = LdapConfig.getLdapConfig();
    }
    
    public Collection<String> getGroupNames() throws TransientException,
        AccessControlException
    {
        LdapGroupDAO<T> groupDAO = null;
        LdapUserDAO<T> userDAO = null;
        try
        {
            userDAO = new LdapUserDAO<T>(config);
            groupDAO = new LdapGroupDAO<T>(config, userDAO);
            Collection<String> ret = groupDAO.getGroupNames();
            return ret;
        }
        finally
        {
            if (groupDAO != null)
            {
                groupDAO.close();
            }
            if (userDAO != null)
            {
                userDAO.close();
            }
        }
    }
    
    public Group getGroup(String groupName)
        throws GroupNotFoundException, TransientException,
               AccessControlException
+5 −2
Original line number Diff line number Diff line
@@ -68,12 +68,15 @@
 */
package ca.nrc.cadc.ac.server.web;

import ca.nrc.cadc.util.StringUtil;
import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import ca.nrc.cadc.util.StringUtil;

public class GroupsActionFactory
{
    private static final Logger log = Logger.getLogger(GroupsActionFactory.class);
@@ -109,7 +112,7 @@ public class GroupsActionFactory
        {
            if (method.equals("GET"))
            {
                action = new ListGroupsAction(logInfo);
                action = new GetGroupNamesAction(logInfo);
            }
            else if (method.equals("PUT"))
            {
+2 −2
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ public class GroupActionFactoryTest
    }

    @Test
    public void testCreateListGroupsAction()
    public void testCreateGetGroupNamesAction()
    {
        try
        {
@@ -199,7 +199,7 @@ public class GroupActionFactoryTest
            EasyMock.replay(request);
            GroupsAction action = GroupsActionFactory.getGroupsAction(request, null);
            EasyMock.verify(request);
            Assert.assertTrue("Wrong action", action instanceof ListGroupsAction);
            Assert.assertTrue("Wrong action", action instanceof GetGroupNamesAction);
        }
        catch (Throwable t)
        {
Loading