diff --git a/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java b/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java index bb6966b7d32e91b35c220c656f5b8ed8c44b621b..c8270faae57ea4e3d7c2dc9257e80c08d1401efb 100644 --- a/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java +++ b/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java @@ -93,6 +93,7 @@ import ca.nrc.cadc.auth.HttpPrincipal; import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.util.PropertiesReader; + /** * This class approves the specified pending user by moving the user * from a pending user to an active user in the LDAP server. @@ -114,19 +115,69 @@ public class ApproveUser extends AbstractUserCommand private String dn; + /** * Constructor * @param userID Id of the pending user to be approved + * @param dn of the pending user to be approved */ public ApproveUser(final String userID, final String dn) + { + super(userID); + this.dn = dn; + } + + + /** + * Constructor + * @param userID Id of the pending user to be approved + */ + public ApproveUser(final String userID) { super(userID); - this.dn = dn; } + protected void execute() throws AccessControlException, UserNotFoundException, TransientException { + User<Principal> user = null; + try + { + // Search the user in the pending tree + user = this.getUserPersistence().getPendingUser(this.getPrincipal()); + } + catch (Exception e) + { + log.info("User not found in userRequests"); + this.systemOut.println("User not found in userRequests. Impossible to approve it."); + this.systemOut.println("Check the validity of the provided uid."); + return; + } + log.debug("User found in userRequests"); + // If user DN is not provided by command line, search if it is available in UserRequests + if (dn == null || dn.isEmpty()) { + boolean foundDN = false; + for (Principal p : user.getIdentities()) + { + if (p instanceof X500Principal) + { + this.dn = p.getName(); + log.debug("User DN FOUND in pendingUser. userDN = " + dn); + foundDN = true; + break; + } + } + if(!foundDN) + { + log.debug("User DN NOT FOUND in UserRequests."); + this.systemOut.println("User DN not found in userRequests."); + this.systemOut.println("Use --dn option to provide a valid user DN"); + return; + } + + } + X500Principal dnPrincipal = null; try { @@ -150,7 +201,7 @@ public class ApproveUser extends AbstractUserCommand this.systemOut.println("Could not find pending user " + this.getPrincipal()); } - User<Principal> user = null; + user = null; try { user = this.getUserPersistence().getUser(this.getPrincipal()); diff --git a/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java b/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java index 37847e22d1e69c611fde77356fa92a8cdc17492d..5411f1a56a7ba2568897e8243eeec6c01b5de109 100644 --- a/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java +++ b/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java @@ -231,7 +231,7 @@ public class CmdLineParser } else { - throw new UsageException("Missing parameter 'dn'"); + this.command = new ApproveUser(userID); } }