Commit c814ecb6 authored by CADC Software Admin's avatar CADC Software Admin
Browse files

Merge branch 'release_candidate'

parents 1d1a45cb 10121b0b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@
      <attribute name="Main-Class" value="ca.nrc.cadc.ac.admin.Main"/>
      <attribute name="Class-Path" value="${client.flat.manifest} ${client.non-flat.manifest}"/>
    </manifest>
  	
  	<echo message="classpath: ${client.flat.manifest} ${client.non-flat.manifest}" />
  </target>

  <!-- JAR files needed to run the test suite -->
+45 −9
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;

import javax.security.auth.x500.X500Principal;

import org.apache.log4j.Logger;

import ca.nrc.cadc.ac.User;
@@ -87,22 +89,56 @@ import ca.nrc.cadc.net.TransientException;
public class ApproveUser extends AbstractUserCommand
{
    private static final Logger log = Logger.getLogger(ApproveUser.class);
    private String dn;

    /**
     * Constructor
     * @param userID Id of the pending user to be approved
     */
    public ApproveUser(final String userID)
    public ApproveUser(final String userID, final String dn)
    {
    	super(userID);
    	this.dn = dn;
    }

    protected void execute()
	throws AccessControlException, UserNotFoundException, TransientException
    {
        User<Principal> user = this.getUserPersistence().approvePendingUser(this.getPrincipal());
        String msg = "User " + this.getPrincipal().getName() + " was approved successfully.";
        this.systemOut.println(msg);
        X500Principal dnPrincipal = null;
        try
        {
            dnPrincipal = new X500Principal(dn);
        }
        catch (Exception e)
        {
            throw new IllegalArgumentException("Invalid DN format: " + dn);
        }

        try
        {
            this.getUserPersistence().approvePendingUser(this.getPrincipal());
            this.systemOut.println("User " + this.getPrincipal().getName() + " was approved successfully.");
        }
        catch (UserNotFoundException e)
        {
            this.systemOut.println("Could not find pending user " + this.getPrincipal());
        }

        User<Principal> user = null;
        try
        {
            user = this.getUserPersistence().getUser(this.getPrincipal());
        }
        catch (UserNotFoundException e)
        {
            this.systemOut.println("Could not set user DN");
            return;
        }

        user.getIdentities().add(dnPrincipal);
        this.getUserPersistence().modifyUser(user);
        this.systemOut.println("User " + this.getPrincipal().getName() + " now has DN " + dn);
        this.printUser(user);

    }
}
+18 −12
Original line number Diff line number Diff line
@@ -222,7 +222,15 @@ public class CmdLineParser
    	{
            if (this.hasValue(userID))
    	    {
                this.command = new ApproveUser(userID);
                String dn = am.getValue("dn");
                if (dn != null)
                {
                    this.command = new ApproveUser(userID, dn);
                }
                else
                {
                    throw new UsageException("Missing parameter 'dn'");
                }
    	    }

            count++;
@@ -285,14 +293,12 @@ public class CmdLineParser
    	sb.append("\n");
    	sb.append("Usage: " + APP_NAME + " <command> [-v|--verbose|-d|--debug] [-h|--help]\n");
    	sb.append("Where command is\n");
    	sb.append("--list               :list users in the Users tree\n");
    	sb.append("                     :can be executed as an anonymous user\n");
    	sb.append("--list-pending       :list users in the UserRequests tree\n");
    	sb.append("                     :can be executed as an anonymous user\n");
    	sb.append("--view=<userid>      :print the entire details of the user\n");
    	sb.append("--approve=<userid>   :delete the user from the UserRequests tree\n");
    	sb.append("                     :and insert it into the Users tree\n");
    	sb.append("--reject=<userid>    :delete the user from the UserRequests tree\n");
    	sb.append("--list                       : List users in the Users tree\n");
    	sb.append("--list-pending               : List users in the UserRequests tree\n");
    	sb.append("--view=<userid>              : Print the entire details of the user\n");
    	sb.append("--approve=<userid> --dn=<dn> : Approve user with userid=<userid> and set the\n");
    	sb.append("                             : distinguished name to <dn>\n");
    	sb.append("--reject=<userid>            : Delete this user request\n");
    	sb.append("\n");
    	sb.append("-v|--verbose                 : Verbose mode print progress and error messages\n");
    	sb.append("-d|--debug                   : Debug mode print all the logging messages\n");
+5 −5
Original line number Diff line number Diff line
@@ -70,11 +70,13 @@
package ca.nrc.cadc.ac.admin;

import java.io.PrintStream;
import java.security.Principal;
import java.security.cert.CertificateException;

import org.apache.log4j.Logger;

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

/**
 * A command line admin tool for LDAP users.
@@ -147,12 +149,10 @@ public class Main
            else
            {
                // Set the necessary JNDI system property for lookups.
                System.setProperty("java.naming.factory.initial",
                                   ContextFactoryImpl.class.getName());
                System.setProperty("java.naming.factory.initial",  ContextFactoryImpl.class.getName());

                final CommandRunner runner =
                        new CommandRunner(parser, new PluginFactory().
                                createUserPersistence());
                UserPersistence<Principal> userPersistence = new PluginFactory().createUserPersistence();
                final CommandRunner runner =  new CommandRunner(parser, userPersistence);

                runner.run();
            }
+26 −26
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ public class CmdLineParserTest
    	// case 6: one --approve command
    	try
    	{
    	    String[] dArgs = {"--approve=jdoe", "-d"};
    	    String[] dArgs = {"--approve=jdoe", "--dn=dn", "-d"};
    	    CmdLineParser parser = new CmdLineParser(dArgs, sysOut, sysErr);
    	    Assert.assertEquals(Level.DEBUG, parser.getLogLevel());
    	    Assert.assertTrue(parser.getCommand() instanceof ApproveUser);
@@ -285,7 +285,7 @@ public class CmdLineParserTest
    	// case 7: one command with no user ID
    	try
    	{
    	    String[] dArgs = {"--approve", "-d"};
    	    String[] dArgs = {"--approve", "--dn=dn", "-d"};
    	    new CmdLineParser(dArgs, sysOut, sysErr);
    	    Assert.fail("Should have received a UsageException.");
    	}
@@ -302,7 +302,7 @@ public class CmdLineParserTest
    	// case 8: one command with no user ID
    	try
    	{
    	    String[] dArgs = {"--approve=", "-d"};
    	    String[] dArgs = {"--approve=", "--dn=dn", "-d"};
    	    new CmdLineParser(dArgs, sysOut, sysErr);
    	    Assert.fail("Should have received a UsageException.");
    	}
Loading