Commit 0ab722e5 authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Story 1734: Added listing of users.

parent 659bf4e8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import ca.nrc.cadc.net.TransientException;

import com.unboundid.ldap.sdk.DN;


public interface UserPersistence<T extends Principal>
{
    /**
+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class LdapConfig

    public static LdapConfig getLdapConfig(final String ldapProperties)
    {
        logger.debug("Reading LDAP properties from: " + ldapProperties);
        logger.info("Reading LDAP properties from: " + ldapProperties);
        PropertiesReader pr = new PropertiesReader(ldapProperties);
        
        MultiValuedProperties config = pr.getAllProperties();
+7 −22
Original line number Diff line number Diff line
@@ -69,19 +69,18 @@

package ca.nrc.cadc.ac.server.web.users;

import java.io.Writer;
import java.util.Collection;

import org.apache.log4j.Logger;

import ca.nrc.cadc.ac.server.UserPersistence;

public class GetUserNamesAction extends UsersAction

public class GetUsersAction extends UsersAction
{
    
    private static final Logger log = Logger.getLogger(GetUserNamesAction.class);
    private static final Logger log = Logger.getLogger(GetUsersAction.class);

    GetUserNamesAction(UserLogInfo logInfo)
    GetUsersAction(UserLogInfo logInfo)
    {
        super(logInfo);
    }
@@ -89,23 +88,9 @@ public class GetUserNamesAction extends UsersAction
    public Object run()
        throws Exception
    {
        UserPersistence userPersistence = getUserPersistence();
        Collection<String> users = userPersistence.getUserNames();
        log.debug("Found " + users.size() + " user names");
        response.setContentType("text/plain");
        log.debug("Set content-type to text/plain");
        Writer writer = response.getWriter();
        boolean start = true;
        for (final String user : users)
        {
            if (!start)
            {
                writer.write("\r\n");
            }
            writer.write(user);
            start = false;
        }
        final UserPersistence userPersistence = getUserPersistence();

        writeUsers(userPersistence.getUserNames());
        return null;
    }
}
+15 −23
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import java.security.AccessControlException;
import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collection;

import javax.security.auth.Subject;
import javax.servlet.http.HttpServletResponse;
@@ -251,42 +252,33 @@ public abstract class UsersAction
    }

    /**
     * Read a user from the HTTP Request's stream.
     * Write a user to the response's writer.
     *
     * @param inputStream       The Input Stream to read from.
     * @return                  User instance.
     * @throws IOException      Any reading error(s)
     * @param user              The user object to marshall and write out.
     * @throws IOException      Any writing errors.
     */
    protected final User<Principal> readUser(
            final InputStream inputStream) throws IOException
    protected final <T extends Principal> void writeUser(final User<T> user)
            throws IOException
    {
        final User<Principal> user;
        response.setContentType(acceptedContentType);
        final Writer writer = response.getWriter();

        if (acceptedContentType.equals(DEFAULT_CONTENT_TYPE))
        {
            user = ca.nrc.cadc.ac.xml.UserReader.read(inputStream);
            ca.nrc.cadc.ac.xml.UserWriter.write(user, writer);
        }
        else if (acceptedContentType.equals(JSON_CONTENT_TYPE))
        {
            user = ca.nrc.cadc.ac.json.UserReader.read(inputStream);
        }
        else
        {
            // Should never happen.
            throw new IOException("Unknown content being asked for: "
                                  + acceptedContentType);
            ca.nrc.cadc.ac.json.UserWriter.write(user, writer);
        }

        return user;
    }

    /**
     * Write a user to the response's writer.
     * Write out a list of users as this Action's specified content type.
     *
     * @param user              The user object to marshall and write out.
     * @throws IOException      Any writing errors.
     * @param users         The Collection of user entries.
     */
    protected final <T extends Principal> void writeUser(final User<T> user)
    protected final void writeUsers(final Collection<String> users)
            throws IOException
    {
        response.setContentType(acceptedContentType);
@@ -294,11 +286,11 @@ public abstract class UsersAction

        if (acceptedContentType.equals(DEFAULT_CONTENT_TYPE))
        {
            ca.nrc.cadc.ac.xml.UserWriter.write(user, writer);
            ca.nrc.cadc.ac.xml.UsersWriter.write(users, writer);
        }
        else if (acceptedContentType.equals(JSON_CONTENT_TYPE))
        {
            ca.nrc.cadc.ac.json.UserWriter.write(user, writer);
            ca.nrc.cadc.ac.json.UsersWriter.write(users, writer);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class UsersActionFactory
        {
            if (method.equals("GET"))
            {
                action = new GetUserNamesAction(logInfo);
                action = new GetUsersAction(logInfo);
            }
            else if (method.equals("PUT"))
            {
Loading