Commit eaab184d authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Merge branch 'master' of ssh://gimli2.cadc.dao.nrc.ca/srv/cadc/git/ac into t72959

parents 6b4fabc1 4e8ffb57
......@@ -158,16 +158,4 @@
<property name="testingJars" value="${junit}:${asm}:${cglib}:${easymock}:${objenesis}:{unboundid}:${cadcLog}"/>
<target name="int-test" depends="build,compile-test,setup-test">
<echo message="Running test suite..."/>
<junit printsummary="yes" haltonfailure="yes" fork="yes">
<classpath>
<pathelement path="${build}/class"/>
<pathelement path="${build}/test/class"/>
<pathelement path="${jars}:${testingJars}"/>
</classpath>
<test name="ca.nrc.cadc.ac.admin.integration.UserAdminIntTest"/>
<formatter type="plain" usefile="false"/>
</junit>
</target>
</project>
......@@ -71,7 +71,6 @@ package ca.nrc.cadc.ac.admin;
import java.io.PrintStream;
import java.security.AccessControlException;
import java.security.Principal;
import java.security.PrivilegedAction;
import ca.nrc.cadc.ac.server.UserPersistence;
......@@ -88,12 +87,12 @@ public abstract class AbstractCommand implements PrivilegedAction<Object>
protected PrintStream systemOut = System.out;
protected PrintStream systemErr = System.err;
private UserPersistence<Principal> userPersistence;
private UserPersistence userPersistence;
protected abstract void doRun()
throws AccessControlException, TransientException;
/**
* Set the system out.
* @param printStream The stream to write System.out to .
......@@ -102,7 +101,7 @@ public abstract class AbstractCommand implements PrivilegedAction<Object>
{
this.systemOut = printStream;
}
/**
* Set the system err.
* @param printStream The stream to write System.err to.
......@@ -111,36 +110,36 @@ public abstract class AbstractCommand implements PrivilegedAction<Object>
{
this.systemErr = printStream;
}
@Override
public Object run()
public Object run()
{
try
try
{
this.doRun();
}
catch (AccessControlException e)
}
catch (AccessControlException e)
{
this.systemErr.println("ERROR: " + e.getMessage());
e.printStackTrace(systemErr);
}
catch (TransientException e)
}
catch (TransientException e)
{
String message = "Internal Transient Error: " + e.getMessage();
this.systemErr.println("ERROR: " + message);
e.printStackTrace(systemErr);
}
return null;
}
protected void setUserPersistence(
final UserPersistence<Principal> userPersistence)
final UserPersistence userPersistence)
{
this.userPersistence = userPersistence;
}
public UserPersistence<Principal> getUserPersistence()
public UserPersistence getUserPersistence()
{
return userPersistence;
}
......
......@@ -70,14 +70,15 @@
package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Collection;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
import org.apache.log4j.Logger;
import ca.nrc.cadc.ac.PersonalDetails;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.net.TransientException;
/**
......@@ -89,14 +90,14 @@ public abstract class AbstractListUsers extends AbstractCommand
{
private static final Logger log = Logger.getLogger(AbstractListUsers.class);
protected abstract Collection<User<Principal>> getUsers()
protected abstract Collection<User> getUsers()
throws AccessControlException, TransientException;
protected void doRun() throws AccessControlException, TransientException
{
Collection<User<Principal>> users = this.getUsers();
Collection<User> users = this.getUsers();
for (User<Principal> user : users)
for (User user : users)
{
this.systemOut.println(getUserString(user));
}
......@@ -106,21 +107,36 @@ public abstract class AbstractListUsers extends AbstractCommand
private String getUserString(User user)
{
StringBuilder sb = new StringBuilder(user.getUserID().getName());
StringBuilder sb = new StringBuilder();
HttpPrincipal username = user.getHttpPrincipal();
if (username != null)
{
sb.append(username.getName());
}
else
{
Set<X500Principal> x500Principals = user.getIdentities(X500Principal.class);
if (!x500Principals.isEmpty())
{
sb.append(x500Principals.iterator().next().getName());
}
else
{
sb.append("Internal ID: " + user.getID().getURI());
}
}
Set<PersonalDetails> detailSet = user.getDetails(PersonalDetails.class);
if (detailSet.size() > 0)
if (user.personalDetails != null)
{
sb.append(" [");
PersonalDetails details = detailSet.iterator().next();
sb.append(details.getFirstName());
sb.append(user.personalDetails.getFirstName());
sb.append(" ");
sb.append(details.getLastName());
sb.append(user.personalDetails.getLastName());
sb.append("]");
if (details.institute != null)
if (user.personalDetails.institute != null)
{
sb.append(" [");
sb.append(details.institute);
sb.append(user.personalDetails.institute);
sb.append("]");
}
}
......
......@@ -75,7 +75,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import ca.nrc.cadc.ac.PersonalDetails;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.auth.HttpPrincipal;
......@@ -86,12 +85,12 @@ import ca.nrc.cadc.net.TransientException;
* @author yeunga
*
*/
public abstract class AbstractUserCommand extends AbstractCommand
public abstract class AbstractUserCommand extends AbstractCommand
{
private static final Logger log = Logger.getLogger(AbstractUserCommand.class);
private HttpPrincipal principal;
protected abstract void execute()
protected abstract void execute()
throws UserNotFoundException, AccessControlException, TransientException;
/**
......@@ -102,26 +101,26 @@ public abstract class AbstractUserCommand extends AbstractCommand
{
this.principal = new HttpPrincipal(userID);
}
protected Principal getPrincipal()
{
return this.principal;
}
protected void doRun() throws AccessControlException, TransientException
{
try
try
{
this.execute();
}
catch (UserNotFoundException e1)
}
catch (UserNotFoundException e1)
{
String msg = "User " + this.getPrincipal().getName() + " was not found.";
this.systemOut.println(msg);
}
}
}
protected void printUser(final User<Principal> user)
protected void printUser(final User user)
{
if (user != null)
{
......@@ -133,13 +132,12 @@ public abstract class AbstractUserCommand extends AbstractCommand
{
this.systemOut.println(p.toString());
}
// print user's personal details
this.systemOut.println();
PersonalDetails personalDetails = user.getUserDetail(PersonalDetails.class);
if (personalDetails != null)
if (user.personalDetails != null)
{
this.systemOut.println(personalDetails.toStringFormatted());
this.systemOut.println(user.personalDetails.toStringFormatted());
}
}
}
......
......@@ -70,11 +70,9 @@
package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Date;
import java.util.IllegalFormatException;
import java.util.Properties;
import java.util.Set;
import javax.mail.Address;
import javax.mail.Message;
......@@ -86,7 +84,6 @@ import javax.security.auth.x500.X500Principal;
import org.apache.log4j.Logger;
import ca.nrc.cadc.ac.PersonalDetails;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.auth.HttpPrincipal;
......@@ -141,16 +138,17 @@ public class ApproveUser extends AbstractUserCommand
try
{
this.getUserPersistence().approvePendingUser(this.getPrincipal());
this.getUserPersistence().approveUserRequest(this.getPrincipal());
this.systemOut.println("User " + this.getPrincipal().getName() + " was approved successfully.");
approved = true;
}
catch (UserNotFoundException e)
{
this.systemOut.println("Could not find pending user " + this.getPrincipal());
this.systemOut.println("Could not find userRequest " + this.getPrincipal());
return;
}
User<Principal> user = null;
User user = null;
try
{
user = this.getUserPersistence().getUser(this.getPrincipal());
......@@ -175,7 +173,7 @@ public class ApproveUser extends AbstractUserCommand
}
private void emailUser(User<Principal> user)
private void emailUser(User user)
{
try
{
......@@ -201,12 +199,10 @@ public class ApproveUser extends AbstractUserCommand
return;
}
Set<PersonalDetails> pds = user.getDetails(PersonalDetails.class);
String recipient = null;
if (pds != null && !pds.isEmpty())
if (user.personalDetails != null)
{
PersonalDetails pd = pds.iterator().next();
recipient = pd.email;
recipient = user.personalDetails.email;
}
if (recipient == null)
{
......
......@@ -187,13 +187,13 @@ public class CmdLineParser
if (am.isSet("list"))
{
System.out.println("--list");
this.command = new ListActiveUsers();
this.command = new ListUsers();
count++;
}
if (am.isSet("list-pending"))
{
this.command = new ListPendingUsers();
this.command = new ListUserRequests();
count++;
}
......
......@@ -92,11 +92,11 @@ public class CommandRunner
{
private final static Logger LOGGER = Logger.getLogger(CommandRunner.class);
private final CmdLineParser commandLineParser;
private final UserPersistence<Principal> userPersistence;
private final UserPersistence userPersistence;
public CommandRunner(final CmdLineParser commandLineParser,
final UserPersistence<Principal> userPersistence)
final UserPersistence userPersistence)
{
this.commandLineParser = commandLineParser;
this.userPersistence = userPersistence;
......
......@@ -70,7 +70,6 @@
package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Collection;
import org.apache.log4j.Logger;
......@@ -80,17 +79,17 @@ import ca.nrc.cadc.net.TransientException;
/**
* This class provides a list of all active or pending users in the LDAP server.
* The users' nsaccountlocked attribute is not set.
* The users' nsaccountlocked attribute is not set.
* @author yeunga
*
*/
public class ListPendingUsers extends AbstractListUsers
{
private static final Logger log = Logger.getLogger(ListPendingUsers.class);
protected Collection<User<Principal>> getUsers()
public class ListUserRequests extends AbstractListUsers
{
private static final Logger log = Logger.getLogger(ListUserRequests.class);
protected Collection<User> getUsers()
throws AccessControlException, TransientException
{
return this.getUserPersistence().getPendingUsers();
return this.getUserPersistence().getUserRequests();
}
}
......@@ -70,7 +70,6 @@
package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Collection;
import org.apache.log4j.Logger;
......@@ -84,11 +83,11 @@ import ca.nrc.cadc.net.TransientException;
* @author yeunga
*
*/
public class ListActiveUsers extends AbstractListUsers
{
private static final Logger log = Logger.getLogger(ListActiveUsers.class);
protected Collection<User<Principal>> getUsers()
public class ListUsers extends AbstractListUsers
{
private static final Logger log = Logger.getLogger(ListUsers.class);
protected Collection<User> getUsers()
throws AccessControlException, TransientException
{
return this.getUserPersistence().getUsers();
......
......@@ -70,7 +70,6 @@
package ca.nrc.cadc.ac.admin;
import java.io.PrintStream;
import java.security.Principal;
import java.security.cert.CertificateException;
import org.apache.log4j.Logger;
......@@ -151,7 +150,7 @@ public class Main
// Set the necessary JNDI system property for lookups.
System.setProperty("java.naming.factory.initial", ContextFactoryImpl.class.getName());
UserPersistence<Principal> userPersistence = new PluginFactory().createUserPersistence();
UserPersistence userPersistence = new PluginFactory().createUserPersistence();
final CommandRunner runner = new CommandRunner(parser, userPersistence);
runner.run();
......
......@@ -98,7 +98,7 @@ public class RejectUser extends AbstractUserCommand
throws AccessControlException, UserNotFoundException, TransientException
{
// delete user from the pending tree
this.getUserPersistence().deletePendingUser(this.getPrincipal());
this.getUserPersistence().deleteUserRequest(this.getPrincipal());
String msg = "User " + this.getPrincipal().getName() + " was rejected successfully.";
this.systemOut.println(msg);
}
......
......@@ -70,7 +70,6 @@
package ca.nrc.cadc.ac.admin;
import java.security.AccessControlException;
import java.security.Principal;
import org.apache.log4j.Logger;
......@@ -83,10 +82,10 @@ import ca.nrc.cadc.net.TransientException;
* @author yeunga
*
*/
public class ViewUser extends AbstractUserCommand
public class ViewUser extends AbstractUserCommand
{
private static final Logger log = Logger.getLogger(ViewUser.class);
/**
* Constructor
* @param userID Id of the user to provide details for
......@@ -96,22 +95,22 @@ public class ViewUser extends AbstractUserCommand
super(userID);
log.debug("view user: " + userID);
}
protected void execute()
throws AccessControlException, TransientException, UserNotFoundException
protected void execute()
throws AccessControlException, TransientException, UserNotFoundException
{
try
try
{
// Try the main tree first
log.debug("principal: " + this.getPrincipal());
User<Principal> user = this.getUserPersistence().getUser(this.getPrincipal());
User user = this.getUserPersistence().getUser(this.getPrincipal());
this.printUser(user);
}
catch (UserNotFoundException e)
}
catch (UserNotFoundException e)
{
// Not in the main tree, try the pending tree
User<Principal> user = this.getUserPersistence().getPendingUser(this.getPrincipal());
User user = this.getUserPersistence().getUserRequest(this.getPrincipal());
this.printUser(user);
}
}
}
}
......@@ -223,7 +223,7 @@ public class CmdLineParserTest
String[] dArgs = {"--list", "-d"};
CmdLineParser parser = new CmdLineParser(dArgs, sysOut, sysErr);
Assert.assertEquals(Level.DEBUG, parser.getLogLevel());
Assert.assertTrue(parser.getCommand() instanceof ListActiveUsers);
Assert.assertTrue(parser.getCommand() instanceof ListUsers);
}
catch (Exception e)
{
......@@ -236,7 +236,7 @@ public class CmdLineParserTest
String[] dArgs = {"--list-pending", "-d"};
CmdLineParser parser = new CmdLineParser(dArgs, sysOut, sysErr);
Assert.assertEquals(Level.DEBUG, parser.getLogLevel());
Assert.assertTrue(parser.getCommand() instanceof ListPendingUsers);
Assert.assertTrue(parser.getCommand() instanceof ListUserRequests);
}
catch (Exception e)
{
......
......@@ -137,7 +137,35 @@
<pathelement path="${jars}:${testingJars}"/>
</classpath>
<sysproperty key="ca.nrc.cadc.util.PropertiesReader.dir" value="test"/>
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapConfigTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapConnectionsTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapPersistenceTest" />-->
<test name="ca.nrc.cadc.ac.server.ldap.LdapUserDAOTest" />
<!--<test name="ca.nrc.cadc.ac.server.web.groups.AddGroupMemberActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.AddUserMemberActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.DeleteGroupActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.GetGroupNamesActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.GroupActionFactoryTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.RemoveGroupMemberActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.groups.RemoveUserMemberActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.users.GetUserActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.users.GetUserListActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.users.ModifyUserActionTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.users.UserActionFactoryTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.ModifyPasswordServletTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.ResetPasswordServletTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.UserLoginServletTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.UserServletTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.web.WhoAmIServletTest" />-->
<!--<test name="ca.nrc.cadc.ac.server.RequestValidatorTest" />-->
<formatter type="plain" usefile="false" />
</junit>
</target>
......
......@@ -69,7 +69,6 @@
package ca.nrc.cadc.ac.server;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Collection;
import ca.nrc.cadc.ac.Group;
......@@ -79,7 +78,7 @@ import ca.nrc.cadc.ac.Role;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.net.TransientException;
public interface GroupPersistence<T extends Principal>
public interface GroupPersistence
{
/**
* Call if this object is to be shut down.
......
......@@ -68,18 +68,14 @@
*/
package ca.nrc.cadc.ac.server;
import ca.nrc.cadc.ac.server.ldap.LdapGroupPersistence;
import ca.nrc.cadc.ac.server.ldap.LdapUserPersistence;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Properties;
import java.util.Set;
import org.apache.log4j.Logger;
import com.unboundid.ldap.sdk.LDAPException;
import ca.nrc.cadc.ac.server.ldap.LdapGroupPersistence;
import ca.nrc.cadc.ac.server.ldap.LdapUserPersistence;
public class PluginFactory
{
......@@ -118,20 +114,20 @@ public class PluginFactory
}
@SuppressWarnings("unchecked")
public <T extends Principal> GroupPersistence<T> createGroupPersistence()