Skip to content
Snippets Groups Projects
Commit 6e2fc4ff authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Mangement of empty DN in approve operation added

parent 3111a1e1
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,7 @@ import ca.nrc.cadc.auth.HttpPrincipal; ...@@ -93,6 +93,7 @@ import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.util.PropertiesReader; import ca.nrc.cadc.util.PropertiesReader;
/** /**
* This class approves the specified pending user by moving the user * This class approves the specified pending user by moving the user
* from a pending user to an active user in the LDAP server. * from a pending user to an active user in the LDAP server.
...@@ -114,9 +115,11 @@ public class ApproveUser extends AbstractUserCommand ...@@ -114,9 +115,11 @@ public class ApproveUser extends AbstractUserCommand
private String dn; private String dn;
/** /**
* Constructor * Constructor
* @param userID Id of the pending user to be approved * @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) public ApproveUser(final String userID, final String dn)
{ {
...@@ -124,9 +127,57 @@ public class ApproveUser extends AbstractUserCommand ...@@ -124,9 +127,57 @@ public class ApproveUser extends AbstractUserCommand
this.dn = dn; this.dn = dn;
} }
/**
* Constructor
* @param userID Id of the pending user to be approved
*/
public ApproveUser(final String userID)
{
super(userID);
}
protected void execute() protected void execute()
throws AccessControlException, UserNotFoundException, TransientException 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; X500Principal dnPrincipal = null;
try try
{ {
...@@ -150,7 +201,7 @@ public class ApproveUser extends AbstractUserCommand ...@@ -150,7 +201,7 @@ public class ApproveUser extends AbstractUserCommand
this.systemOut.println("Could not find pending user " + this.getPrincipal()); this.systemOut.println("Could not find pending user " + this.getPrincipal());
} }
User<Principal> user = null; user = null;
try try
{ {
user = this.getUserPersistence().getUser(this.getPrincipal()); user = this.getUserPersistence().getUser(this.getPrincipal());
......
...@@ -231,7 +231,7 @@ public class CmdLineParser ...@@ -231,7 +231,7 @@ public class CmdLineParser
} }
else else
{ {
throw new UsageException("Missing parameter 'dn'"); this.command = new ApproveUser(userID);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment