Commit 82336f39 authored by Brian Major's avatar Brian Major
Browse files

t72306 - added dn setting to approve function

parent f6c95380
Loading
Loading
Loading
Loading
+17 −8
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,29 @@ 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);
        this.systemOut.println("User " + this.getPrincipal().getName() + " was approved successfully.");
        log.debug("approved user, now setting dn");
        user = this.getUserPersistence().getUser(this.getPrincipal());
        X500Principal dnPrincipal = new X500Principal(dn);
        user.getIdentities().add(dnPrincipal);
        this.getUserPersistence().modifyUser(user);
        this.systemOut.println("User " + this.getPrincipal().getName() + " now has DN " + dn);
        this.printUser(user);
    }
}
+20 −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,14 @@ 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("                               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> --dn=<dn> : 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("\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");