Commit 82b45a08 authored by Adrian Damian's avatar Adrian Damian
Browse files

Merge branch 's1666' into s1711

parents 4c09aa32 9441f331
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -94,13 +94,14 @@
    <property name="cadcUtil"            value="${lib}/cadcUtil.jar" />
    <property name="cadcUWS"             value="${lib}/cadcUWS.jar" />

    <property name="javacsv"             value="${ext.lib}/javacsv.jar" />
    <property name="jdom2"               value="${ext.lib}/jdom2.jar" />
    <property name="log4j"               value="${ext.lib}/log4j.jar" />
    <property name="servlet"             value="${ext.lib}/servlet-api.jar" />
    <property name="unboundid"           value="${ext.lib}/unboundid-ldapsdk-se.jar" />
    <property name="xerces"              value="${ext.lib}/xerces.jar" />

    <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" />
    <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" />

    <target name="build" depends="compile">
        <jar jarfile="${build}/lib/${project}.jar"
@@ -130,7 +131,7 @@
        </copy>
    </target>
    
<!--    <target name="test" depends="compile-test,resources">
    <target name="test" depends="compile,compile-test,resources">
        <echo message="Running test suite..." />
        <junit printsummary="yes" haltonfailure="yes" fork="yes">
            <classpath>
@@ -138,9 +139,9 @@
                <pathelement path="${build}/test/class"/>
                <pathelement path="${testingJars}"/>
            </classpath>
            <test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" />
            <test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" />
            <formatter type="plain" usefile="false" />
        </junit>
    </target>-->
    </target>

</project>
+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.
     *
+53 −1
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.util.StringUtil;

import com.unboundid.ldap.sdk.AddRequest;
import com.unboundid.ldap.sdk.Attribute;
@@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        attributes.add(new Attribute("objectClass", "groupofuniquenames"));
        attributes.add(new Attribute("cn", groupID));
        
        if (description != null)
        if (StringUtil.hasText(description))
        {
            attributes.add(new Attribute("description", description));
        }
@@ -306,6 +307,57 @@ 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 = Filter.createEqualityFilter("cn", "*");
            String [] attributes = new String[] {"cn", "nsaccountlock"};
            
            SearchRequest searchRequest = 
                    new SearchRequest(config.getGroupsDN(), 
                                      SearchScope.SUB, filter, attributes);
    
            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
+9 −2
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ import ca.nrc.cadc.ac.server.GroupPersistence;

import com.csvreader.CsvWriter;

import javax.servlet.http.HttpServletResponse;

public class GetGroupNamesAction extends GroupsAction
{

@@ -86,9 +88,9 @@ public class GetGroupNamesAction extends GroupsAction
    {
        GroupPersistence groupPersistence = getGroupPersistence();
        Collection<String> groups = groupPersistence.getGroupNames();
        response.setContentType("text/csv");
        getHttpServletResponse().setContentType("text/csv");
        
        CsvWriter writer = new CsvWriter(response.getWriter(), ',');
        CsvWriter writer = new CsvWriter(getHttpServletResponse().getWriter(), ',');
        
        for (String group : groups)
        {
@@ -98,4 +100,9 @@ public class GetGroupNamesAction extends GroupsAction
        return null;
    }

    protected HttpServletResponse getHttpServletResponse()
    {
        return this.response;
    }

}
Loading